+########################################################################
+
+def sign_release_dir(suite, dirname):
+ cnf = Config()
+
+ if cnf.has_key("Dinstall::SigningKeyring"):
+ keyring = "--secret-keyring \"%s\"" % cnf["Dinstall::SigningKeyring"]
+ if cnf.has_key("Dinstall::SigningPubKeyring"):
+ keyring += " --keyring \"%s\"" % cnf["Dinstall::SigningPubKeyring"]
+
+ arguments = "--no-options --batch --no-tty --armour --personal-digest-preferences=SHA256"
+
+ relname = os.path.join(dirname, 'Release')
+
+ dest = os.path.join(dirname, 'Release.gpg')
+ if os.path.exists(dest):
+ os.unlink(dest)
+
+ inlinedest = os.path.join(dirname, 'InRelease')
+ if os.path.exists(inlinedest):
+ os.unlink(inlinedest)
+
+ defkeyid=""
+ for keyid in suite.signingkeys or []:
+ defkeyid += "--local-user %s " % keyid
+
+ os.system("gpg %s %s %s --detach-sign <%s >>%s" %
+ (keyring, defkeyid, arguments, relname, dest))
+ os.system("gpg %s %s %s --clearsign <%s >>%s" %
+ (keyring, defkeyid, arguments, relname, inlinedest))
+
+class XzFile(object):
+ def __init__(self, filename, mode='r'):
+ self.filename = filename
+ def read(self):
+ cmd = ("xz", "-d")
+ with open(self.filename, 'r') as stdin:
+ process = daklib.daksubprocess.Popen(cmd, stdin=stdin, stdout=subprocess.PIPE)
+ (stdout, stderr) = process.communicate()
+ return stdout
+
+
+class HashFunc(object):
+ def __init__(self, release_field, func, db_name):
+ self.release_field = release_field
+ self.func = func
+ self.db_name = db_name
+
+RELEASE_HASHES = [
+ HashFunc('MD5Sum', apt_pkg.md5sum, 'md5'),
+ HashFunc('SHA1', apt_pkg.sha1sum, 'sha1'),
+ HashFunc('SHA256', apt_pkg.sha256sum, 'sha256'),
+]
+
+
+class ReleaseWriter(object):
+ def __init__(self, suite):
+ self.suite = suite
+
+ def suite_path(self):
+ """
+ Absolute path to the suite-specific files.
+ """
+ cnf = Config()
+ suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
+
+ return os.path.join(self.suite.archive.path, 'dists',
+ self.suite.suite_name, suite_suffix)
+
+ def suite_release_path(self):
+ """
+ Absolute path where Release files are physically stored.
+ This should be a path that sorts after the dists/ directory.
+ """
+ # TODO: Eventually always create Release in `zzz-dists` to avoid
+ # special cases. However we don't want to move existing Release files
+ # for released suites.
+ # See `create_release_symlinks` below.
+ if not self.suite.byhash:
+ return self.suite_path()
+
+ cnf = Config()
+ suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
+
+ return os.path.join(self.suite.archive.path, 'zzz-dists',
+ self.suite.suite_name, suite_suffix)
+
+ def create_release_symlinks(self):
+ """
+ Create symlinks for Release files.
+ This creates the symlinks for Release files in the `suite_path`
+ to the actual files in `suite_release_path`.
+ """
+ # TODO: Eventually always create the links.
+ # See `suite_release_path` above.
+ if not self.suite.byhash:
+ return
+
+ relpath = os.path.relpath(self.suite_release_path(), self.suite_path())
+ for f in ("Release", "Release.gpg", "InRelease"):
+ source = os.path.join(relpath, f)
+ dest = os.path.join(self.suite_path(), f)
+ if not os.path.islink(dest):
+ os.unlink(dest)
+ elif os.readlink(dest) == source:
+ continue
+ else:
+ os.unlink(dest)
+ os.symlink(source, dest)
+
+ def create_output_directories(self):
+ for path in (self.suite_path(), self.suite_release_path()):
+ try:
+ os.makedirs(path)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ def generate_release_files(self):
+ """
+ Generate Release files for the given suite
+
+ @type suite: string
+ @param suite: Suite name
+ """
+
+ suite = self.suite
+ session = object_session(suite)
+
+ architectures = get_suite_architectures(suite.suite_name, skipall=True, skipsrc=True, session=session)
+
+ # Attribs contains a tuple of field names and the database names to use to
+ # fill them in
+ attribs = ( ('Origin', 'origin'),
+ ('Label', 'label'),
+ ('Suite', 'release_suite_output'),
+ ('Version', 'version'),
+ ('Codename', 'codename'),
+ ('Changelogs', 'changelog_url'),
+ )
+
+ # A "Sub" Release file has slightly different fields
+ subattribs = ( ('Archive', 'suite_name'),
+ ('Origin', 'origin'),
+ ('Label', 'label'),
+ ('Version', 'version') )
+
+ # Boolean stuff. If we find it true in database, write out "yes" into the release file
+ boolattrs = ( ('NotAutomatic', 'notautomatic'),
+ ('ButAutomaticUpgrades', 'butautomaticupgrades'),
+ ('Acquire-By-Hash', 'byhash'),
+ )
+
+ cnf = Config()
+
+ suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
+
+ self.create_output_directories()
+ self.create_release_symlinks()
+
+ outfile = os.path.join(self.suite_release_path(), "Release")
+ out = open(outfile + ".new", "w")
+
+ for key, dbfield in attribs:
+ # Hack to skip NULL Version fields as we used to do this
+ # We should probably just always ignore anything which is None
+ if key in ("Version", "Changelogs") and getattr(suite, dbfield) is None:
+ continue
+
+ out.write("%s: %s\n" % (key, getattr(suite, dbfield)))
+
+ out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
+
+ if suite.validtime:
+ validtime=float(suite.validtime)
+ out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))