#!/usr/bin/python # repository-update # Update metadata for an APT repository. Handles binary and source package # lists, and release files. # # Dafydd Harries , 2005. import os import sys def run(command, args, output_file=None): print (command, args) pid = os.fork() if pid > 0: os.wait() else: if output_file is not None: fh = file(output_file, 'w') os.dup2(fh.fileno(), 1) os.execlp(command, command, *args) def gzip(file): run('gzip', ['--rsyncable', '-9', '-c', file], '%s.gz' % file) def sign(file): gpg = 'gnome-gpg' try: os.unlink('%s.gpg' % file) except OSError: pass run(gpg, ['--sign', '-b', '-a', '-o', '%s.gpg' % file, file]) def main(argv): options = { 'origin': 'Dafydd Harries', 'description': "Dafydd Harries' packages", 'label': None, 'archive': None, 'codename': None, 'architectures': 'i386', } if len(argv) != 3: sys.stderr.write('usage: %s repository subdir' % argv[0]) return 1 dir, subdir = argv[1:] for option in options: key = 'REPOSITORY_' + option.upper() if key in os.environ: options[option] = os.environ[key] packages = os.path.join(subdir, 'Packages') sources = os.path.join(subdir, 'Sources') release = os.path.join(subdir, 'Release') os.chdir(dir) print "Generating package lists." run('apt-ftparchive', ['packages', subdir], packages) gzip(packages) print "Generating source lists." run('apt-ftparchive', ['sources', subdir], sources) gzip(sources) print "Generating release file." args = [] for option in options: if options[option]: args.append('-oAPT::FTPArchive::Release::%s=%s' % (option.capitalize(), options[option])) args.extend(['release', subdir]) run('apt-ftparchive', args, release) print "Signing release file." sign(release) if __name__ == '__main__': sys.exit(main(sys.argv))