~debian-lptools/debian/sid/lptools/sid

« back to all changes in this revision

Viewing changes to bin/lp-project-upload

  • Committer: Jelmer Vernooij
  • Date: 2023-09-28 12:07:22 UTC
  • mfrom: (2.18.8)
  • Revision ID: jelmer@jelmer.uk-20230928120722-704pws90v7e943dk
* New upstream snapshot.
 + Drop patches for conversion to python 3 and breezy; now merged upstream.
+ debian/upstream/metadata: Drop unknown Homepage field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
 
1
#!/usr/bin/python3
2
2
 
3
3
# Copyright (c) 2009 Canonical Ltd.
4
4
#
34
34
def create_release(project, version):
35
35
    '''Create new release and milestone for LP project.'''
36
36
 
37
 
    print 'Release %s could not be found for project. Create it? (Y/n)' % \
38
 
          version
 
37
    print('Release %s could not be found for project. Create it? (Y/n)' % \
 
38
          version)
39
39
    answer = sys.stdin.readline().strip()
40
40
    if answer.startswith('n'):
41
41
        sys.exit(0)
46
46
    elif n_series > 1:
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):'
49
 
        print msg
 
49
        print(msg)
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()
54
54
        try:
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)
58
58
            sys.exit(3)
59
59
        else:
60
 
            print "Using series named '%s'" % series.name
 
60
            print("Using series named '%s'" % series.name)
61
61
    else:
62
 
        print >> sys.stderr, ('Does not support creating releases if no '
63
 
                              'series exists.')
 
62
        print(('Does not support creating releases if no '
 
63
                              'series exists.'), file=sys.stderr)
64
64
        sys.exit(3)
65
65
 
66
66
    release_date = datetime.date.today().strftime('%Y-%m-%d')
70
70
 
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())
75
75
    os.close(fd)
76
76
    subprocess.call(['sensible-editor', f])
77
77
    return cat_file(f)
86
86
 
87
87
def main():
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.
90
90
 
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)
92
92
        sys.exit(1)
93
93
 
94
94
    new_milestone = None
123
123
            release = create_release(proj, version)
124
124
 
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)
134
135
 
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()
137
139
        else:
138
140
            signature_content = None
139
141
 
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)
146
148
 
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)
169
171
 
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)
172
174
        sys.exit(1)
173
175
 
174
176
if __name__ == '__main__':