34
34
def create_release(project, version):
35
35
'''Create new release and milestone for LP project.'''
37
print 'Release %s could not be found for project. Create it? (Y/n)' % \
37
print('Release %s could not be found for project. Create it? (Y/n)' % \
39
39
answer = sys.stdin.readline().strip()
40
40
if answer.startswith('n'):
47
47
msg = 'More than one series exist. Which one would you like to ' \
48
48
'upload to? Possible series are (listed as index, name):'
50
50
for idx, serie in enumerate(project.series):
51
print '\t%i - %s' % (idx, serie.name)
52
print 'Enter series index: '
51
print('\t%i - %s' % (idx, serie.name))
52
print('Enter series index: ')
53
53
answer = sys.stdin.readline().strip()
55
55
series = project.series[int(answer)]
56
56
except (ValueError, IndexError):
57
print >> sys.stderr, 'The series index is invalid (%s).' % answer
57
print('The series index is invalid (%s).' % answer, file=sys.stderr)
60
print "Using series named '%s'" % series.name
60
print("Using series named '%s'" % series.name)
62
print >> sys.stderr, ('Does not support creating releases if no '
62
print(('Does not support creating releases if no '
63
'series exists.'), file=sys.stderr)
66
66
release_date = datetime.date.today().strftime('%Y-%m-%d')
71
71
def edit_file(prefix, description):
72
72
(fd, f) = tempfile.mkstemp(prefix=prefix+'.')
73
os.write(fd, '\n\n#------\n# Please enter the %s here. '
74
'Lines which start with "#" are ignored.\n' % description)
73
os.write(fd, b'\n\n#------\n# Please enter the %s here. '
74
b'Lines which start with "#" are ignored.\n' % description.encode())
76
76
subprocess.call(['sensible-editor', f])
88
88
if len(sys.argv) < 4 or len(sys.argv) > 7:
89
print >> sys.stderr, '''Upload a release tarball to a Launchpad project.
89
print('''Upload a release tarball to a Launchpad project.
91
Usage: %s <project name> <version> <tarball> [new milestone] [changelog file] [releasenotes file]''' % sys.argv[0]
91
Usage: %s <project name> <version> <tarball> [new milestone] [changelog file] [releasenotes file]''' % sys.argv[0], file=sys.stderr)
94
94
new_milestone = None
123
123
release = create_release(proj, version)
125
125
# Get the file contents.
126
file_content = open(tarball, 'r').read()
126
with open(tarball, 'rb') as f:
127
file_content = f.read()
127
128
# Get the signature, if available.
128
129
signature = tarball + '.asc'
129
130
if not os.path.exists(signature):
130
print 'Calling GPG to create tarball signature...'
131
print('Calling GPG to create tarball signature...')
131
132
cmd = ['gpg', '--armor', '--sign', '--detach-sig', tarball]
132
133
if subprocess.call(cmd) != 0:
133
print >> sys.stderr, 'gpg failed, aborting'
134
print('gpg failed, aborting', file=sys.stderr)
135
136
if os.path.exists(signature):
136
signature_content = open(signature, 'r').read()
137
with open(signature, 'rb') as f:
138
signature_content = f.read()
138
140
signature_content = None
140
142
# Create a new product release file.
141
143
filename = os.path.basename(tarball)
142
144
release.add_file(filename=filename, description='release tarball',
143
file_content=file_content, content_type='application/x-gzip',
144
file_type='Code Release Tarball', signature_filename=signature,
145
signature_content=signature_content)
145
file_content=file_content, content_type='application/x-gzip',
146
file_type='Code Release Tarball', signature_filename=signature,
147
signature_content=signature_content)
147
149
if changelog_file is not None:
148
150
changelog = cat_file(changelog_file)
167
169
if mil.name in [milestone.name for milestone in series.all_milestones]:
168
170
series.newMilestone(name=new_milestone)
170
except HTTPError, error:
171
print 'An error happened in the upload:', error.content
172
except HTTPError as error:
173
print('An error happened in the upload:', error.content)
174
176
if __name__ == '__main__':