keys[key]["uid"] = uid
if keyid != None: continue
- keyid = database.get_or_set_uid_id(uid)
+ keyid = get_or_set_uid_id(uid).uid
byuid[keyid] = (uid, name)
byname[uid] = (keyid, name)
keys[x]["uid"] = format % "invalid-uid"
else:
uid = format % keys[x]["email"]
- keyid = database.get_or_set_uid_id(uid)
+ keyid = get_or_set_uid(uid).uid
byuid[keyid] = (uid, keys[x]["name"])
byname[uid] = (keyid, keys[x]["name"])
keys[x]["uid"] = uid
if any_invalid:
uid = format % "invalid-uid"
- keyid = database.get_or_set_uid_id(uid)
+ keyid = get_or_set_uid_id(uid).uid
byuid[keyid] = (uid, "ungeneratable user id")
byname[uid] = (keyid, "ungeneratable user id")
return (byname, byuid)
is_dm = cnf["Import-Keyring::"+keyringname+"::Debian-Maintainer"]
- keyring_id = database.get_or_set_keyring_id(
- keyringname.split("/")[-1])
+ keyring_id = get_or_set_keyring(
+ keyringname.split("/")[-1], session,
+ ).keyring_id
### Generate new uid entries if they're needed (from LDAP or the keyring)
(desuid_byname, desuid_byid) = keyring.generate_desired_users()
import os
import re
import sys
+import gzip
import apt_pkg
import apt_inst
for component in components:
filename = "%s/dists/%s/%s/binary-%s/Packages.gz" % (cnf["Dir::Root"], suites[0], component, architecture)
# apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
- (fd, temp_filename) = utils.temp_filename()
- (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
- if (result != 0):
- utils.fubar("Gunzip invocation failed!\n%s\n" % (output), result)
- packages = utils.open_file(temp_filename)
+ packages = gzip.open(filename, 'rb')
Packages = apt_pkg.ParseTagFile(packages)
while Packages.Step():
package = Packages.Section.Find("Package")
virtual_packages[virtual_pkg] += 1
p2c[package] = component
packages.close()
- os.unlink(temp_filename)
# If a virtual package is only provided by the to-be-removed
# packages, treat the virtual package as to-be-removed too.
for component in components:
filename = "%s/dists/%s/%s/source/Sources.gz" % (cnf["Dir::Root"], suites[0], component)
# apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
- (fd, temp_filename) = utils.temp_filename()
- result, output = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
- if result != 0:
- sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
- sys.exit(result)
- sources = utils.open_file(temp_filename, "r")
+ sources = gzip.open(filename, 'rb')
Sources = apt_pkg.ParseTagFile(sources)
while Sources.Step():
source = Sources.Section.Find("Package")
__all__.append('Keyring')
+def get_or_set_keyring(keyring, session=None):
+ """
+ If C{keyring} does not have an entry in the C{keyrings} table yet, create one
+ and return the new Keyring
+ If C{keyring} already has an entry, simply return the existing Keyring
+
+ @type keyring: string
+ @param keyring: the keyring name
+
+ @rtype: Keyring
+ @return: the Keyring object for this keyring
+
+ """
+ privatetrans = False
+ if session is None:
+ session = DBConn().session()
+ privatetrans = True
+
+ try:
+ obj = session.query(Keyring).filter_by(keyring_name=keyring).first()
+
+ if obj is None:
+ obj = Keyring(keyring_name=keyring)
+ session.add(obj)
+ if privatetrans:
+ session.commit()
+ else:
+ session.flush()
+
+ return obj
+ finally:
+ if privatetrans:
+ session.close()
+
+__all__.append('get_or_set_keyring')
+
################################################################################
class Location(object):