3
from __future__ import print_function
5
from argparse import ArgumentParser
10
from launchpadlib.launchpad import Launchpad
13
def get_changes(package_dir):
14
"""Return source_name, version, file_name of the changes in the dir."""
16
f for f in os.listdir(package_dir) if f.endswith('_source.changes')]
17
file_name = file_names[0]
18
for file_name in os.listdir(package_dir):
19
if file_name.endswith('_source.changes'):
22
raise ValueError('*.changes file not found in {}'.format(package_dir))
23
with open(os.path.join(package_dir, file_name)) as changes_file:
24
changes = changes_file.read()
25
version = source_name = None
26
for line in changes.splitlines():
27
if line.startswith('Version:'):
28
ignore, version = line.split(' ')
29
if line.startswith('Source:'):
30
ignore, source_name = line.split(' ')
31
if version and source_name:
35
'Version: and Source: not found in {}'.format(file_name))
36
return source_name, version, file_name
39
def upload_package(ppa, archive, package_dir, dry_run=False):
40
"""Upload a source package found in the directory to the PPA.
42
Return True when the upload is performed, or False when the archive already
43
has the source package.
45
source_name, version, file_name = get_changes(package_dir)
46
package_histories = archive.getPublishedSources(
47
source_name=source_name, version=version)
49
print('{} {} is uploaded'.format(source_name, version))
51
print('uploading {} {}'.format(source_name, version))
53
subprocess.check_call(['dput', ppa, file_name], cwd=package_dir)
57
def upload_packages(lp, ppa, package_dirs, dry_run=False):
58
"""Upload new source packages to the PPA."""
59
ignore, team_archive = ppa.split(':')
60
team_name, archive_name = team_archive.split('/')
61
team = lp.people[team_name]
62
archive = team.getPPAByName(name=archive_name)
63
for package_dir in package_dirs:
64
upload_package(ppa, archive, package_dir, dry_run=dry_run)
67
def get_args(argv=None):
68
"""Return the option parser for this program."""
69
parser = ArgumentParser('Upload new source packages to Launchpad.')
71
'-d', '--dry-run', action="store_true", default=False,
72
help='Explain what will happen without making changes')
74
"-c", "--credentials", default=None, type=os.path.expanduser,
75
help="Launchpad credentials file.")
77
'ppa', help='The ppa to upload to: ppa:<person>/<archive>.')
79
'package_dirs', nargs='+', type=os.path.expanduser,
80
help='One or more source package directories.')
81
return parser.parse_args(argv)
85
"""Upload new source packages to a PPA."""
87
lp = Launchpad.login_with(
88
'upload-packages', service_root='https://api.launchpad.net',
89
version='devel', credentials_file=args.credentials)
91
lp, args.ppa, args.package_dirs, dry_run=args.dry_run)
95
if __name__ == '__main__':
96
sys.exit(main(sys.argv[1:]))