-
Notifications
You must be signed in to change notification settings - Fork 5
/
dapopulate
executable file
·99 lines (88 loc) · 4.53 KB
/
dapopulate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
"""
Populate a development repository from other APT repository, and emit
the binary dependencies manifest.
"""
import dabuildsys
from dabuildsys import reprepro, BuildError
import argparse
import debian.deb822
import glob
import os
import sys
def main():
argparser = argparse.ArgumentParser(description="Populates the development pocket of given distribution")
argparser.add_argument('--allow-out-of-date', action='store_true', help="Include packages from APT even if there is a newer version in Git")
argparser.add_argument('--use-development', action='store_true', help="Use development pocket of donor instead of production")
argparser.add_argument('--handle-broken', choices=['ignore', 'include', 'error'], default='error',
help="How to handle packages with invalid structure in Git")
argparser.add_argument('release', choices=dabuildsys.releases, help="Release to populate")
argparser.add_argument('donor', choices=dabuildsys.releases, help="Release to get packages from")
args = argparser.parse_args()
# Get the repositories involved
repo = dabuildsys.APTDistribution(args.release + '-development')
if args.use_development:
_, _, donor_repo = dabuildsys.get_release(args.donor)
else:
donor_repo = dabuildsys.APTDistribution(args.donor)
# Refuse to deal with non-empty repos
if repo.sources or repo.binaries:
raise BuildError("The repository appears to be not empty, cannot populate")
# Get the list of all packages, including, in some cases, packages which are malformed
# or equivs (FIXME: this should be removed)
print "Scanning the source checkout to determine the latest released versions"
packages = []
for package_name, package_path in dabuildsys.package_map.iteritems():
try:
package = dabuildsys.PackageCheckout(package_name)
if args.donor not in package.get_supported_releases():
continue
packages.append( (package.name, package.released_version) )
except BuildError as err:
if args.handle_broken == 'ignore':
pass
elif args.handle_broken == 'include':
try:
with open( os.path.join(package_path, 'debian/changelog') ) as f:
dch = f.read()
package_name, _, _, version = dabuildsys.PackageCheckout.parse_changelog(dch)
packages.append( (package_name, version) )
except IOError as err:
# FIXME FIXME prithee FIXME
# This code should be gone once equivs packages are gone
equivs_path, = glob.glob(os.path.join(package_path, '*.equivs'))
with open( equivs_path ) as f:
equivs = list(debian.deb822.Deb822.iter_paragraphs(f))
packages.append( (package_name, debian.debian_support.Version(equivs[1]['Version']) ) )
else:
raise
# Prevent populating the repository with out-of-date packages
print "Checking the version consistency of donor repository against Git"
for package_name, version in packages:
donor_version = donor_repo.sources[package_name].version
if donor_version < version:
if args.allow_out_of_date:
print "WARNING: package %s is out-of-date in donor repository" % package_name
else:
raise BuildError("Package %s is out-of-date in donor repository" % package_name)
all_versions = reprepro.list_package_versions(package_name)
source_versions = [vers['source'] for dname, vers in all_versions.iteritems() if 'source' in vers]
if donor_version < max(source_versions):
raise BuildError("Package %s has version %s in donor, but %s exists" % (package_name, donor_version, max(source_versions)))
# Actually populate the repository
print "Populating %s with %i packages from %s" % (repo.name, len(packages), donor_repo.name)
try:
for package_name, git_version in packages:
pkg = donor_repo.sources[package_name]
print "Copying %s from %s to %s" % (package_name, pkg.origin, repo.name)
reprepro.copy_package(pkg, pkg.origin, repo.name, export=False)
finally:
print reprepro.call('export', repo.name)
if __name__ == '__main__':
if not dabuildsys.claim_lock():
print >>sys.stderr, "The lock is in place; unable to proceed"
sys.exit(1)
try:
main()
finally:
dabuildsys.release_lock()