diff --git a/make-ppa b/make-ppa index f8754ac..0fa4b42 100755 --- a/make-ppa +++ b/make-ppa @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Creates source packages and uploads them to Launchpad. # @@ -15,7 +15,7 @@ import re import argparse CHANGELOG = 'debian/changelog' -DISTS = ['trusty', 'xenial', 'bionic', 'focal', 'jammy', 'kinetic'] + VERSION_PATTERN = re.compile( r'^(?P[+-.a-z0-9]+)\s+\((?P[^)]+)\)\s+(?P[^)]+); urgency=(?P.+)$') OUTPUT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -24,14 +24,27 @@ if sys.version_info[0] < 3: input = raw_input +def supported_distros(): + distro_info = subprocess.check_output( + ['distro-info', '--supported', '--codename', '--days'], text=True + ) + + dists = [] + for line in distro_info.splitlines(): + name, days = line.split(' ') + if int(days) < 0: + dists.append(name) + + return dists + + class Package(object): - def __init__(self, dists=DISTS, ppa='yubico/stable'): + def __init__(self, dists, ppa): self.dists = dists - file = open(CHANGELOG, 'r') - self.changelog = file.readlines() - file.close() + with open(CHANGELOG, 'r') as file: + self.changelog = file.readlines() match = VERSION_PATTERN.match(self.changelog[0]) self.ppa = ppa @@ -60,9 +73,8 @@ class Package(object): changelog = list(self.changelog) changelog[0] = line - file = open(CHANGELOG, 'w') - file.writelines(changelog) - file.close() + with open(CHANGELOG, 'w') as file: + file.writelines(changelog) os.system('debuild -S -sa -us -uc') os.system('mv ../%s_%s* %s/' % @@ -92,9 +104,8 @@ class Package(object): for dist in self.dists: self.build_dist(dist) - file = open(CHANGELOG, 'w') - file.writelines(self.changelog) - file.close() + with open(CHANGELOG, 'w') as file: + file.writelines(self.changelog) def sign(self, key, program): args = [ @@ -118,7 +129,7 @@ if __name__ == '__main__': help='Do not sign the packages (implies --no-upload)') parser.add_argument('--no-upload', action='store_false', dest='upload', help='Do not upload the (signed) packages') - parser.add_argument('--dists', nargs='+', default=DISTS, metavar='DIST', + parser.add_argument('--dists', nargs='+', default=supported_distros(), metavar='DIST', help='Distributions to build for') parser.add_argument('--ppa', nargs='?', default='yubico/stable', help='PPA to upload to')