提交 30413cf0 编写于 作者: J James Troup

Globally remove trailing semi-colon damage.

上级 a1692ffe
此差异已折叠。
...@@ -47,14 +47,14 @@ ...@@ -47,14 +47,14 @@
################################################################################ ################################################################################
import pg, sys, os; import pg, sys, os
import utils, db_access, logging; import utils, db_access, logging
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Options = None; Options = None
projectB = None; projectB = None
Logger = None Logger = None
sections = {} sections = {}
priorities = {} priorities = {}
...@@ -79,58 +79,58 @@ def gen_blacklist(dir): ...@@ -79,58 +79,58 @@ def gen_blacklist(dir):
blacklist[entry] = 1 blacklist[entry] = 1
def process(osuite, affected_suites, originosuite, component, type): def process(osuite, affected_suites, originosuite, component, type):
global Logger, Options, projectB, sections, priorities; global Logger, Options, projectB, sections, priorities
osuite_id = db_access.get_suite_id(osuite); osuite_id = db_access.get_suite_id(osuite)
if osuite_id == -1: if osuite_id == -1:
utils.fubar("Suite '%s' not recognised." % (osuite)); utils.fubar("Suite '%s' not recognised." % (osuite))
originosuite_id = None originosuite_id = None
if originosuite: if originosuite:
originosuite_id = db_access.get_suite_id(originosuite); originosuite_id = db_access.get_suite_id(originosuite)
if originosuite_id == -1: if originosuite_id == -1:
utils.fubar("Suite '%s' not recognised." % (originosuite)); utils.fubar("Suite '%s' not recognised." % (originosuite))
component_id = db_access.get_component_id(component); component_id = db_access.get_component_id(component)
if component_id == -1: if component_id == -1:
utils.fubar("Component '%s' not recognised." % (component)); utils.fubar("Component '%s' not recognised." % (component))
type_id = db_access.get_override_type_id(type); type_id = db_access.get_override_type_id(type)
if type_id == -1: if type_id == -1:
utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type)); utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type))
dsc_type_id = db_access.get_override_type_id("dsc"); dsc_type_id = db_access.get_override_type_id("dsc")
deb_type_id = db_access.get_override_type_id("deb") deb_type_id = db_access.get_override_type_id("deb")
source_priority_id = db_access.get_priority_id("source") source_priority_id = db_access.get_priority_id("source")
if type == "deb" or type == "udeb": if type == "deb" or type == "udeb":
packages = {}; packages = {}
q = projectB.query(""" q = projectB.query("""
SELECT b.package FROM binaries b, bin_associations ba, files f, SELECT b.package FROM binaries b, bin_associations ba, files f,
location l, component c location l, component c
WHERE b.type = '%s' AND b.id = ba.bin AND f.id = b.file AND l.id = f.location WHERE b.type = '%s' AND b.id = ba.bin AND f.id = b.file AND l.id = f.location
AND c.id = l.component AND ba.suite IN (%s) AND c.id = %s AND c.id = l.component AND ba.suite IN (%s) AND c.id = %s
""" % (type, ",".join(map(str,affected_suites)), component_id)); """ % (type, ",".join(map(str,affected_suites)), component_id))
for i in q.getresult(): for i in q.getresult():
packages[i[0]] = 0; packages[i[0]] = 0
src_packages = {}; src_packages = {}
q = projectB.query(""" q = projectB.query("""
SELECT s.source FROM source s, src_associations sa, files f, location l, SELECT s.source FROM source s, src_associations sa, files f, location l,
component c component c
WHERE s.id = sa.source AND f.id = s.file AND l.id = f.location WHERE s.id = sa.source AND f.id = s.file AND l.id = f.location
AND c.id = l.component AND sa.suite IN (%s) AND c.id = %s AND c.id = l.component AND sa.suite IN (%s) AND c.id = %s
""" % (",".join(map(str,affected_suites)), component_id)); """ % (",".join(map(str,affected_suites)), component_id))
for i in q.getresult(): for i in q.getresult():
src_packages[i[0]] = 0; src_packages[i[0]] = 0
# ----------- # -----------
# Drop unused overrides # Drop unused overrides
q = projectB.query("SELECT package, priority, section, maintainer FROM override WHERE suite = %s AND component = %s AND type = %s" % (osuite_id, component_id, type_id)); q = projectB.query("SELECT package, priority, section, maintainer FROM override WHERE suite = %s AND component = %s AND type = %s" % (osuite_id, component_id, type_id))
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
if type == "dsc": if type == "dsc":
for i in q.getresult(): for i in q.getresult():
package = i[0]; package = i[0]
if src_packages.has_key(package): if src_packages.has_key(package):
src_packages[package] = 1 src_packages[package] = 1
else: else:
...@@ -142,12 +142,12 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -142,12 +142,12 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
if not Options["No-Action"]: if not Options["No-Action"]:
projectB.query("""DELETE FROM override WHERE package = projectB.query("""DELETE FROM override WHERE package =
'%s' AND suite = %s AND component = %s AND type = '%s' AND suite = %s AND component = %s AND type =
%s""" % (package, osuite_id, component_id, type_id)); %s""" % (package, osuite_id, component_id, type_id))
# create source overrides based on binary overrides, as source # create source overrides based on binary overrides, as source
# overrides not always get created # overrides not always get created
q = projectB.query(""" SELECT package, priority, section, q = projectB.query(""" SELECT package, priority, section,
maintainer FROM override WHERE suite = %s AND component = %s maintainer FROM override WHERE suite = %s AND component = %s
""" % (osuite_id, component_id)); """ % (osuite_id, component_id))
for i in q.getresult(): for i in q.getresult():
package = i[0] package = i[0]
if not src_packages.has_key(package) or src_packages[package]: if not src_packages.has_key(package) or src_packages[package]:
...@@ -161,7 +161,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -161,7 +161,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
component, priority, section, type, maintainer) VALUES component, priority, section, type, maintainer) VALUES
('%s', %s, %s, %s, %s, %s, '%s')""" % (package, ('%s', %s, %s, %s, %s, %s, '%s')""" % (package,
osuite_id, component_id, source_priority_id, i[2], osuite_id, component_id, source_priority_id, i[2],
dsc_type_id, i[3])); dsc_type_id, i[3]))
# Check whether originosuite has an override for us we can # Check whether originosuite has an override for us we can
# copy # copy
if originosuite: if originosuite:
...@@ -172,7 +172,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -172,7 +172,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
target.suite=%s AND origin.component = target.component AND origin.type = target.suite=%s AND origin.component = target.component AND origin.type =
target.type) WHERE origin.suite = %s AND origin.component = %s target.type) WHERE origin.suite = %s AND origin.component = %s
AND origin.type = %s""" % AND origin.type = %s""" %
(osuite_id, originosuite_id, component_id, type_id)); (osuite_id, originosuite_id, component_id, type_id))
for i in q.getresult(): for i in q.getresult():
package = i[0] package = i[0]
if not src_packages.has_key(package) or src_packages[package]: if not src_packages.has_key(package) or src_packages[package]:
...@@ -184,7 +184,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -184,7 +184,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
maintainer='%s' WHERE package='%s' AND maintainer='%s' WHERE package='%s' AND
suite=%s AND component=%s AND type=%s""" % suite=%s AND component=%s AND type=%s""" %
(i[2], i[3], package, osuite_id, component_id, (i[2], i[3], package, osuite_id, component_id,
dsc_type_id)); dsc_type_id))
continue continue
# we can copy # we can copy
src_packages[package] = 1 src_packages[package] = 1
...@@ -195,7 +195,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -195,7 +195,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
component, priority, section, type, maintainer) VALUES component, priority, section, type, maintainer) VALUES
('%s', %s, %s, %s, %s, %s, '%s')""" % (package, ('%s', %s, %s, %s, %s, %s, '%s')""" % (package,
osuite_id, component_id, source_priority_id, i[2], osuite_id, component_id, source_priority_id, i[2],
dsc_type_id, i[3])); dsc_type_id, i[3]))
for package, hasoverride in src_packages.items(): for package, hasoverride in src_packages.items():
if not hasoverride: if not hasoverride:
...@@ -203,7 +203,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -203,7 +203,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
else: # binary override else: # binary override
for i in q.getresult(): for i in q.getresult():
package = i[0]; package = i[0]
if packages.has_key(package): if packages.has_key(package):
packages[package] = 1 packages[package] = 1
else: else:
...@@ -215,7 +215,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -215,7 +215,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
if not Options["No-Action"]: if not Options["No-Action"]:
projectB.query("""DELETE FROM override WHERE package = projectB.query("""DELETE FROM override WHERE package =
'%s' AND suite = %s AND component = %s AND type = '%s' AND suite = %s AND component = %s AND type =
%s""" % (package, osuite_id, component_id, type_id)); %s""" % (package, osuite_id, component_id, type_id))
# Check whether originosuite has an override for us we can # Check whether originosuite has an override for us we can
# copy # copy
...@@ -227,7 +227,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -227,7 +227,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
target.suite=%s AND origin.component = target.component AND target.suite=%s AND origin.component = target.component AND
origin.type = target.type) WHERE origin.suite = %s AND origin.type = target.type) WHERE origin.suite = %s AND
origin.component = %s AND origin.type = %s""" % (osuite_id, origin.component = %s AND origin.type = %s""" % (osuite_id,
originosuite_id, component_id, type_id)); originosuite_id, component_id, type_id))
for i in q.getresult(): for i in q.getresult():
package = i[0] package = i[0]
if not packages.has_key(package) or packages[package]: if not packages.has_key(package) or packages[package]:
...@@ -240,7 +240,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -240,7 +240,7 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
maintainer='%s' WHERE package='%s' AND maintainer='%s' WHERE package='%s' AND
suite=%s AND component=%s AND type=%s""" % suite=%s AND component=%s AND type=%s""" %
(i[1], i[2], i[3], package, osuite_id, (i[1], i[2], i[3], package, osuite_id,
component_id, type_id)); component_id, type_id))
continue continue
# we can copy # we can copy
packages[package] = 1 packages[package] = 1
...@@ -249,36 +249,36 @@ SELECT s.source FROM source s, src_associations sa, files f, location l, ...@@ -249,36 +249,36 @@ SELECT s.source FROM source s, src_associations sa, files f, location l,
if not Options["No-Action"]: if not Options["No-Action"]:
projectB.query("""INSERT INTO override (package, suite, projectB.query("""INSERT INTO override (package, suite,
component, priority, section, type, maintainer) VALUES component, priority, section, type, maintainer) VALUES
('%s', %s, %s, %s, %s, %s, '%s')""" % (package, osuite_id, component_id, i[1], i[2], type_id, i[3])); ('%s', %s, %s, %s, %s, %s, '%s')""" % (package, osuite_id, component_id, i[1], i[2], type_id, i[3]))
for package, hasoverride in packages.items(): for package, hasoverride in packages.items():
if not hasoverride: if not hasoverride:
utils.warn("%s has no override!" % package) utils.warn("%s has no override!" % package)
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
sys.stdout.flush() sys.stdout.flush()
################################################################################ ################################################################################
def main (): def main ():
global Logger, Options, projectB, sections, priorities; global Logger, Options, projectB, sections, priorities
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('h',"help","Cindy::Options::Help"), Arguments = [('h',"help","Cindy::Options::Help"),
('n',"no-action", "Cindy::Options::No-Action")]; ('n',"no-action", "Cindy::Options::No-Action")]
for i in [ "help", "no-action" ]: for i in [ "help", "no-action" ]:
if not Cnf.has_key("Cindy::Options::%s" % (i)): if not Cnf.has_key("Cindy::Options::%s" % (i)):
Cnf["Cindy::Options::%s" % (i)] = ""; Cnf["Cindy::Options::%s" % (i)] = ""
apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv); apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
Options = Cnf.SubTree("Cindy::Options") Options = Cnf.SubTree("Cindy::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
# init sections, priorities: # init sections, priorities:
q = projectB.query("SELECT id, section FROM section") q = projectB.query("SELECT id, section FROM section")
...@@ -304,13 +304,13 @@ def main (): ...@@ -304,13 +304,13 @@ def main ():
originosuite = None originosuite = None
originremark = "" originremark = ""
try: try:
originosuite = Cnf["Cindy::OverrideSuites::%s::OriginSuite" % osuite]; originosuite = Cnf["Cindy::OverrideSuites::%s::OriginSuite" % osuite]
originosuite = originosuite.lower() originosuite = originosuite.lower()
originremark = " taking missing from %s" % originosuite originremark = " taking missing from %s" % originosuite
except KeyError: except KeyError:
pass pass
print "Processing %s%s..." % (osuite, originremark); print "Processing %s%s..." % (osuite, originremark)
# Get a list of all suites that use the override file of 'osuite' # Get a list of all suites that use the override file of 'osuite'
ocodename = Cnf["Suite::%s::codename" % osuite] ocodename = Cnf["Suite::%s::codename" % osuite]
suites = [] suites = []
...@@ -338,9 +338,9 @@ def main (): ...@@ -338,9 +338,9 @@ def main ():
otypes = ["dsc"] + otypes otypes = ["dsc"] + otypes
for otype in otypes: for otype in otypes:
print "Processing %s [%s - %s] using %s..." \ print "Processing %s [%s - %s] using %s..." \
% (osuite, component, otype, suites); % (osuite, component, otype, suites)
sys.stdout.flush() sys.stdout.flush()
process(osuite, suiteids, originosuite, component, otype); process(osuite, suiteids, originosuite, component, otype)
Logger.close() Logger.close()
......
...@@ -29,18 +29,18 @@ ...@@ -29,18 +29,18 @@
################################################################################ ################################################################################
import pg, sys, os; import pg, sys, os
import utils, db_access import utils, db_access
import apt_pkg, apt_inst; import apt_pkg, apt_inst
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
Options = None; Options = None
stable = {}; stable = {}
stable_virtual = {}; stable_virtual = {}
architectures = None; architectures = None
################################################################################ ################################################################################
...@@ -59,105 +59,105 @@ Need either changes files, deb files or an admin.txt file with a '.joey' suffix. ...@@ -59,105 +59,105 @@ Need either changes files, deb files or an admin.txt file with a '.joey' suffix.
def d_test (dict, key, positive, negative): def d_test (dict, key, positive, negative):
if not dict: if not dict:
return negative; return negative
if dict.has_key(key): if dict.has_key(key):
return positive; return positive
else: else:
return negative; return negative
################################################################################ ################################################################################
def check_dep (depends, dep_type, check_archs, filename, files): def check_dep (depends, dep_type, check_archs, filename, files):
pkg_unsat = 0; pkg_unsat = 0
for arch in check_archs: for arch in check_archs:
for parsed_dep in apt_pkg.ParseDepends(depends): for parsed_dep in apt_pkg.ParseDepends(depends):
unsat = []; unsat = []
for atom in parsed_dep: for atom in parsed_dep:
(dep, version, constraint) = atom; (dep, version, constraint) = atom
# As a real package? # As a real package?
if stable.has_key(dep): if stable.has_key(dep):
if stable[dep].has_key(arch): if stable[dep].has_key(arch):
if apt_pkg.CheckDep(stable[dep][arch], constraint, version): if apt_pkg.CheckDep(stable[dep][arch], constraint, version):
if Options["debug"]: if Options["debug"]:
print "Found %s as a real package." % (utils.pp_deps(parsed_dep)); print "Found %s as a real package." % (utils.pp_deps(parsed_dep))
unsat = 0; unsat = 0
break; break
# As a virtual? # As a virtual?
if stable_virtual.has_key(dep): if stable_virtual.has_key(dep):
if stable_virtual[dep].has_key(arch): if stable_virtual[dep].has_key(arch):
if not constraint and not version: if not constraint and not version:
if Options["debug"]: if Options["debug"]:
print "Found %s as a virtual package." % (utils.pp_deps(parsed_dep)); print "Found %s as a virtual package." % (utils.pp_deps(parsed_dep))
unsat = 0; unsat = 0
break; break
# As part of the same .changes? # As part of the same .changes?
epochless_version = utils.re_no_epoch.sub('', version) epochless_version = utils.re_no_epoch.sub('', version)
dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch); dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch)
if files.has_key(dep_filename): if files.has_key(dep_filename):
if Options["debug"]: if Options["debug"]:
print "Found %s in the same upload." % (utils.pp_deps(parsed_dep)); print "Found %s in the same upload." % (utils.pp_deps(parsed_dep))
unsat = 0; unsat = 0
break; break
# Not found... # Not found...
# [FIXME: must be a better way ... ] # [FIXME: must be a better way ... ]
error = "%s not found. [Real: " % (utils.pp_deps(parsed_dep)) error = "%s not found. [Real: " % (utils.pp_deps(parsed_dep))
if stable.has_key(dep): if stable.has_key(dep):
if stable[dep].has_key(arch): if stable[dep].has_key(arch):
error += "%s:%s:%s" % (dep, arch, stable[dep][arch]); error += "%s:%s:%s" % (dep, arch, stable[dep][arch])
else: else:
error += "%s:-:-" % (dep); error += "%s:-:-" % (dep)
else: else:
error += "-:-:-"; error += "-:-:-"
error += ", Virtual: "; error += ", Virtual: "
if stable_virtual.has_key(dep): if stable_virtual.has_key(dep):
if stable_virtual[dep].has_key(arch): if stable_virtual[dep].has_key(arch):
error += "%s:%s" % (dep, arch); error += "%s:%s" % (dep, arch)
else: else:
error += "%s:-"; error += "%s:-"
else: else:
error += "-:-"; error += "-:-"
error += ", Upload: "; error += ", Upload: "
if files.has_key(dep_filename): if files.has_key(dep_filename):
error += "yes"; error += "yes"
else: else:
error += "no"; error += "no"
error += "]"; error += "]"
unsat.append(error); unsat.append(error)
if unsat: if unsat:
sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, utils.pp_deps(parsed_dep), dep_type)); sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, utils.pp_deps(parsed_dep), dep_type))
for error in unsat: for error in unsat:
sys.stderr.write(" %s\n" % (error)); sys.stderr.write(" %s\n" % (error))
pkg_unsat = 1; pkg_unsat = 1
return pkg_unsat; return pkg_unsat
def check_package(filename, files): def check_package(filename, files):
try: try:
control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename))); control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename)))
except: except:
utils.warn("%s: debExtractControl() raised %s." % (filename, sys.exc_type)); utils.warn("%s: debExtractControl() raised %s." % (filename, sys.exc_type))
return 1; return 1
Depends = control.Find("Depends"); Depends = control.Find("Depends")
Pre_Depends = control.Find("Pre-Depends"); Pre_Depends = control.Find("Pre-Depends")
#Recommends = control.Find("Recommends"); #Recommends = control.Find("Recommends")
pkg_arch = control.Find("Architecture"); pkg_arch = control.Find("Architecture")
base_file = os.path.basename(filename); base_file = os.path.basename(filename)
if pkg_arch == "all": if pkg_arch == "all":
check_archs = architectures; check_archs = architectures
else: else:
check_archs = [pkg_arch]; check_archs = [pkg_arch]
pkg_unsat = 0; pkg_unsat = 0
if Pre_Depends: if Pre_Depends:
pkg_unsat += check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files); pkg_unsat += check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files)
if Depends: if Depends:
pkg_unsat += check_dep(Depends, "dependency", check_archs, base_file, files); pkg_unsat += check_dep(Depends, "dependency", check_archs, base_file, files)
#if Recommends: #if Recommends:
#pkg_unsat += check_dep(Recommends, "recommendation", check_archs, base_file, files); #pkg_unsat += check_dep(Recommends, "recommendation", check_archs, base_file, files)
return pkg_unsat; return pkg_unsat
################################################################################ ################################################################################
...@@ -165,142 +165,142 @@ def pass_fail (filename, result): ...@@ -165,142 +165,142 @@ def pass_fail (filename, result):
if not Options["quiet"]: if not Options["quiet"]:
print "%s:" % (os.path.basename(filename)), print "%s:" % (os.path.basename(filename)),
if result: if result:
print "FAIL"; print "FAIL"
else: else:
print "ok"; print "ok"
################################################################################ ################################################################################
def check_changes (filename): def check_changes (filename):
try: try:
changes = utils.parse_changes(filename); changes = utils.parse_changes(filename)
files = utils.build_file_list(changes); files = utils.build_file_list(changes)
except: except:
utils.warn("Error parsing changes file '%s'" % (filename)); utils.warn("Error parsing changes file '%s'" % (filename))
return; return
result = 0; result = 0
# Move to the pool directory # Move to the pool directory
cwd = os.getcwd(); cwd = os.getcwd()
file = files.keys()[0]; file = files.keys()[0]
pool_dir = Cnf["Dir::Pool"] + '/' + utils.poolify(changes["source"], files[file]["component"]); pool_dir = Cnf["Dir::Pool"] + '/' + utils.poolify(changes["source"], files[file]["component"])
os.chdir(pool_dir); os.chdir(pool_dir)
changes_result = 0; changes_result = 0
for file in files.keys(): for file in files.keys():
if file.endswith(".deb"): if file.endswith(".deb"):
result = check_package(file, files); result = check_package(file, files)
if Options["verbose"]: if Options["verbose"]:
pass_fail(file, result); pass_fail(file, result)
changes_result += result; changes_result += result
pass_fail (filename, changes_result); pass_fail (filename, changes_result)
# Move back # Move back
os.chdir(cwd); os.chdir(cwd)
################################################################################ ################################################################################
def check_deb (filename): def check_deb (filename):
result = check_package(filename, {}); result = check_package(filename, {})
pass_fail(filename, result); pass_fail(filename, result)
################################################################################ ################################################################################
def check_joey (filename): def check_joey (filename):
file = utils.open_file(filename); file = utils.open_file(filename)
cwd = os.getcwd(); cwd = os.getcwd()
os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"])); os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]))
for line in file.readlines(): for line in file.readlines():
line = line.rstrip(); line = line.rstrip()
if line.find('install') != -1: if line.find('install') != -1:
split_line = line.split(); split_line = line.split()
if len(split_line) != 2: if len(split_line) != 2:
utils.fubar("Parse error (not exactly 2 elements): %s" % (line)); utils.fubar("Parse error (not exactly 2 elements): %s" % (line))
install_type = split_line[0]; install_type = split_line[0]
if install_type not in [ "install", "install-u", "sync-install" ]: if install_type not in [ "install", "install-u", "sync-install" ]:
utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line)); utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line))
changes_filename = split_line[1] changes_filename = split_line[1]
if Options["debug"]: if Options["debug"]:
print "Processing %s..." % (changes_filename); print "Processing %s..." % (changes_filename)
check_changes(changes_filename); check_changes(changes_filename)
file.close(); file.close()
os.chdir(cwd); os.chdir(cwd)
################################################################################ ################################################################################
def parse_packages(): def parse_packages():
global stable, stable_virtual, architectures; global stable, stable_virtual, architectures
# Parse the Packages files (since it's a sub-second operation on auric) # Parse the Packages files (since it's a sub-second operation on auric)
suite = "stable"; suite = "stable"
stable = {}; stable = {}
components = Cnf.ValueList("Suite::%s::Components" % (suite)); components = Cnf.ValueList("Suite::%s::Components" % (suite))
architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite))); architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)))
for component in components: for component in components:
for architecture in architectures: for architecture in architectures:
filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture); filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture)
packages = utils.open_file(filename, 'r'); packages = utils.open_file(filename, 'r')
Packages = apt_pkg.ParseTagFile(packages); Packages = apt_pkg.ParseTagFile(packages)
while Packages.Step(): while Packages.Step():
package = Packages.Section.Find('Package'); package = Packages.Section.Find('Package')
version = Packages.Section.Find('Version'); version = Packages.Section.Find('Version')
provides = Packages.Section.Find('Provides'); provides = Packages.Section.Find('Provides')
if not stable.has_key(package): if not stable.has_key(package):
stable[package] = {}; stable[package] = {}
stable[package][architecture] = version; stable[package][architecture] = version
if provides: if provides:
for virtual_pkg in provides.split(","): for virtual_pkg in provides.split(","):
virtual_pkg = virtual_pkg.strip(); virtual_pkg = virtual_pkg.strip()
if not stable_virtual.has_key(virtual_pkg): if not stable_virtual.has_key(virtual_pkg):
stable_virtual[virtual_pkg] = {}; stable_virtual[virtual_pkg] = {}
stable_virtual[virtual_pkg][architecture] = "NA"; stable_virtual[virtual_pkg][architecture] = "NA"
packages.close() packages.close()
################################################################################ ################################################################################
def main (): def main ():
global Cnf, projectB, Options; global Cnf, projectB, Options
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('d', "debug", "Jeri::Options::Debug"), Arguments = [('d', "debug", "Jeri::Options::Debug"),
('q',"quiet","Jeri::Options::Quiet"), ('q',"quiet","Jeri::Options::Quiet"),
('v',"verbose","Jeri::Options::Verbose"), ('v',"verbose","Jeri::Options::Verbose"),
('h',"help","Jeri::Options::Help")]; ('h',"help","Jeri::Options::Help")]
for i in [ "debug", "quiet", "verbose", "help" ]: for i in [ "debug", "quiet", "verbose", "help" ]:
if not Cnf.has_key("Jeri::Options::%s" % (i)): if not Cnf.has_key("Jeri::Options::%s" % (i)):
Cnf["Jeri::Options::%s" % (i)] = ""; Cnf["Jeri::Options::%s" % (i)] = ""
arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Jeri::Options") Options = Cnf.SubTree("Jeri::Options")
if Options["Help"]: if Options["Help"]:
usage(0); usage(0)
if not arguments: if not arguments:
utils.fubar("need at least one package name as an argument."); utils.fubar("need at least one package name as an argument.")
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
print "Parsing packages files...", print "Parsing packages files...",
parse_packages(); parse_packages()
print "done."; print "done."
for file in arguments: for file in arguments:
if file.endswith(".changes"): if file.endswith(".changes"):
check_changes(file); check_changes(file)
elif file.endswith(".deb"): elif file.endswith(".deb"):
check_deb(file); check_deb(file)
elif file.endswith(".joey"): elif file.endswith(".joey"):
check_joey(file); check_joey(file)
else: else:
utils.fubar("Unrecognised file type: '%s'." % (file)); utils.fubar("Unrecognised file type: '%s'." % (file))
####################################################################################### #######################################################################################
......
...@@ -20,18 +20,18 @@ ...@@ -20,18 +20,18 @@
################################################################################ ################################################################################
import os, pg, re, sys; import os, pg, re, sys
import utils, db_access; import utils, db_access
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
Options = None; Options = None
pu = {}; pu = {}
re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$"); re_isdeb = re.compile (r"^(.+)_(.+?)_(.+?).u?deb$")
################################################################################ ################################################################################
...@@ -49,91 +49,91 @@ Need either changes files or an admin.txt file with a '.joey' suffix.""" ...@@ -49,91 +49,91 @@ Need either changes files or an admin.txt file with a '.joey' suffix."""
def check_changes (filename): def check_changes (filename):
try: try:
changes = utils.parse_changes(filename); changes = utils.parse_changes(filename)
files = utils.build_file_list(changes); files = utils.build_file_list(changes)
except: except:
utils.warn("Couldn't read changes file '%s'." % (filename)); utils.warn("Couldn't read changes file '%s'." % (filename))
return; return
num_files = len(files.keys()); num_files = len(files.keys())
for file in files.keys(): for file in files.keys():
if utils.re_isadeb.match(file): if utils.re_isadeb.match(file):
m = re_isdeb.match(file); m = re_isdeb.match(file)
pkg = m.group(1); pkg = m.group(1)
version = m.group(2); version = m.group(2)
arch = m.group(3); arch = m.group(3)
if Options["debug"]: if Options["debug"]:
print "BINARY: %s ==> %s_%s_%s" % (file, pkg, version, arch); print "BINARY: %s ==> %s_%s_%s" % (file, pkg, version, arch)
else: else:
m = utils.re_issource.match(file) m = utils.re_issource.match(file)
if m: if m:
pkg = m.group(1); pkg = m.group(1)
version = m.group(2); version = m.group(2)
type = m.group(3); type = m.group(3)
if type != "dsc": if type != "dsc":
del files[file]; del files[file]
num_files -= 1; num_files -= 1
continue; continue
arch = "source"; arch = "source"
if Options["debug"]: if Options["debug"]:
print "SOURCE: %s ==> %s_%s_%s" % (file, pkg, version, arch); print "SOURCE: %s ==> %s_%s_%s" % (file, pkg, version, arch)
else: else:
utils.fubar("unknown type, fix me"); utils.fubar("unknown type, fix me")
if not pu.has_key(pkg): if not pu.has_key(pkg):
# FIXME # FIXME
utils.warn("%s doesn't seem to exist in p-u?? (from %s [%s])" % (pkg, file, filename)); utils.warn("%s doesn't seem to exist in p-u?? (from %s [%s])" % (pkg, file, filename))
continue; continue
if not pu[pkg].has_key(arch): if not pu[pkg].has_key(arch):
# FIXME # FIXME
utils.warn("%s doesn't seem to exist for %s in p-u?? (from %s [%s])" % (pkg, arch, file, filename)); utils.warn("%s doesn't seem to exist for %s in p-u?? (from %s [%s])" % (pkg, arch, file, filename))
continue; continue
pu_version = utils.re_no_epoch.sub('', pu[pkg][arch]); pu_version = utils.re_no_epoch.sub('', pu[pkg][arch])
if pu_version == version: if pu_version == version:
if Options["verbose"]: if Options["verbose"]:
print "%s: ok" % (file); print "%s: ok" % (file)
else: else:
if Options["verbose"]: if Options["verbose"]:
print "%s: superseded, removing. [%s]" % (file, pu_version); print "%s: superseded, removing. [%s]" % (file, pu_version)
del files[file]; del files[file]
new_num_files = len(files.keys()); new_num_files = len(files.keys())
if new_num_files == 0: if new_num_files == 0:
print "%s: no files left, superseded by %s" % (filename, pu_version); print "%s: no files left, superseded by %s" % (filename, pu_version)
dest = Cnf["Dir::Morgue"] + "/misc/"; dest = Cnf["Dir::Morgue"] + "/misc/"
utils.move(filename, dest); utils.move(filename, dest)
elif new_num_files < num_files: elif new_num_files < num_files:
print "%s: lost files, MWAAP." % (filename); print "%s: lost files, MWAAP." % (filename)
else: else:
if Options["verbose"]: if Options["verbose"]:
print "%s: ok" % (filename); print "%s: ok" % (filename)
################################################################################ ################################################################################
def check_joey (filename): def check_joey (filename):
file = utils.open_file(filename); file = utils.open_file(filename)
cwd = os.getcwd(); cwd = os.getcwd()
os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"])); os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]))
for line in file.readlines(): for line in file.readlines():
line = line.rstrip(); line = line.rstrip()
if line.find('install') != -1: if line.find('install') != -1:
split_line = line.split(); split_line = line.split()
if len(split_line) != 2: if len(split_line) != 2:
utils.fubar("Parse error (not exactly 2 elements): %s" % (line)); utils.fubar("Parse error (not exactly 2 elements): %s" % (line))
install_type = split_line[0]; install_type = split_line[0]
if install_type not in [ "install", "install-u", "sync-install" ]: if install_type not in [ "install", "install-u", "sync-install" ]:
utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line)); utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line))
changes_filename = split_line[1] changes_filename = split_line[1]
if Options["debug"]: if Options["debug"]:
print "Processing %s..." % (changes_filename); print "Processing %s..." % (changes_filename)
check_changes(changes_filename); check_changes(changes_filename)
os.chdir(cwd); os.chdir(cwd)
################################################################################ ################################################################################
def init_pu (): def init_pu ():
global pu; global pu
q = projectB.query(""" q = projectB.query("""
SELECT b.package, b.version, a.arch_string SELECT b.package, b.version, a.arch_string
...@@ -144,49 +144,49 @@ UNION SELECT s.source, s.version, 'source' ...@@ -144,49 +144,49 @@ UNION SELECT s.source, s.version, 'source'
FROM src_associations sa, source s, suite su FROM src_associations sa, source s, suite su
WHERE s.id = sa.source AND sa.suite = su.id WHERE s.id = sa.source AND sa.suite = su.id
AND su.suite_name = 'proposed-updates' AND su.suite_name = 'proposed-updates'
ORDER BY package, version, arch_string; ORDER BY package, version, arch_string
"""); """)
ql = q.getresult(); ql = q.getresult()
for i in ql: for i in ql:
pkg = i[0]; pkg = i[0]
version = i[1]; version = i[1]
arch = i[2]; arch = i[2]
if not pu.has_key(pkg): if not pu.has_key(pkg):
pu[pkg] = {}; pu[pkg] = {}
pu[pkg][arch] = version; pu[pkg][arch] = version
def main (): def main ():
global Cnf, projectB, Options; global Cnf, projectB, Options
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('d', "debug", "Halle::Options::Debug"), Arguments = [('d', "debug", "Halle::Options::Debug"),
('v',"verbose","Halle::Options::Verbose"), ('v',"verbose","Halle::Options::Verbose"),
('h',"help","Halle::Options::Help")]; ('h',"help","Halle::Options::Help")]
for i in [ "debug", "verbose", "help" ]: for i in [ "debug", "verbose", "help" ]:
if not Cnf.has_key("Halle::Options::%s" % (i)): if not Cnf.has_key("Halle::Options::%s" % (i)):
Cnf["Halle::Options::%s" % (i)] = ""; Cnf["Halle::Options::%s" % (i)] = ""
arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Halle::Options") Options = Cnf.SubTree("Halle::Options")
if Options["Help"]: if Options["Help"]:
usage(0); usage(0)
if not arguments: if not arguments:
utils.fubar("need at least one package name as an argument."); utils.fubar("need at least one package name as an argument.")
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
init_pu(); init_pu()
for file in arguments: for file in arguments:
if file.endswith(".changes"): if file.endswith(".changes"):
check_changes(file); check_changes(file)
elif file.endswith(".joey"): elif file.endswith(".joey"):
check_joey(file); check_joey(file)
else: else:
utils.fubar("Unrecognised file type: '%s'." % (file)); utils.fubar("Unrecognised file type: '%s'." % (file))
####################################################################################### #######################################################################################
......
...@@ -34,16 +34,16 @@ ...@@ -34,16 +34,16 @@
################################################################################ ################################################################################
import os, stat, sys, time; import os, stat, sys, time
import utils; import utils
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Cnf = None; Cnf = None
Options = None; Options = None
del_dir = None; del_dir = None
delete_date = None; delete_date = None
################################################################################ ################################################################################
...@@ -62,35 +62,35 @@ Clean out incoming directories. ...@@ -62,35 +62,35 @@ Clean out incoming directories.
################################################################################ ################################################################################
def init (): def init ():
global delete_date, del_dir; global delete_date, del_dir
delete_date = int(time.time())-(int(Options["Days"])*84600); delete_date = int(time.time())-(int(Options["Days"])*84600)
# Ensure a directory exists to remove files to # Ensure a directory exists to remove files to
if not Options["No-Action"]: if not Options["No-Action"]:
date = time.strftime("%Y-%m-%d"); date = time.strftime("%Y-%m-%d")
del_dir = Cnf["Dir::Morgue"] + '/' + Cnf["Shania::MorgueSubDir"] + '/' + date; del_dir = Cnf["Dir::Morgue"] + '/' + Cnf["Shania::MorgueSubDir"] + '/' + date
if not os.path.exists(del_dir): if not os.path.exists(del_dir):
os.makedirs(del_dir, 02775); os.makedirs(del_dir, 02775)
if not os.path.isdir(del_dir): if not os.path.isdir(del_dir):
utils.fubar("%s must be a directory." % (del_dir)); utils.fubar("%s must be a directory." % (del_dir))
# Move to the directory to clean # Move to the directory to clean
incoming = Options["Incoming"]; incoming = Options["Incoming"]
if incoming == "": if incoming == "":
incoming = Cnf["Dir::Queue::Unchecked"]; incoming = Cnf["Dir::Queue::Unchecked"]
os.chdir(incoming); os.chdir(incoming)
# Remove a file to the morgue # Remove a file to the morgue
def remove (file): def remove (file):
if os.access(file, os.R_OK): if os.access(file, os.R_OK):
dest_filename = del_dir + '/' + os.path.basename(file); dest_filename = del_dir + '/' + os.path.basename(file)
# If the destination file exists; try to find another filename to use # If the destination file exists; try to find another filename to use
if os.path.exists(dest_filename): if os.path.exists(dest_filename):
dest_filename = utils.find_next_free(dest_filename, 10); dest_filename = utils.find_next_free(dest_filename, 10)
utils.move(file, dest_filename, 0660); utils.move(file, dest_filename, 0660)
else: else:
utils.warn("skipping '%s', permission denied." % (os.path.basename(file))); utils.warn("skipping '%s', permission denied." % (os.path.basename(file)))
# Removes any old files. # Removes any old files.
# [Used for Incoming/REJECT] # [Used for Incoming/REJECT]
...@@ -100,111 +100,111 @@ def flush_old (): ...@@ -100,111 +100,111 @@ def flush_old ():
if os.path.isfile(file): if os.path.isfile(file):
if os.stat(file)[stat.ST_MTIME] < delete_date: if os.stat(file)[stat.ST_MTIME] < delete_date:
if Options["No-Action"]: if Options["No-Action"]:
print "I: Would delete '%s'." % (os.path.basename(file)); print "I: Would delete '%s'." % (os.path.basename(file))
else: else:
if Options["Verbose"]: if Options["Verbose"]:
print "Removing '%s' (to '%s')." % (os.path.basename(file), del_dir); print "Removing '%s' (to '%s')." % (os.path.basename(file), del_dir)
remove(file); remove(file)
else: else:
if Options["Verbose"]: if Options["Verbose"]:
print "Skipping, too new, '%s'." % (os.path.basename(file)); print "Skipping, too new, '%s'." % (os.path.basename(file))
# Removes any files which are old orphans (not associated with a valid .changes file). # Removes any files which are old orphans (not associated with a valid .changes file).
# [Used for Incoming] # [Used for Incoming]
# #
def flush_orphans (): def flush_orphans ():
all_files = {}; all_files = {}
changes_files = []; changes_files = []
# Build up the list of all files in the directory # Build up the list of all files in the directory
for i in os.listdir('.'): for i in os.listdir('.'):
if os.path.isfile(i): if os.path.isfile(i):
all_files[i] = 1; all_files[i] = 1
if i.endswith(".changes"): if i.endswith(".changes"):
changes_files.append(i); changes_files.append(i)
# Proces all .changes and .dsc files. # Proces all .changes and .dsc files.
for changes_filename in changes_files: for changes_filename in changes_files:
try: try:
changes = utils.parse_changes(changes_filename); changes = utils.parse_changes(changes_filename)
files = utils.build_file_list(changes); files = utils.build_file_list(changes)
except: except:
utils.warn("error processing '%s'; skipping it. [Got %s]" % (changes_filename, sys.exc_type)); utils.warn("error processing '%s'; skipping it. [Got %s]" % (changes_filename, sys.exc_type))
continue; continue
dsc_files = {}; dsc_files = {}
for file in files.keys(): for file in files.keys():
if file.endswith(".dsc"): if file.endswith(".dsc"):
try: try:
dsc = utils.parse_changes(file); dsc = utils.parse_changes(file)
dsc_files = utils.build_file_list(dsc, is_a_dsc=1); dsc_files = utils.build_file_list(dsc, is_a_dsc=1)
except: except:
utils.warn("error processing '%s'; skipping it. [Got %s]" % (file, sys.exc_type)); utils.warn("error processing '%s'; skipping it. [Got %s]" % (file, sys.exc_type))
continue; continue
# Ensure all the files we've seen aren't deleted # Ensure all the files we've seen aren't deleted
keys = []; keys = []
for i in (files.keys(), dsc_files.keys(), [changes_filename]): for i in (files.keys(), dsc_files.keys(), [changes_filename]):
keys.extend(i); keys.extend(i)
for key in keys: for key in keys:
if all_files.has_key(key): if all_files.has_key(key):
if Options["Verbose"]: if Options["Verbose"]:
print "Skipping, has parents, '%s'." % (key); print "Skipping, has parents, '%s'." % (key)
del all_files[key]; del all_files[key]
# Anthing left at this stage is not referenced by a .changes (or # Anthing left at this stage is not referenced by a .changes (or
# a .dsc) and should be deleted if old enough. # a .dsc) and should be deleted if old enough.
for file in all_files.keys(): for file in all_files.keys():
if os.stat(file)[stat.ST_MTIME] < delete_date: if os.stat(file)[stat.ST_MTIME] < delete_date:
if Options["No-Action"]: if Options["No-Action"]:
print "I: Would delete '%s'." % (os.path.basename(file)); print "I: Would delete '%s'." % (os.path.basename(file))
else: else:
if Options["Verbose"]: if Options["Verbose"]:
print "Removing '%s' (to '%s')." % (os.path.basename(file), del_dir); print "Removing '%s' (to '%s')." % (os.path.basename(file), del_dir)
remove(file); remove(file)
else: else:
if Options["Verbose"]: if Options["Verbose"]:
print "Skipping, too new, '%s'." % (os.path.basename(file)); print "Skipping, too new, '%s'." % (os.path.basename(file))
################################################################################ ################################################################################
def main (): def main ():
global Cnf, Options; global Cnf, Options
Cnf = utils.get_conf() Cnf = utils.get_conf()
for i in ["Help", "Incoming", "No-Action", "Verbose" ]: for i in ["Help", "Incoming", "No-Action", "Verbose" ]:
if not Cnf.has_key("Shania::Options::%s" % (i)): if not Cnf.has_key("Shania::Options::%s" % (i)):
Cnf["Shania::Options::%s" % (i)] = ""; Cnf["Shania::Options::%s" % (i)] = ""
if not Cnf.has_key("Shania::Options::Days"): if not Cnf.has_key("Shania::Options::Days"):
Cnf["Shania::Options::Days"] = "14"; Cnf["Shania::Options::Days"] = "14"
Arguments = [('h',"help","Shania::Options::Help"), Arguments = [('h',"help","Shania::Options::Help"),
('d',"days","Shania::Options::Days", "IntLevel"), ('d',"days","Shania::Options::Days", "IntLevel"),
('i',"incoming","Shania::Options::Incoming", "HasArg"), ('i',"incoming","Shania::Options::Incoming", "HasArg"),
('n',"no-action","Shania::Options::No-Action"), ('n',"no-action","Shania::Options::No-Action"),
('v',"verbose","Shania::Options::Verbose")]; ('v',"verbose","Shania::Options::Verbose")]
apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Shania::Options") Options = Cnf.SubTree("Shania::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
init(); init()
if Options["Verbose"]: if Options["Verbose"]:
print "Processing incoming..." print "Processing incoming..."
flush_orphans(); flush_orphans()
reject = Cnf["Dir::Queue::Reject"] reject = Cnf["Dir::Queue::Reject"]
if os.path.exists(reject) and os.path.isdir(reject): if os.path.exists(reject) and os.path.isdir(reject):
if Options["Verbose"]: if Options["Verbose"]:
print "Processing incoming/REJECT..." print "Processing incoming/REJECT..."
os.chdir(reject); os.chdir(reject)
flush_old(); flush_old()
####################################################################################### #######################################################################################
if __name__ == '__main__': if __name__ == '__main__':
main(); main()
...@@ -35,9 +35,9 @@ import utils ...@@ -35,9 +35,9 @@ import utils
################################################################################ ################################################################################
projectB = None; projectB = None
Cnf = None; Cnf = None
Options = None; Options = None
now_date = None; # mark newly "deleted" things as deleted "now" now_date = None; # mark newly "deleted" things as deleted "now"
delete_date = None; # delete things marked "deleted" earler than this delete_date = None; # delete things marked "deleted" earler than this
...@@ -54,7 +54,7 @@ Clean old packages from suites. ...@@ -54,7 +54,7 @@ Clean old packages from suites.
################################################################################ ################################################################################
def check_binaries(): def check_binaries():
global delete_date, now_date; global delete_date, now_date
print "Checking for orphaned binary packages..." print "Checking for orphaned binary packages..."
...@@ -63,33 +63,33 @@ def check_binaries(): ...@@ -63,33 +63,33 @@ def check_binaries():
q = projectB.query(""" q = projectB.query("""
SELECT b.file FROM binaries b, files f SELECT b.file FROM binaries b, files f
WHERE f.last_used IS NULL AND b.file = f.id WHERE f.last_used IS NULL AND b.file = f.id
AND NOT EXISTS (SELECT 1 FROM bin_associations ba WHERE ba.bin = b.id)"""); AND NOT EXISTS (SELECT 1 FROM bin_associations ba WHERE ba.bin = b.id)""")
ql = q.getresult(); ql = q.getresult()
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in ql: for i in ql:
file_id = i[0]; file_id = i[0]
projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s AND last_used IS NULL" % (now_date, file_id)) projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s AND last_used IS NULL" % (now_date, file_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# Check for any binaries which are marked for eventual deletion # Check for any binaries which are marked for eventual deletion
# but are now used again. # but are now used again.
q = projectB.query(""" q = projectB.query("""
SELECT b.file FROM binaries b, files f SELECT b.file FROM binaries b, files f
WHERE f.last_used IS NOT NULL AND f.id = b.file WHERE f.last_used IS NOT NULL AND f.id = b.file
AND EXISTS (SELECT 1 FROM bin_associations ba WHERE ba.bin = b.id)"""); AND EXISTS (SELECT 1 FROM bin_associations ba WHERE ba.bin = b.id)""")
ql = q.getresult(); ql = q.getresult()
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in ql: for i in ql:
file_id = i[0]; file_id = i[0]
projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (file_id)); projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (file_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
######################################## ########################################
def check_sources(): def check_sources():
global delete_date, now_date; global delete_date, now_date
print "Checking for orphaned source packages..." print "Checking for orphaned source packages..."
...@@ -99,29 +99,29 @@ def check_sources(): ...@@ -99,29 +99,29 @@ def check_sources():
SELECT s.id, s.file FROM source s, files f SELECT s.id, s.file FROM source s, files f
WHERE f.last_used IS NULL AND s.file = f.id WHERE f.last_used IS NULL AND s.file = f.id
AND NOT EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id) AND NOT EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id)
AND NOT EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)"""); AND NOT EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)""")
#### XXX: this should ignore cases where the files for the binary b #### XXX: this should ignore cases where the files for the binary b
#### have been marked for deletion (so the delay between bins go #### have been marked for deletion (so the delay between bins go
#### byebye and sources go byebye is 0 instead of StayOfExecution) #### byebye and sources go byebye is 0 instead of StayOfExecution)
ql = q.getresult(); ql = q.getresult()
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in ql: for i in ql:
source_id = i[0]; source_id = i[0]
dsc_file_id = i[1]; dsc_file_id = i[1]
# Mark the .dsc file for deletion # Mark the .dsc file for deletion
projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s AND last_used IS NULL" % (now_date, dsc_file_id)) projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s AND last_used IS NULL" % (now_date, dsc_file_id))
# Mark all other files references by .dsc too if they're not used by anyone else # Mark all other files references by .dsc too if they're not used by anyone else
x = projectB.query("SELECT f.id FROM files f, dsc_files d WHERE d.source = %s AND d.file = f.id" % (source_id)); x = projectB.query("SELECT f.id FROM files f, dsc_files d WHERE d.source = %s AND d.file = f.id" % (source_id))
for j in x.getresult(): for j in x.getresult():
file_id = j[0]; file_id = j[0]
y = projectB.query("SELECT id FROM dsc_files d WHERE d.file = %s" % (file_id)); y = projectB.query("SELECT id FROM dsc_files d WHERE d.file = %s" % (file_id))
if len(y.getresult()) == 1: if len(y.getresult()) == 1:
projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s AND last_used IS NULL" % (now_date, file_id)); projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s AND last_used IS NULL" % (now_date, file_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# Check for any sources which are marked for deletion but which # Check for any sources which are marked for deletion but which
# are now used again. # are now used again.
...@@ -130,44 +130,44 @@ SELECT s.id, s.file FROM source s, files f ...@@ -130,44 +130,44 @@ SELECT s.id, s.file FROM source s, files f
SELECT f.id FROM source s, files f, dsc_files df SELECT f.id FROM source s, files f, dsc_files df
WHERE f.last_used IS NOT NULL AND s.id = df.source AND df.file = f.id WHERE f.last_used IS NOT NULL AND s.id = df.source AND df.file = f.id
AND ((EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id)) AND ((EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id))
OR (EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)))"""); OR (EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)))""")
#### XXX: this should also handle deleted binaries specially (ie, not #### XXX: this should also handle deleted binaries specially (ie, not
#### reinstate sources because of them #### reinstate sources because of them
ql = q.getresult(); ql = q.getresult()
# Could be done in SQL; but left this way for hysterical raisins # Could be done in SQL; but left this way for hysterical raisins
# [and freedom to innovate don'cha know?] # [and freedom to innovate don'cha know?]
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in ql: for i in ql:
file_id = i[0]; file_id = i[0]
projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (file_id)); projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (file_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
######################################## ########################################
def check_files(): def check_files():
global delete_date, now_date; global delete_date, now_date
# FIXME: this is evil; nothing should ever be in this state. if # FIXME: this is evil; nothing should ever be in this state. if
# they are, it's a bug and the files should not be auto-deleted. # they are, it's a bug and the files should not be auto-deleted.
return; return
print "Checking for unused files..." print "Checking for unused files..."
q = projectB.query(""" q = projectB.query("""
SELECT id FROM files f SELECT id FROM files f
WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.file = f.id) WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.file = f.id)
AND NOT EXISTS (SELECT 1 FROM dsc_files df WHERE df.file = f.id)"""); AND NOT EXISTS (SELECT 1 FROM dsc_files df WHERE df.file = f.id)""")
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in q.getresult(): for i in q.getresult():
file_id = i[0]; file_id = i[0]
projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s" % (now_date, file_id)); projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s" % (now_date, file_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
def clean_binaries(): def clean_binaries():
global delete_date, now_date; global delete_date, now_date
# We do this here so that the binaries we remove will have their # We do this here so that the binaries we remove will have their
# source also removed (if possible). # source also removed (if possible).
...@@ -176,72 +176,72 @@ def clean_binaries(): ...@@ -176,72 +176,72 @@ def clean_binaries():
# buys anything keeping this separate # buys anything keeping this separate
print "Cleaning binaries from the DB..." print "Cleaning binaries from the DB..."
if not Options["No-Action"]: if not Options["No-Action"]:
before = time.time(); before = time.time()
sys.stdout.write("[Deleting from binaries table... "); sys.stdout.write("[Deleting from binaries table... ")
sys.stderr.write("DELETE FROM binaries WHERE EXISTS (SELECT 1 FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')\n" % (delete_date)); sys.stderr.write("DELETE FROM binaries WHERE EXISTS (SELECT 1 FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')\n" % (delete_date))
projectB.query("DELETE FROM binaries WHERE EXISTS (SELECT 1 FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')" % (delete_date)); projectB.query("DELETE FROM binaries WHERE EXISTS (SELECT 1 FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')" % (delete_date))
sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before))); sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before)))
######################################## ########################################
def clean(): def clean():
global delete_date, now_date; global delete_date, now_date
count = 0; count = 0
size = 0; size = 0
print "Cleaning out packages..." print "Cleaning out packages..."
date = time.strftime("%Y-%m-%d"); date = time.strftime("%Y-%m-%d")
dest = Cnf["Dir::Morgue"] + '/' + Cnf["Rhona::MorgueSubDir"] + '/' + date; dest = Cnf["Dir::Morgue"] + '/' + Cnf["Rhona::MorgueSubDir"] + '/' + date
if not os.path.exists(dest): if not os.path.exists(dest):
os.mkdir(dest); os.mkdir(dest)
# Delete from source # Delete from source
if not Options["No-Action"]: if not Options["No-Action"]:
before = time.time(); before = time.time()
sys.stdout.write("[Deleting from source table... "); sys.stdout.write("[Deleting from source table... ")
projectB.query("DELETE FROM dsc_files WHERE EXISTS (SELECT 1 FROM source s, files f, dsc_files df WHERE f.last_used <= '%s' AND s.file = f.id AND s.id = df.source AND df.id = dsc_files.id)" % (delete_date)); projectB.query("DELETE FROM dsc_files WHERE EXISTS (SELECT 1 FROM source s, files f, dsc_files df WHERE f.last_used <= '%s' AND s.file = f.id AND s.id = df.source AND df.id = dsc_files.id)" % (delete_date))
projectB.query("DELETE FROM source WHERE EXISTS (SELECT 1 FROM files WHERE source.file = files.id AND files.last_used <= '%s')" % (delete_date)); projectB.query("DELETE FROM source WHERE EXISTS (SELECT 1 FROM files WHERE source.file = files.id AND files.last_used <= '%s')" % (delete_date))
sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before))); sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before)))
# Delete files from the pool # Delete files from the pool
q = projectB.query("SELECT l.path, f.filename FROM location l, files f WHERE f.last_used <= '%s' AND l.id = f.location" % (delete_date)); q = projectB.query("SELECT l.path, f.filename FROM location l, files f WHERE f.last_used <= '%s' AND l.id = f.location" % (delete_date))
for i in q.getresult(): for i in q.getresult():
filename = i[0] + i[1]; filename = i[0] + i[1]
if not os.path.exists(filename): if not os.path.exists(filename):
utils.warn("can not find '%s'." % (filename)); utils.warn("can not find '%s'." % (filename))
continue; continue
if os.path.isfile(filename): if os.path.isfile(filename):
if os.path.islink(filename): if os.path.islink(filename):
count += 1; count += 1
if Options["No-Action"]: if Options["No-Action"]:
print "Removing symlink %s..." % (filename); print "Removing symlink %s..." % (filename)
else: else:
os.unlink(filename); os.unlink(filename)
else: else:
size += os.stat(filename)[stat.ST_SIZE]; size += os.stat(filename)[stat.ST_SIZE]
count += 1; count += 1
dest_filename = dest + '/' + os.path.basename(filename); dest_filename = dest + '/' + os.path.basename(filename)
# If the destination file exists; try to find another filename to use # If the destination file exists; try to find another filename to use
if os.path.exists(dest_filename): if os.path.exists(dest_filename):
dest_filename = utils.find_next_free(dest_filename); dest_filename = utils.find_next_free(dest_filename)
if Options["No-Action"]: if Options["No-Action"]:
print "Cleaning %s -> %s ..." % (filename, dest_filename); print "Cleaning %s -> %s ..." % (filename, dest_filename)
else: else:
utils.move(filename, dest_filename); utils.move(filename, dest_filename)
else: else:
utils.fubar("%s is neither symlink nor file?!" % (filename)); utils.fubar("%s is neither symlink nor file?!" % (filename))
# Delete from the 'files' table # Delete from the 'files' table
if not Options["No-Action"]: if not Options["No-Action"]:
before = time.time(); before = time.time()
sys.stdout.write("[Deleting from files table... "); sys.stdout.write("[Deleting from files table... ")
projectB.query("DELETE FROM files WHERE last_used <= '%s'" % (delete_date)); projectB.query("DELETE FROM files WHERE last_used <= '%s'" % (delete_date))
sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before))); sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before)))
if count > 0: if count > 0:
sys.stderr.write("Cleaned %d files, %s.\n" % (count, utils.size_type(size))); sys.stderr.write("Cleaned %d files, %s.\n" % (count, utils.size_type(size)))
################################################################################ ################################################################################
...@@ -251,20 +251,20 @@ def clean_maintainers(): ...@@ -251,20 +251,20 @@ def clean_maintainers():
q = projectB.query(""" q = projectB.query("""
SELECT m.id FROM maintainer m SELECT m.id FROM maintainer m
WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.maintainer = m.id) WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.maintainer = m.id)
AND NOT EXISTS (SELECT 1 FROM source s WHERE s.maintainer = m.id)"""); AND NOT EXISTS (SELECT 1 FROM source s WHERE s.maintainer = m.id)""")
ql = q.getresult(); ql = q.getresult()
count = 0; count = 0
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in ql: for i in ql:
maintainer_id = i[0]; maintainer_id = i[0]
if not Options["No-Action"]: if not Options["No-Action"]:
projectB.query("DELETE FROM maintainer WHERE id = %s" % (maintainer_id)); projectB.query("DELETE FROM maintainer WHERE id = %s" % (maintainer_id))
count += 1; count += 1
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
if count > 0: if count > 0:
sys.stderr.write("Cleared out %d maintainer entries.\n" % (count)); sys.stderr.write("Cleared out %d maintainer entries.\n" % (count))
################################################################################ ################################################################################
...@@ -274,81 +274,81 @@ def clean_fingerprints(): ...@@ -274,81 +274,81 @@ def clean_fingerprints():
q = projectB.query(""" q = projectB.query("""
SELECT f.id FROM fingerprint f SELECT f.id FROM fingerprint f
WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.sig_fpr = f.id) WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.sig_fpr = f.id)
AND NOT EXISTS (SELECT 1 FROM source s WHERE s.sig_fpr = f.id)"""); AND NOT EXISTS (SELECT 1 FROM source s WHERE s.sig_fpr = f.id)""")
ql = q.getresult(); ql = q.getresult()
count = 0; count = 0
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for i in ql: for i in ql:
fingerprint_id = i[0]; fingerprint_id = i[0]
if not Options["No-Action"]: if not Options["No-Action"]:
projectB.query("DELETE FROM fingerprint WHERE id = %s" % (fingerprint_id)); projectB.query("DELETE FROM fingerprint WHERE id = %s" % (fingerprint_id))
count += 1; count += 1
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
if count > 0: if count > 0:
sys.stderr.write("Cleared out %d fingerprint entries.\n" % (count)); sys.stderr.write("Cleared out %d fingerprint entries.\n" % (count))
################################################################################ ################################################################################
def clean_queue_build(): def clean_queue_build():
global now_date; global now_date
if not Cnf.ValueList("Dinstall::QueueBuildSuites") or Options["No-Action"]: if not Cnf.ValueList("Dinstall::QueueBuildSuites") or Options["No-Action"]:
return; return
print "Cleaning out queue build symlinks..." print "Cleaning out queue build symlinks..."
our_delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::QueueBuildStayOfExecution"]))); our_delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::QueueBuildStayOfExecution"])))
count = 0; count = 0
q = projectB.query("SELECT filename FROM queue_build WHERE last_used <= '%s'" % (our_delete_date)); q = projectB.query("SELECT filename FROM queue_build WHERE last_used <= '%s'" % (our_delete_date))
for i in q.getresult(): for i in q.getresult():
filename = i[0]; filename = i[0]
if not os.path.exists(filename): if not os.path.exists(filename):
utils.warn("%s (from queue_build) doesn't exist." % (filename)); utils.warn("%s (from queue_build) doesn't exist." % (filename))
continue; continue
if not Cnf.FindB("Dinstall::SecurityQueueBuild") and not os.path.islink(filename): if not Cnf.FindB("Dinstall::SecurityQueueBuild") and not os.path.islink(filename):
utils.fubar("%s (from queue_build) should be a symlink but isn't." % (filename)); utils.fubar("%s (from queue_build) should be a symlink but isn't." % (filename))
os.unlink(filename); os.unlink(filename)
count += 1; count += 1
projectB.query("DELETE FROM queue_build WHERE last_used <= '%s'" % (our_delete_date)); projectB.query("DELETE FROM queue_build WHERE last_used <= '%s'" % (our_delete_date))
if count: if count:
sys.stderr.write("Cleaned %d queue_build files.\n" % (count)); sys.stderr.write("Cleaned %d queue_build files.\n" % (count))
################################################################################ ################################################################################
def main(): def main():
global Cnf, Options, projectB, delete_date, now_date; global Cnf, Options, projectB, delete_date, now_date
Cnf = utils.get_conf() Cnf = utils.get_conf()
for i in ["Help", "No-Action" ]: for i in ["Help", "No-Action" ]:
if not Cnf.has_key("Rhona::Options::%s" % (i)): if not Cnf.has_key("Rhona::Options::%s" % (i)):
Cnf["Rhona::Options::%s" % (i)] = ""; Cnf["Rhona::Options::%s" % (i)] = ""
Arguments = [('h',"help","Rhona::Options::Help"), Arguments = [('h',"help","Rhona::Options::Help"),
('n',"no-action","Rhona::Options::No-Action")]; ('n',"no-action","Rhona::Options::No-Action")]
apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Rhona::Options") Options = Cnf.SubTree("Rhona::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
now_date = time.strftime("%Y-%m-%d %H:%M"); now_date = time.strftime("%Y-%m-%d %H:%M")
delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::StayOfExecution"]))); delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::StayOfExecution"])))
check_binaries(); check_binaries()
clean_binaries(); clean_binaries()
check_sources(); check_sources()
check_files(); check_files()
clean(); clean()
clean_maintainers(); clean_maintainers()
clean_fingerprints(); clean_fingerprints()
clean_queue_build(); clean_queue_build()
################################################################################ ################################################################################
......
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
################################################################################ ################################################################################
import pg, sys; import pg, sys
import utils, db_access; import utils, db_access
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
################################################################################ ################################################################################
...@@ -42,42 +42,42 @@ Looks for fixable descrepancies between stable and unstable. ...@@ -42,42 +42,42 @@ Looks for fixable descrepancies between stable and unstable.
################################################################################ ################################################################################
def main (): def main ():
global Cnf, projectB; global Cnf, projectB
Cnf = utils.get_conf(); Cnf = utils.get_conf()
Arguments = [('h',"help","Andrea::Options::Help")]; Arguments = [('h',"help","Andrea::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Andrea::Options::%s" % (i)): if not Cnf.has_key("Andrea::Options::%s" % (i)):
Cnf["Andrea::Options::%s" % (i)] = ""; Cnf["Andrea::Options::%s" % (i)] = ""
apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv); apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
Options = Cnf.SubTree("Andrea::Options") Options = Cnf.SubTree("Andrea::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
src_suite = "stable"; src_suite = "stable"
dst_suite = "unstable"; dst_suite = "unstable"
src_suite_id = db_access.get_suite_id(src_suite); src_suite_id = db_access.get_suite_id(src_suite)
dst_suite_id = db_access.get_suite_id(dst_suite); dst_suite_id = db_access.get_suite_id(dst_suite)
arch_all_id = db_access.get_architecture_id("all"); arch_all_id = db_access.get_architecture_id("all")
dsc_type_id = db_access.get_override_type_id("dsc"); dsc_type_id = db_access.get_override_type_id("dsc")
for arch in Cnf.ValueList("Suite::%s::Architectures" % (src_suite)): for arch in Cnf.ValueList("Suite::%s::Architectures" % (src_suite)):
if arch == "source": if arch == "source":
continue; continue
# Arch: all doesn't work; consider packages which go from # Arch: all doesn't work; consider packages which go from
# arch: all to arch: any, e.g. debconf... needs more checks # arch: all to arch: any, e.g. debconf... needs more checks
# and thought later. # and thought later.
if arch == "all": if arch == "all":
continue; continue
arch_id = db_access.get_architecture_id(arch); arch_id = db_access.get_architecture_id(arch)
q = projectB.query(""" q = projectB.query("""
SELECT b_src.package, b_src.version, a.arch_string SELECT b_src.package, b_src.version, a.arch_string
FROM binaries b_src, bin_associations ba, override o, architecture a FROM binaries b_src, bin_associations ba, override o, architecture a
...@@ -91,9 +91,9 @@ SELECT b_src.package, b_src.version, a.arch_string ...@@ -91,9 +91,9 @@ SELECT b_src.package, b_src.version, a.arch_string
(SELECT 1 FROM bin_associations ba3, binaries b2 (SELECT 1 FROM bin_associations ba3, binaries b2
WHERE ba3.bin = b2.id AND ba3.suite = %s AND b2.package = b_dst.package)) WHERE ba3.bin = b2.id AND ba3.suite = %s AND b2.package = b_dst.package))
ORDER BY b_src.package;""" ORDER BY b_src.package;"""
% (src_suite_id, arch_id, dst_suite_id, dsc_type_id, arch_id, arch_all_id, dst_suite_id, dst_suite_id)); % (src_suite_id, arch_id, dst_suite_id, dsc_type_id, arch_id, arch_all_id, dst_suite_id, dst_suite_id))
for i in q.getresult(): for i in q.getresult():
print " ".join(i); print " ".join(i)
####################################################################################### #######################################################################################
......
...@@ -50,15 +50,15 @@ ...@@ -50,15 +50,15 @@
################################################################################ ################################################################################
import pg, sys, time; import pg, sys, time
import utils, db_access, logging; import utils, db_access, logging
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
Logger = None; Logger = None
################################################################################ ################################################################################
...@@ -85,162 +85,162 @@ def usage (exit_code=0): ...@@ -85,162 +85,162 @@ def usage (exit_code=0):
################################################################################ ################################################################################
def process_file (file, suite, component, type, action): def process_file (file, suite, component, type, action):
suite_id = db_access.get_suite_id(suite); suite_id = db_access.get_suite_id(suite)
if suite_id == -1: if suite_id == -1:
utils.fubar("Suite '%s' not recognised." % (suite)); utils.fubar("Suite '%s' not recognised." % (suite))
component_id = db_access.get_component_id(component); component_id = db_access.get_component_id(component)
if component_id == -1: if component_id == -1:
utils.fubar("Component '%s' not recognised." % (component)); utils.fubar("Component '%s' not recognised." % (component))
type_id = db_access.get_override_type_id(type); type_id = db_access.get_override_type_id(type)
if type_id == -1: if type_id == -1:
utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc.)" % (type)); utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc.)" % (type))
# --set is done mostly internal for performance reasons; most # --set is done mostly internal for performance reasons; most
# invocations of --set will be updates and making people wait 2-3 # invocations of --set will be updates and making people wait 2-3
# minutes while 6000 select+inserts are run needlessly isn't cool. # minutes while 6000 select+inserts are run needlessly isn't cool.
original = {}; original = {}
new = {}; new = {}
c_skipped = 0; c_skipped = 0
c_added = 0; c_added = 0
c_updated = 0; c_updated = 0
c_removed = 0; c_removed = 0
c_error = 0; c_error = 0
q = projectB.query("SELECT o.package, o.priority, o.section, o.maintainer, p.priority, s.section FROM override o, priority p, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s and o.priority = p.id and o.section = s.id" q = projectB.query("SELECT o.package, o.priority, o.section, o.maintainer, p.priority, s.section FROM override o, priority p, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s and o.priority = p.id and o.section = s.id"
% (suite_id, component_id, type_id)); % (suite_id, component_id, type_id))
for i in q.getresult(): for i in q.getresult():
original[i[0]] = i[1:]; original[i[0]] = i[1:]
start_time = time.time(); start_time = time.time()
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for line in file.readlines(): for line in file.readlines():
line = utils.re_comments.sub('', line).strip(); line = utils.re_comments.sub('', line).strip()
if line == "": if line == "":
continue; continue
maintainer_override = None; maintainer_override = None
if type == "dsc": if type == "dsc":
split_line = line.split(None, 2); split_line = line.split(None, 2)
if len(split_line) == 2: if len(split_line) == 2:
(package, section) = split_line; (package, section) = split_line
elif len(split_line) == 3: elif len(split_line) == 3:
(package, section, maintainer_override) = split_line; (package, section, maintainer_override) = split_line
else: else:
utils.warn("'%s' does not break into 'package section [maintainer-override]'." % (line)); utils.warn("'%s' does not break into 'package section [maintainer-override]'." % (line))
c_error += 1; c_error += 1
continue; continue
priority = "source"; priority = "source"
else: # binary or udeb else: # binary or udeb
split_line = line.split(None, 3); split_line = line.split(None, 3)
if len(split_line) == 3: if len(split_line) == 3:
(package, priority, section) = split_line; (package, priority, section) = split_line
elif len(split_line) == 4: elif len(split_line) == 4:
(package, priority, section, maintainer_override) = split_line; (package, priority, section, maintainer_override) = split_line
else: else:
utils.warn("'%s' does not break into 'package priority section [maintainer-override]'." % (line)); utils.warn("'%s' does not break into 'package priority section [maintainer-override]'." % (line))
c_error += 1; c_error += 1
continue; continue
section_id = db_access.get_section_id(section); section_id = db_access.get_section_id(section)
if section_id == -1: if section_id == -1:
utils.warn("'%s' is not a valid section. ['%s' in suite %s, component %s]." % (section, package, suite, component)); utils.warn("'%s' is not a valid section. ['%s' in suite %s, component %s]." % (section, package, suite, component))
c_error += 1; c_error += 1
continue; continue
priority_id = db_access.get_priority_id(priority); priority_id = db_access.get_priority_id(priority)
if priority_id == -1: if priority_id == -1:
utils.warn("'%s' is not a valid priority. ['%s' in suite %s, component %s]." % (priority, package, suite, component)); utils.warn("'%s' is not a valid priority. ['%s' in suite %s, component %s]." % (priority, package, suite, component))
c_error += 1; c_error += 1
continue; continue
if new.has_key(package): if new.has_key(package):
utils.warn("Can't insert duplicate entry for '%s'; ignoring all but the first. [suite %s, component %s]" % (package, suite, component)); utils.warn("Can't insert duplicate entry for '%s'; ignoring all but the first. [suite %s, component %s]" % (package, suite, component))
c_error += 1; c_error += 1
continue; continue
new[package] = ""; new[package] = ""
if original.has_key(package): if original.has_key(package):
(old_priority_id, old_section_id, old_maintainer_override, old_priority, old_section) = original[package]; (old_priority_id, old_section_id, old_maintainer_override, old_priority, old_section) = original[package]
if action == "add" or old_priority_id == priority_id and \ if action == "add" or old_priority_id == priority_id and \
old_section_id == section_id and \ old_section_id == section_id and \
((old_maintainer_override == maintainer_override) or \ ((old_maintainer_override == maintainer_override) or \
(old_maintainer_override == "" and maintainer_override == None)): (old_maintainer_override == "" and maintainer_override == None)):
# If it's unchanged or we're in 'add only' mode, ignore it # If it's unchanged or we're in 'add only' mode, ignore it
c_skipped += 1; c_skipped += 1
continue; continue
else: else:
# If it's changed, delete the old one so we can # If it's changed, delete the old one so we can
# reinsert it with the new information # reinsert it with the new information
c_updated += 1; c_updated += 1
projectB.query("DELETE FROM override WHERE suite = %s AND component = %s AND package = '%s' AND type = %s" projectB.query("DELETE FROM override WHERE suite = %s AND component = %s AND package = '%s' AND type = %s"
% (suite_id, component_id, package, type_id)); % (suite_id, component_id, package, type_id))
# Log changes # Log changes
if old_priority_id != priority_id: if old_priority_id != priority_id:
Logger.log(["changed priority",package,old_priority,priority]); Logger.log(["changed priority",package,old_priority,priority])
if old_section_id != section_id: if old_section_id != section_id:
Logger.log(["changed section",package,old_section,section]); Logger.log(["changed section",package,old_section,section])
if old_maintainer_override != maintainer_override: if old_maintainer_override != maintainer_override:
Logger.log(["changed maintainer override",package,old_maintainer_override,maintainer_override]); Logger.log(["changed maintainer override",package,old_maintainer_override,maintainer_override])
update_p = 1; update_p = 1
else: else:
c_added += 1; c_added += 1
update_p = 0; update_p = 0
if maintainer_override: if maintainer_override:
projectB.query("INSERT INTO override (suite, component, type, package, priority, section, maintainer) VALUES (%s, %s, %s, '%s', %s, %s, '%s')" projectB.query("INSERT INTO override (suite, component, type, package, priority, section, maintainer) VALUES (%s, %s, %s, '%s', %s, %s, '%s')"
% (suite_id, component_id, type_id, package, priority_id, section_id, maintainer_override)); % (suite_id, component_id, type_id, package, priority_id, section_id, maintainer_override))
else: else:
projectB.query("INSERT INTO override (suite, component, type, package, priority, section,maintainer) VALUES (%s, %s, %s, '%s', %s, %s, '')" projectB.query("INSERT INTO override (suite, component, type, package, priority, section,maintainer) VALUES (%s, %s, %s, '%s', %s, %s, '')"
% (suite_id, component_id, type_id, package, priority_id, section_id)); % (suite_id, component_id, type_id, package, priority_id, section_id))
if not update_p: if not update_p:
Logger.log(["new override",suite,component,type,package,priority,section,maintainer_override]); Logger.log(["new override",suite,component,type,package,priority,section,maintainer_override])
if not action == "add": if not action == "add":
# Delete any packages which were removed # Delete any packages which were removed
for package in original.keys(): for package in original.keys():
if not new.has_key(package): if not new.has_key(package):
projectB.query("DELETE FROM override WHERE suite = %s AND component = %s AND package = '%s' AND type = %s" projectB.query("DELETE FROM override WHERE suite = %s AND component = %s AND package = '%s' AND type = %s"
% (suite_id, component_id, package, type_id)); % (suite_id, component_id, package, type_id))
c_removed += 1; c_removed += 1
Logger.log(["removed override",suite,component,type,package]); Logger.log(["removed override",suite,component,type,package])
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
if not Cnf["Natalie::Options::Quiet"]: if not Cnf["Natalie::Options::Quiet"]:
print "Done in %d seconds. [Updated = %d, Added = %d, Removed = %d, Skipped = %d, Errors = %d]" % (int(time.time()-start_time), c_updated, c_added, c_removed, c_skipped, c_error); print "Done in %d seconds. [Updated = %d, Added = %d, Removed = %d, Skipped = %d, Errors = %d]" % (int(time.time()-start_time), c_updated, c_added, c_removed, c_skipped, c_error)
Logger.log(["set complete",c_updated, c_added, c_removed, c_skipped, c_error]); Logger.log(["set complete",c_updated, c_added, c_removed, c_skipped, c_error])
################################################################################ ################################################################################
def list(suite, component, type): def list(suite, component, type):
suite_id = db_access.get_suite_id(suite); suite_id = db_access.get_suite_id(suite)
if suite_id == -1: if suite_id == -1:
utils.fubar("Suite '%s' not recognised." % (suite)); utils.fubar("Suite '%s' not recognised." % (suite))
component_id = db_access.get_component_id(component); component_id = db_access.get_component_id(component)
if component_id == -1: if component_id == -1:
utils.fubar("Component '%s' not recognised." % (component)); utils.fubar("Component '%s' not recognised." % (component))
type_id = db_access.get_override_type_id(type); type_id = db_access.get_override_type_id(type)
if type_id == -1: if type_id == -1:
utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type)); utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type))
if type == "dsc": if type == "dsc":
q = projectB.query("SELECT o.package, s.section, o.maintainer FROM override o, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s AND o.section = s.id ORDER BY s.section, o.package" % (suite_id, component_id, type_id)); q = projectB.query("SELECT o.package, s.section, o.maintainer FROM override o, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s AND o.section = s.id ORDER BY s.section, o.package" % (suite_id, component_id, type_id))
for i in q.getresult(): for i in q.getresult():
print utils.result_join(i); print utils.result_join(i)
else: else:
q = projectB.query("SELECT o.package, p.priority, s.section, o.maintainer, p.level FROM override o, priority p, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s AND o.priority = p.id AND o.section = s.id ORDER BY s.section, p.level, o.package" % (suite_id, component_id, type_id)); q = projectB.query("SELECT o.package, p.priority, s.section, o.maintainer, p.level FROM override o, priority p, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s AND o.priority = p.id AND o.section = s.id ORDER BY s.section, p.level, o.package" % (suite_id, component_id, type_id))
for i in q.getresult(): for i in q.getresult():
print utils.result_join(i[:-1]); print utils.result_join(i[:-1])
################################################################################ ################################################################################
def main (): def main ():
global Cnf, projectB, Logger; global Cnf, projectB, Logger
Cnf = utils.get_conf(); Cnf = utils.get_conf()
Arguments = [('a', "add", "Natalie::Options::Add"), Arguments = [('a', "add", "Natalie::Options::Add"),
('c', "component", "Natalie::Options::Component", "HasArg"), ('c', "component", "Natalie::Options::Component", "HasArg"),
('h', "help", "Natalie::Options::Help"), ('h', "help", "Natalie::Options::Help"),
...@@ -248,46 +248,46 @@ def main (): ...@@ -248,46 +248,46 @@ def main ():
('q', "quiet", "Natalie::Options::Quiet"), ('q', "quiet", "Natalie::Options::Quiet"),
('s', "suite", "Natalie::Options::Suite", "HasArg"), ('s', "suite", "Natalie::Options::Suite", "HasArg"),
('S', "set", "Natalie::Options::Set"), ('S', "set", "Natalie::Options::Set"),
('t', "type", "Natalie::Options::Type", "HasArg")]; ('t', "type", "Natalie::Options::Type", "HasArg")]
# Default arguments # Default arguments
for i in [ "add", "help", "list", "quiet", "set" ]: for i in [ "add", "help", "list", "quiet", "set" ]:
if not Cnf.has_key("Natalie::Options::%s" % (i)): if not Cnf.has_key("Natalie::Options::%s" % (i)):
Cnf["Natalie::Options::%s" % (i)] = ""; Cnf["Natalie::Options::%s" % (i)] = ""
if not Cnf.has_key("Natalie::Options::Component"): if not Cnf.has_key("Natalie::Options::Component"):
Cnf["Natalie::Options::Component"] = "main"; Cnf["Natalie::Options::Component"] = "main"
if not Cnf.has_key("Natalie::Options::Suite"): if not Cnf.has_key("Natalie::Options::Suite"):
Cnf["Natalie::Options::Suite"] = "unstable"; Cnf["Natalie::Options::Suite"] = "unstable"
if not Cnf.has_key("Natalie::Options::Type"): if not Cnf.has_key("Natalie::Options::Type"):
Cnf["Natalie::Options::Type"] = "deb"; Cnf["Natalie::Options::Type"] = "deb"
file_list = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); file_list = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
if Cnf["Natalie::Options::Help"]: if Cnf["Natalie::Options::Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
action = None; action = None
for i in [ "add", "list", "set" ]: for i in [ "add", "list", "set" ]:
if Cnf["Natalie::Options::%s" % (i)]: if Cnf["Natalie::Options::%s" % (i)]:
if action: if action:
utils.fubar("Can not perform more than one action at once."); utils.fubar("Can not perform more than one action at once.")
action = i; action = i
(suite, component, type) = (Cnf["Natalie::Options::Suite"], Cnf["Natalie::Options::Component"], Cnf["Natalie::Options::Type"]) (suite, component, type) = (Cnf["Natalie::Options::Suite"], Cnf["Natalie::Options::Component"], Cnf["Natalie::Options::Type"])
if action == "list": if action == "list":
list(suite, component, type); list(suite, component, type)
else: else:
Logger = logging.Logger(Cnf, "natalie"); Logger = logging.Logger(Cnf, "natalie")
if file_list: if file_list:
for file in file_list: for file in file_list:
process_file(utils.open_file(file), suite, component, type, action); process_file(utils.open_file(file), suite, component, type, action)
else: else:
process_file(sys.stdin, suite, component, type, action); process_file(sys.stdin, suite, component, type, action)
Logger.close(); Logger.close()
####################################################################################### #######################################################################################
......
...@@ -42,15 +42,15 @@ ...@@ -42,15 +42,15 @@
####################################################################################### #######################################################################################
import pg, sys; import pg, sys
import apt_pkg; import apt_pkg
import utils, db_access, logging; import utils, db_access, logging
####################################################################################### #######################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
Logger = None; Logger = None
################################################################################ ################################################################################
...@@ -74,163 +74,163 @@ def get_id (package, version, architecture): ...@@ -74,163 +74,163 @@ def get_id (package, version, architecture):
else: else:
q = projectB.query("SELECT b.id FROM binaries b, architecture a WHERE b.package = '%s' AND b.version = '%s' AND (a.arch_string = '%s' OR a.arch_string = 'all') AND b.architecture = a.id" % (package, version, architecture)) q = projectB.query("SELECT b.id FROM binaries b, architecture a WHERE b.package = '%s' AND b.version = '%s' AND (a.arch_string = '%s' OR a.arch_string = 'all') AND b.architecture = a.id" % (package, version, architecture))
ql = q.getresult(); ql = q.getresult()
if not ql: if not ql:
utils.warn("Couldn't find '%s~%s~%s'." % (package, version, architecture)); utils.warn("Couldn't find '%s~%s~%s'." % (package, version, architecture))
return None; return None
if len(ql) > 1: if len(ql) > 1:
utils.warn("Found more than one match for '%s~%s~%s'." % (package, version, architecture)); utils.warn("Found more than one match for '%s~%s~%s'." % (package, version, architecture))
return None; return None
id = ql[0][0]; id = ql[0][0]
return id; return id
####################################################################################### #######################################################################################
def set_suite (file, suite_id): def set_suite (file, suite_id):
lines = file.readlines(); lines = file.readlines()
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
# Build up a dictionary of what is currently in the suite # Build up a dictionary of what is currently in the suite
current = {}; current = {}
q = projectB.query("SELECT b.package, b.version, a.arch_string, ba.id FROM binaries b, bin_associations ba, architecture a WHERE ba.suite = %s AND ba.bin = b.id AND b.architecture = a.id" % (suite_id)); q = projectB.query("SELECT b.package, b.version, a.arch_string, ba.id FROM binaries b, bin_associations ba, architecture a WHERE ba.suite = %s AND ba.bin = b.id AND b.architecture = a.id" % (suite_id))
ql = q.getresult(); ql = q.getresult()
for i in ql: for i in ql:
key = " ".join(i[:3]); key = " ".join(i[:3])
current[key] = i[3]; current[key] = i[3]
q = projectB.query("SELECT s.source, s.version, sa.id FROM source s, src_associations sa WHERE sa.suite = %s AND sa.source = s.id" % (suite_id)); q = projectB.query("SELECT s.source, s.version, sa.id FROM source s, src_associations sa WHERE sa.suite = %s AND sa.source = s.id" % (suite_id))
ql = q.getresult(); ql = q.getresult()
for i in ql: for i in ql:
key = " ".join(i[:2]) + " source"; key = " ".join(i[:2]) + " source"
current[key] = i[2]; current[key] = i[2]
# Build up a dictionary of what should be in the suite # Build up a dictionary of what should be in the suite
desired = {}; desired = {}
for line in lines: for line in lines:
split_line = line.strip().split(); split_line = line.strip().split()
if len(split_line) != 3: if len(split_line) != 3:
utils.warn("'%s' does not break into 'package version architecture'." % (line[:-1])); utils.warn("'%s' does not break into 'package version architecture'." % (line[:-1]))
continue; continue
key = " ".join(split_line); key = " ".join(split_line)
desired[key] = ""; desired[key] = ""
# Check to see which packages need removed and remove them # Check to see which packages need removed and remove them
for key in current.keys(): for key in current.keys():
if not desired.has_key(key): if not desired.has_key(key):
(package, version, architecture) = key.split(); (package, version, architecture) = key.split()
id = current[key]; id = current[key]
if architecture == "source": if architecture == "source":
q = projectB.query("DELETE FROM src_associations WHERE id = %s" % (id)); q = projectB.query("DELETE FROM src_associations WHERE id = %s" % (id))
else: else:
q = projectB.query("DELETE FROM bin_associations WHERE id = %s" % (id)); q = projectB.query("DELETE FROM bin_associations WHERE id = %s" % (id))
Logger.log(["removed",key,id]); Logger.log(["removed",key,id])
# Check to see which packages need added and add them # Check to see which packages need added and add them
for key in desired.keys(): for key in desired.keys():
if not current.has_key(key): if not current.has_key(key):
(package, version, architecture) = key.split(); (package, version, architecture) = key.split()
id = get_id (package, version, architecture); id = get_id (package, version, architecture)
if not id: if not id:
continue; continue
if architecture == "source": if architecture == "source":
q = projectB.query("INSERT INTO src_associations (suite, source) VALUES (%s, %s)" % (suite_id, id)); q = projectB.query("INSERT INTO src_associations (suite, source) VALUES (%s, %s)" % (suite_id, id))
else: else:
q = projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%s, %s)" % (suite_id, id)); q = projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%s, %s)" % (suite_id, id))
Logger.log(["added",key,id]); Logger.log(["added",key,id])
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
####################################################################################### #######################################################################################
def process_file (file, suite, action): def process_file (file, suite, action):
suite_id = db_access.get_suite_id(suite); suite_id = db_access.get_suite_id(suite)
if action == "set": if action == "set":
set_suite (file, suite_id); set_suite (file, suite_id)
return; return
lines = file.readlines(); lines = file.readlines()
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
for line in lines: for line in lines:
split_line = line.strip().split(); split_line = line.strip().split()
if len(split_line) != 3: if len(split_line) != 3:
utils.warn("'%s' does not break into 'package version architecture'." % (line[:-1])); utils.warn("'%s' does not break into 'package version architecture'." % (line[:-1]))
continue; continue
(package, version, architecture) = split_line; (package, version, architecture) = split_line
id = get_id(package, version, architecture); id = get_id(package, version, architecture)
if not id: if not id:
continue; continue
if architecture == "source": if architecture == "source":
# Find the existing assoications ID, if any # Find the existing assoications ID, if any
q = projectB.query("SELECT id FROM src_associations WHERE suite = %s and source = %s" % (suite_id, id)); q = projectB.query("SELECT id FROM src_associations WHERE suite = %s and source = %s" % (suite_id, id))
ql = q.getresult(); ql = q.getresult()
if not ql: if not ql:
assoication_id = None; assoication_id = None
else: else:
assoication_id = ql[0][0]; assoication_id = ql[0][0]
# Take action # Take action
if action == "add": if action == "add":
if assoication_id: if assoication_id:
utils.warn("'%s~%s~%s' already exists in suite %s." % (package, version, architecture, suite)); utils.warn("'%s~%s~%s' already exists in suite %s." % (package, version, architecture, suite))
continue; continue
else: else:
q = projectB.query("INSERT INTO src_associations (suite, source) VALUES (%s, %s)" % (suite_id, id)); q = projectB.query("INSERT INTO src_associations (suite, source) VALUES (%s, %s)" % (suite_id, id))
elif action == "remove": elif action == "remove":
if assoication_id == None: if assoication_id == None:
utils.warn("'%s~%s~%s' doesn't exist in suite %s." % (package, version, architecture, suite)); utils.warn("'%s~%s~%s' doesn't exist in suite %s." % (package, version, architecture, suite))
continue; continue
else: else:
q = projectB.query("DELETE FROM src_associations WHERE id = %s" % (assoication_id)); q = projectB.query("DELETE FROM src_associations WHERE id = %s" % (assoication_id))
else: else:
# Find the existing assoications ID, if any # Find the existing assoications ID, if any
q = projectB.query("SELECT id FROM bin_associations WHERE suite = %s and bin = %s" % (suite_id, id)); q = projectB.query("SELECT id FROM bin_associations WHERE suite = %s and bin = %s" % (suite_id, id))
ql = q.getresult(); ql = q.getresult()
if not ql: if not ql:
assoication_id = None; assoication_id = None
else: else:
assoication_id = ql[0][0]; assoication_id = ql[0][0]
# Take action # Take action
if action == "add": if action == "add":
if assoication_id: if assoication_id:
utils.warn("'%s~%s~%s' already exists in suite %s." % (package, version, architecture, suite)); utils.warn("'%s~%s~%s' already exists in suite %s." % (package, version, architecture, suite))
continue; continue
else: else:
q = projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%s, %s)" % (suite_id, id)); q = projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%s, %s)" % (suite_id, id))
elif action == "remove": elif action == "remove":
if assoication_id == None: if assoication_id == None:
utils.warn("'%s~%s~%s' doesn't exist in suite %s." % (package, version, architecture, suite)); utils.warn("'%s~%s~%s' doesn't exist in suite %s." % (package, version, architecture, suite))
continue; continue
else: else:
q = projectB.query("DELETE FROM bin_associations WHERE id = %s" % (assoication_id)); q = projectB.query("DELETE FROM bin_associations WHERE id = %s" % (assoication_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
####################################################################################### #######################################################################################
def get_list (suite): def get_list (suite):
suite_id = db_access.get_suite_id(suite); suite_id = db_access.get_suite_id(suite)
# List binaries # List binaries
q = projectB.query("SELECT b.package, b.version, a.arch_string FROM binaries b, bin_associations ba, architecture a WHERE ba.suite = %s AND ba.bin = b.id AND b.architecture = a.id" % (suite_id)); q = projectB.query("SELECT b.package, b.version, a.arch_string FROM binaries b, bin_associations ba, architecture a WHERE ba.suite = %s AND ba.bin = b.id AND b.architecture = a.id" % (suite_id))
ql = q.getresult(); ql = q.getresult()
for i in ql: for i in ql:
print " ".join(i); print " ".join(i)
# List source # List source
q = projectB.query("SELECT s.source, s.version FROM source s, src_associations sa WHERE sa.suite = %s AND sa.source = s.id" % (suite_id)); q = projectB.query("SELECT s.source, s.version FROM source s, src_associations sa WHERE sa.suite = %s AND sa.source = s.id" % (suite_id))
ql = q.getresult(); ql = q.getresult()
for i in ql: for i in ql:
print " ".join(i) + " source"; print " ".join(i) + " source"
####################################################################################### #######################################################################################
def main (): def main ():
global Cnf, projectB, Logger; global Cnf, projectB, Logger
Cnf = utils.get_conf() Cnf = utils.get_conf()
...@@ -238,52 +238,52 @@ def main (): ...@@ -238,52 +238,52 @@ def main ():
('h',"help","Heidi::Options::Help"), ('h',"help","Heidi::Options::Help"),
('l',"list","Heidi::Options::List","HasArg"), ('l',"list","Heidi::Options::List","HasArg"),
('r',"remove", "Heidi::Options::Remove", "HasArg"), ('r',"remove", "Heidi::Options::Remove", "HasArg"),
('s',"set", "Heidi::Options::Set", "HasArg")]; ('s',"set", "Heidi::Options::Set", "HasArg")]
for i in ["add", "help", "list", "remove", "set", "version" ]: for i in ["add", "help", "list", "remove", "set", "version" ]:
if not Cnf.has_key("Heidi::Options::%s" % (i)): if not Cnf.has_key("Heidi::Options::%s" % (i)):
Cnf["Heidi::Options::%s" % (i)] = ""; Cnf["Heidi::Options::%s" % (i)] = ""
file_list = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); file_list = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Heidi::Options") Options = Cnf.SubTree("Heidi::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"],int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"],int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
action = None; action = None
for i in ("add", "list", "remove", "set"): for i in ("add", "list", "remove", "set"):
if Cnf["Heidi::Options::%s" % (i)] != "": if Cnf["Heidi::Options::%s" % (i)] != "":
suite = Cnf["Heidi::Options::%s" % (i)]; suite = Cnf["Heidi::Options::%s" % (i)]
if db_access.get_suite_id(suite) == -1: if db_access.get_suite_id(suite) == -1:
utils.fubar("Unknown suite '%s'." %(suite)); utils.fubar("Unknown suite '%s'." %(suite))
else: else:
if action: if action:
utils.fubar("Can only perform one action at a time."); utils.fubar("Can only perform one action at a time.")
action = i; action = i
# Need an action... # Need an action...
if action == None: if action == None:
utils.fubar("No action specified."); utils.fubar("No action specified.")
# Safety/Sanity check # Safety/Sanity check
if action == "set" and suite != "testing": if action == "set" and suite != "testing":
utils.fubar("Will not reset a suite other than testing."); utils.fubar("Will not reset a suite other than testing.")
if action == "list": if action == "list":
get_list(suite); get_list(suite)
else: else:
Logger = logging.Logger(Cnf, "heidi"); Logger = logging.Logger(Cnf, "heidi")
if file_list: if file_list:
for file in file_list: for file in file_list:
process_file(utils.open_file(file), suite, action); process_file(utils.open_file(file), suite, action)
else: else:
process_file(sys.stdin, suite, action); process_file(sys.stdin, suite, action)
Logger.close(); Logger.close()
####################################################################################### #######################################################################################
......
此差异已折叠。
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
################################################################################ ################################################################################
import sys; import sys
import katie, utils; import katie, utils
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
...@@ -45,88 +45,88 @@ Dumps the info in .katie FILE(s). ...@@ -45,88 +45,88 @@ Dumps the info in .katie FILE(s).
def main(): def main():
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('h',"help","Ashley::Options::Help")]; Arguments = [('h',"help","Ashley::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Ashley::Options::%s" % (i)): if not Cnf.has_key("Ashley::Options::%s" % (i)):
Cnf["Ashley::Options::%s" % (i)] = ""; Cnf["Ashley::Options::%s" % (i)] = ""
apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv); apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
Options = Cnf.SubTree("Ashley::Options") Options = Cnf.SubTree("Ashley::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
k = katie.Katie(Cnf); k = katie.Katie(Cnf)
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
arg = utils.validate_changes_file_arg(arg,require_changes=-1); arg = utils.validate_changes_file_arg(arg,require_changes=-1)
k.pkg.changes_file = arg; k.pkg.changes_file = arg
print "%s:" % (arg); print "%s:" % (arg)
k.init_vars(); k.init_vars()
k.update_vars(); k.update_vars()
changes = k.pkg.changes; changes = k.pkg.changes
print " Changes:"; print " Changes:"
# Mandatory changes fields # Mandatory changes fields
for i in [ "source", "version", "maintainer", "urgency", "changedby822", for i in [ "source", "version", "maintainer", "urgency", "changedby822",
"changedby2047", "changedbyname", "maintainer822", "changedby2047", "changedbyname", "maintainer822",
"maintainer2047", "maintainername", "maintaineremail", "maintainer2047", "maintainername", "maintaineremail",
"fingerprint", "changes" ]: "fingerprint", "changes" ]:
print " %s: %s" % (i.capitalize(), changes[i]); print " %s: %s" % (i.capitalize(), changes[i])
del changes[i]; del changes[i]
# Mandatory changes lists # Mandatory changes lists
for i in [ "distribution", "architecture", "closes" ]: for i in [ "distribution", "architecture", "closes" ]:
print " %s: %s" % (i.capitalize(), " ".join(changes[i].keys())); print " %s: %s" % (i.capitalize(), " ".join(changes[i].keys()))
del changes[i]; del changes[i]
# Optional changes fields # Optional changes fields
for i in [ "changed-by", "filecontents", "format" ]: for i in [ "changed-by", "filecontents", "format" ]:
if changes.has_key(i): if changes.has_key(i):
print " %s: %s" % (i.capitalize(), changes[i]); print " %s: %s" % (i.capitalize(), changes[i])
del changes[i]; del changes[i]
print; print
if changes: if changes:
utils.warn("changes still has following unrecognised keys: %s" % (changes.keys())); utils.warn("changes still has following unrecognised keys: %s" % (changes.keys()))
dsc = k.pkg.dsc; dsc = k.pkg.dsc
print " Dsc:"; print " Dsc:"
for i in [ "source", "version", "maintainer", "fingerprint", "uploaders", for i in [ "source", "version", "maintainer", "fingerprint", "uploaders",
"bts changelog" ]: "bts changelog" ]:
if dsc.has_key(i): if dsc.has_key(i):
print " %s: %s" % (i.capitalize(), dsc[i]); print " %s: %s" % (i.capitalize(), dsc[i])
del dsc[i]; del dsc[i]
print; print
if dsc: if dsc:
utils.warn("dsc still has following unrecognised keys: %s" % (dsc.keys())); utils.warn("dsc still has following unrecognised keys: %s" % (dsc.keys()))
files = k.pkg.files; files = k.pkg.files
print " Files:" print " Files:"
for file in files.keys(): for file in files.keys():
print " %s:" % (file); print " %s:" % (file)
for i in [ "package", "version", "architecture", "type", "size", for i in [ "package", "version", "architecture", "type", "size",
"md5sum", "component", "location id", "source package", "md5sum", "component", "location id", "source package",
"source version", "maintainer", "dbtype", "files id", "source version", "maintainer", "dbtype", "files id",
"new", "section", "priority", "pool name" ]: "new", "section", "priority", "pool name" ]:
if files[file].has_key(i): if files[file].has_key(i):
print " %s: %s" % (i.capitalize(), files[file][i]); print " %s: %s" % (i.capitalize(), files[file][i])
del files[file][i]; del files[file][i]
if files[file]: if files[file]:
utils.warn("files[%s] still has following unrecognised keys: %s" % (file, files[file].keys())); utils.warn("files[%s] still has following unrecognised keys: %s" % (file, files[file].keys()))
print; print
dsc_files = k.pkg.dsc_files; dsc_files = k.pkg.dsc_files
print " Dsc Files:"; print " Dsc Files:"
for file in dsc_files.keys(): for file in dsc_files.keys():
print " %s:" % (file); print " %s:" % (file)
# Mandatory fields # Mandatory fields
for i in [ "size", "md5sum" ]: for i in [ "size", "md5sum" ]:
print " %s: %s" % (i.capitalize(), dsc_files[file][i]); print " %s: %s" % (i.capitalize(), dsc_files[file][i])
del dsc_files[file][i]; del dsc_files[file][i]
# Optional fields # Optional fields
for i in [ "files id" ]: for i in [ "files id" ]:
if dsc_files[file].has_key(i): if dsc_files[file].has_key(i):
print " %s: %s" % (i.capitalize(), dsc_files[file][i]); print " %s: %s" % (i.capitalize(), dsc_files[file][i])
del dsc_files[file][i]; del dsc_files[file][i]
if dsc_files[file]: if dsc_files[file]:
utils.warn("dsc_files[%s] still has following unrecognised keys: %s" % (file, dsc_files[file].keys())); utils.warn("dsc_files[%s] still has following unrecognised keys: %s" % (file, dsc_files[file].keys()))
################################################################################ ################################################################################
......
...@@ -40,8 +40,8 @@ import pg, db_access ...@@ -40,8 +40,8 @@ import pg, db_access
################################################################################ ################################################################################
re_package = re.compile(r"^(.+?)_.*"); re_package = re.compile(r"^(.+?)_.*")
re_doc_directory = re.compile(r".*/doc/([^/]*).*"); re_doc_directory = re.compile(r".*/doc/([^/]*).*")
re_contrib = re.compile('^contrib/') re_contrib = re.compile('^contrib/')
re_nonfree = re.compile('^non\-free/') re_nonfree = re.compile('^non\-free/')
...@@ -61,28 +61,28 @@ re_spacestrip = re.compile('(\s)') ...@@ -61,28 +61,28 @@ re_spacestrip = re.compile('(\s)')
# Colour definitions # Colour definitions
# Main # Main
main_colour = "\033[36m"; main_colour = "\033[36m"
# Contrib # Contrib
contrib_colour = "\033[33m"; contrib_colour = "\033[33m"
# Non-Free # Non-Free
nonfree_colour = "\033[31m"; nonfree_colour = "\033[31m"
# Arch # Arch
arch_colour = "\033[32m"; arch_colour = "\033[32m"
# End # End
end_colour = "\033[0m"; end_colour = "\033[0m"
# Bold # Bold
bold_colour = "\033[1m"; bold_colour = "\033[1m"
# Bad maintainer # Bad maintainer
maintainer_colour = arch_colour; maintainer_colour = arch_colour
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
Cnf = utils.get_conf() Cnf = utils.get_conf()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])) projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
################################################################################ ################################################################################
...@@ -107,67 +107,67 @@ def get_depends_parts(depend) : ...@@ -107,67 +107,67 @@ def get_depends_parts(depend) :
return d_parts return d_parts
def get_or_list(depend) : def get_or_list(depend) :
or_list = depend.split("|"); or_list = depend.split("|")
return or_list return or_list
def get_comma_list(depend) : def get_comma_list(depend) :
dep_list = depend.split(","); dep_list = depend.split(",")
return dep_list return dep_list
def split_depends (d_str) : def split_depends (d_str) :
# creates a list of lists of dictionaries of depends (package,version relation) # creates a list of lists of dictionaries of depends (package,version relation)
d_str = re_spacestrip.sub('',d_str); d_str = re_spacestrip.sub('',d_str)
depends_tree = []; depends_tree = []
# first split depends string up amongs comma delimiter # first split depends string up amongs comma delimiter
dep_list = get_comma_list(d_str); dep_list = get_comma_list(d_str)
d = 0; d = 0
while d < len(dep_list): while d < len(dep_list):
# put depends into their own list # put depends into their own list
depends_tree.append([dep_list[d]]); depends_tree.append([dep_list[d]])
d += 1; d += 1
d = 0; d = 0
while d < len(depends_tree): while d < len(depends_tree):
k = 0; k = 0
# split up Or'd depends into a multi-item list # split up Or'd depends into a multi-item list
depends_tree[d] = get_or_list(depends_tree[d][0]); depends_tree[d] = get_or_list(depends_tree[d][0])
while k < len(depends_tree[d]): while k < len(depends_tree[d]):
# split depends into {package, version relation} # split depends into {package, version relation}
depends_tree[d][k] = get_depends_parts(depends_tree[d][k]); depends_tree[d][k] = get_depends_parts(depends_tree[d][k])
k += 1; k += 1
d += 1; d += 1
return depends_tree; return depends_tree
def read_control (filename): def read_control (filename):
recommends = []; recommends = []
depends = []; depends = []
section = ''; section = ''
maintainer = ''; maintainer = ''
arch = ''; arch = ''
deb_file = utils.open_file(filename); deb_file = utils.open_file(filename)
try: try:
extracts = apt_inst.debExtractControl(deb_file); extracts = apt_inst.debExtractControl(deb_file)
control = apt_pkg.ParseSection(extracts); control = apt_pkg.ParseSection(extracts)
except: except:
print "can't parse control info"; print "can't parse control info"
control = ''; control = ''
deb_file.close(); deb_file.close()
control_keys = control.keys(); control_keys = control.keys()
if control.has_key("Depends"): if control.has_key("Depends"):
depends_str = control.Find("Depends"); depends_str = control.Find("Depends")
# create list of dependancy lists # create list of dependancy lists
depends = split_depends(depends_str); depends = split_depends(depends_str)
if control.has_key("Recommends"): if control.has_key("Recommends"):
recommends_str = control.Find("Recommends"); recommends_str = control.Find("Recommends")
recommends = split_depends(recommends_str); recommends = split_depends(recommends_str)
if control.has_key("Section"): if control.has_key("Section"):
section_str = control.Find("Section"); section_str = control.Find("Section")
c_match = re_contrib.search(section_str) c_match = re_contrib.search(section_str)
nf_match = re_nonfree.search(section_str) nf_match = re_nonfree.search(section_str)
...@@ -189,78 +189,78 @@ def read_control (filename): ...@@ -189,78 +189,78 @@ def read_control (filename):
localhost = re_localhost.search(maintainer) localhost = re_localhost.search(maintainer)
if localhost: if localhost:
#highlight bad email #highlight bad email
maintainer = maintainer_colour + maintainer + end_colour; maintainer = maintainer_colour + maintainer + end_colour
return (control, control_keys, section, depends, recommends, arch, maintainer) return (control, control_keys, section, depends, recommends, arch, maintainer)
def read_dsc (dsc_filename): def read_dsc (dsc_filename):
dsc = {}; dsc = {}
dsc_file = utils.open_file(dsc_filename); dsc_file = utils.open_file(dsc_filename)
try: try:
dsc = utils.parse_changes(dsc_filename); dsc = utils.parse_changes(dsc_filename)
except: except:
print "can't parse control info" print "can't parse control info"
dsc_file.close(); dsc_file.close()
filecontents = strip_pgp_signature(dsc_filename); filecontents = strip_pgp_signature(dsc_filename)
if dsc.has_key("build-depends"): if dsc.has_key("build-depends"):
builddep = split_depends(dsc["build-depends"]); builddep = split_depends(dsc["build-depends"])
builddepstr = create_depends_string(builddep); builddepstr = create_depends_string(builddep)
filecontents = re_builddep.sub("Build-Depends: "+builddepstr, filecontents); filecontents = re_builddep.sub("Build-Depends: "+builddepstr, filecontents)
if dsc.has_key("build-depends-indep"): if dsc.has_key("build-depends-indep"):
builddepindstr = create_depends_string(split_depends(dsc["build-depends-indep"])); builddepindstr = create_depends_string(split_depends(dsc["build-depends-indep"]))
filecontents = re_builddepind.sub("Build-Depends-Indep: "+builddepindstr, filecontents); filecontents = re_builddepind.sub("Build-Depends-Indep: "+builddepindstr, filecontents)
if dsc.has_key("architecture") : if dsc.has_key("architecture") :
if (dsc["architecture"] != "any"): if (dsc["architecture"] != "any"):
newarch = arch_colour + dsc["architecture"] + end_colour; newarch = arch_colour + dsc["architecture"] + end_colour
filecontents = re_arch.sub("Architecture: " + newarch, filecontents); filecontents = re_arch.sub("Architecture: " + newarch, filecontents)
return filecontents; return filecontents
def create_depends_string (depends_tree): def create_depends_string (depends_tree):
# just look up unstable for now. possibly pull from .changes later # just look up unstable for now. possibly pull from .changes later
suite = "unstable"; suite = "unstable"
result = ""; result = ""
comma_count = 1; comma_count = 1
for l in depends_tree: for l in depends_tree:
if (comma_count >= 2): if (comma_count >= 2):
result += ", "; result += ", "
or_count = 1 or_count = 1
for d in l: for d in l:
if (or_count >= 2 ): if (or_count >= 2 ):
result += " | " result += " | "
# doesn't do version lookup yet. # doesn't do version lookup yet.
q = projectB.query("SELECT DISTINCT(b.package), b.version, c.name, su.suite_name FROM binaries b, files fi, location l, component c, bin_associations ba, suite su WHERE b.package='%s' AND b.file = fi.id AND fi.location = l.id AND l.component = c.id AND ba.bin=b.id AND ba.suite = su.id AND su.suite_name='%s' ORDER BY b.version desc" % (d['name'], suite)); q = projectB.query("SELECT DISTINCT(b.package), b.version, c.name, su.suite_name FROM binaries b, files fi, location l, component c, bin_associations ba, suite su WHERE b.package='%s' AND b.file = fi.id AND fi.location = l.id AND l.component = c.id AND ba.bin=b.id AND ba.suite = su.id AND su.suite_name='%s' ORDER BY b.version desc" % (d['name'], suite))
ql = q.getresult(); ql = q.getresult()
if ql: if ql:
i = ql[0]; i = ql[0]
if i[2] == "contrib": if i[2] == "contrib":
result += contrib_colour + d['name']; result += contrib_colour + d['name']
elif i[2] == "non-free": elif i[2] == "non-free":
result += nonfree_colour + d['name']; result += nonfree_colour + d['name']
else : else :
result += main_colour + d['name']; result += main_colour + d['name']
if d['version'] != '' : if d['version'] != '' :
result += " (%s)" % (d['version']); result += " (%s)" % (d['version'])
result += end_colour; result += end_colour
else: else:
result += bold_colour + d['name']; result += bold_colour + d['name']
if d['version'] != '' : if d['version'] != '' :
result += " (%s)" % (d['version']); result += " (%s)" % (d['version'])
result += end_colour; result += end_colour
or_count += 1; or_count += 1
comma_count += 1; comma_count += 1
return result; return result
def output_deb_info(filename): def output_deb_info(filename):
(control, control_keys, section, depends, recommends, arch, maintainer) = read_control(filename); (control, control_keys, section, depends, recommends, arch, maintainer) = read_control(filename)
if control == '': if control == '':
print "no control info" print "no control info"
...@@ -268,174 +268,174 @@ def output_deb_info(filename): ...@@ -268,174 +268,174 @@ def output_deb_info(filename):
for key in control_keys : for key in control_keys :
output = " " + key + ": " output = " " + key + ": "
if key == 'Depends': if key == 'Depends':
output += create_depends_string(depends); output += create_depends_string(depends)
elif key == 'Recommends': elif key == 'Recommends':
output += create_depends_string(recommends); output += create_depends_string(recommends)
elif key == 'Section': elif key == 'Section':
output += section; output += section
elif key == 'Architecture': elif key == 'Architecture':
output += arch; output += arch
elif key == 'Maintainer': elif key == 'Maintainer':
output += maintainer; output += maintainer
elif key == 'Description': elif key == 'Description':
desc = control.Find(key); desc = control.Find(key)
desc = re_newlinespace.sub('\n ', desc); desc = re_newlinespace.sub('\n ', desc)
output += desc; output += desc
else: else:
output += control.Find(key); output += control.Find(key)
print output; print output
def do_command (command, filename): def do_command (command, filename):
o = os.popen("%s %s" % (command, filename)); o = os.popen("%s %s" % (command, filename))
print o.read(); print o.read()
def print_copyright (deb_filename): def print_copyright (deb_filename):
package = re_package.sub(r'\1', deb_filename); package = re_package.sub(r'\1', deb_filename)
o = os.popen("ar p %s data.tar.gz | tar tzvf - | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{ print $6 }' | head -n 1" % (deb_filename)); o = os.popen("ar p %s data.tar.gz | tar tzvf - | egrep 'usr(/share)?/doc/[^/]*/copyright' | awk '{ print $6 }' | head -n 1" % (deb_filename))
copyright = o.read()[:-1]; copyright = o.read()[:-1]
if copyright == "": if copyright == "":
print "WARNING: No copyright found, please check package manually." print "WARNING: No copyright found, please check package manually."
return; return
doc_directory = re_doc_directory.sub(r'\1', copyright); doc_directory = re_doc_directory.sub(r'\1', copyright)
if package != doc_directory: if package != doc_directory:
print "WARNING: wrong doc directory (expected %s, got %s)." % (package, doc_directory); print "WARNING: wrong doc directory (expected %s, got %s)." % (package, doc_directory)
return; return
o = os.popen("ar p %s data.tar.gz | tar xzOf - %s" % (deb_filename, copyright)); o = os.popen("ar p %s data.tar.gz | tar xzOf - %s" % (deb_filename, copyright))
print o.read(); print o.read()
def check_dsc (dsc_filename): def check_dsc (dsc_filename):
print "---- .dsc file for %s ----" % (dsc_filename); print "---- .dsc file for %s ----" % (dsc_filename)
(dsc) = read_dsc(dsc_filename) (dsc) = read_dsc(dsc_filename)
print dsc print dsc
def check_deb (deb_filename): def check_deb (deb_filename):
filename = os.path.basename(deb_filename); filename = os.path.basename(deb_filename)
if filename.endswith(".udeb"): if filename.endswith(".udeb"):
is_a_udeb = 1; is_a_udeb = 1
else: else:
is_a_udeb = 0; is_a_udeb = 0
print "---- control file for %s ----" % (filename); print "---- control file for %s ----" % (filename)
#do_command ("dpkg -I", deb_filename); #do_command ("dpkg -I", deb_filename)
output_deb_info(deb_filename) output_deb_info(deb_filename)
if is_a_udeb: if is_a_udeb:
print "---- skipping lintian check for deb ----"; print "---- skipping lintian check for deb ----"
print ; print
else: else:
print "---- lintian check for %s ----" % (filename); print "---- lintian check for %s ----" % (filename)
do_command ("lintian", deb_filename); do_command ("lintian", deb_filename)
print "---- linda check for %s ----" % (filename); print "---- linda check for %s ----" % (filename)
do_command ("linda", deb_filename); do_command ("linda", deb_filename)
print "---- contents of %s ----" % (filename); print "---- contents of %s ----" % (filename)
do_command ("dpkg -c", deb_filename); do_command ("dpkg -c", deb_filename)
if is_a_udeb: if is_a_udeb:
print "---- skipping copyright for deb ----"; print "---- skipping copyright for deb ----"
else: else:
print "---- copyright of %s ----" % (filename); print "---- copyright of %s ----" % (filename)
print_copyright(deb_filename); print_copyright(deb_filename)
print "---- file listing of %s ----" % (filename); print "---- file listing of %s ----" % (filename)
do_command ("ls -l", deb_filename); do_command ("ls -l", deb_filename)
# Read a file, strip the signature and return the modified contents as # Read a file, strip the signature and return the modified contents as
# a string. # a string.
def strip_pgp_signature (filename): def strip_pgp_signature (filename):
file = utils.open_file (filename); file = utils.open_file (filename)
contents = ""; contents = ""
inside_signature = 0; inside_signature = 0
skip_next = 0; skip_next = 0
for line in file.readlines(): for line in file.readlines():
if line[:-1] == "": if line[:-1] == "":
continue; continue
if inside_signature: if inside_signature:
continue; continue
if skip_next: if skip_next:
skip_next = 0; skip_next = 0
continue; continue
if line.startswith("-----BEGIN PGP SIGNED MESSAGE"): if line.startswith("-----BEGIN PGP SIGNED MESSAGE"):
skip_next = 1; skip_next = 1
continue; continue
if line.startswith("-----BEGIN PGP SIGNATURE"): if line.startswith("-----BEGIN PGP SIGNATURE"):
inside_signature = 1; inside_signature = 1
continue; continue
if line.startswith("-----END PGP SIGNATURE"): if line.startswith("-----END PGP SIGNATURE"):
inside_signature = 0; inside_signature = 0
continue; continue
contents += line; contents += line
file.close(); file.close()
return contents; return contents
# Display the .changes [without the signature] # Display the .changes [without the signature]
def display_changes (changes_filename): def display_changes (changes_filename):
print "---- .changes file for %s ----" % (changes_filename); print "---- .changes file for %s ----" % (changes_filename)
print strip_pgp_signature(changes_filename); print strip_pgp_signature(changes_filename)
def check_changes (changes_filename): def check_changes (changes_filename):
display_changes(changes_filename); display_changes(changes_filename)
changes = utils.parse_changes (changes_filename); changes = utils.parse_changes (changes_filename)
files = utils.build_file_list(changes); files = utils.build_file_list(changes)
for file in files.keys(): for file in files.keys():
if file.endswith(".deb") or file.endswith(".udeb"): if file.endswith(".deb") or file.endswith(".udeb"):
check_deb(file); check_deb(file)
if file.endswith(".dsc"): if file.endswith(".dsc"):
check_dsc(file); check_dsc(file)
# else: => byhand # else: => byhand
def main (): def main ():
global Cnf, projectB, db_files, waste, excluded; global Cnf, projectB, db_files, waste, excluded
# Cnf = utils.get_conf() # Cnf = utils.get_conf()
Arguments = [('h',"help","Fernanda::Options::Help")]; Arguments = [('h',"help","Fernanda::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Frenanda::Options::%s" % (i)): if not Cnf.has_key("Frenanda::Options::%s" % (i)):
Cnf["Fernanda::Options::%s" % (i)] = ""; Cnf["Fernanda::Options::%s" % (i)] = ""
args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); args = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Fernanda::Options") Options = Cnf.SubTree("Fernanda::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
stdout_fd = sys.stdout; stdout_fd = sys.stdout
for file in args: for file in args:
try: try:
# Pipe output for each argument through less # Pipe output for each argument through less
less_fd = os.popen("less -R -", 'w', 0); less_fd = os.popen("less -R -", 'w', 0)
# -R added to display raw control chars for colour # -R added to display raw control chars for colour
sys.stdout = less_fd; sys.stdout = less_fd
try: try:
if file.endswith(".changes"): if file.endswith(".changes"):
check_changes(file); check_changes(file)
elif file.endswith(".deb") or file.endswith(".udeb"): elif file.endswith(".deb") or file.endswith(".udeb"):
check_deb(file); check_deb(file)
elif file.endswith(".dsc"): elif file.endswith(".dsc"):
check_dsc(file); check_dsc(file)
else: else:
utils.fubar("Unrecognised file type: '%s'." % (file)); utils.fubar("Unrecognised file type: '%s'." % (file))
finally: finally:
# Reset stdout here so future less invocations aren't FUBAR # Reset stdout here so future less invocations aren't FUBAR
less_fd.close(); less_fd.close()
sys.stdout = stdout_fd; sys.stdout = stdout_fd
except IOError, e: except IOError, e:
if errno.errorcode[e.errno] == 'EPIPE': if errno.errorcode[e.errno] == 'EPIPE':
utils.warn("[fernanda] Caught EPIPE; skipping."); utils.warn("[fernanda] Caught EPIPE; skipping.")
pass; pass
else: else:
raise; raise
except KeyboardInterrupt: except KeyboardInterrupt:
utils.warn("[fernanda] Caught C-c; skipping."); utils.warn("[fernanda] Caught C-c; skipping.")
pass; pass
####################################################################################### #######################################################################################
......
...@@ -20,14 +20,14 @@ ...@@ -20,14 +20,14 @@
################################################################################ ################################################################################
import ldap, pg, sys, time; import ldap, pg, sys, time
import apt_pkg; import apt_pkg
import utils; import utils
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
################################################################################ ################################################################################
...@@ -41,54 +41,54 @@ Checks for users with no packages in the archive ...@@ -41,54 +41,54 @@ Checks for users with no packages in the archive
################################################################################ ################################################################################
def get_ldap_value(entry, value): def get_ldap_value(entry, value):
ret = entry.get(value); ret = entry.get(value)
if not ret: if not ret:
return ""; return ""
else: else:
# FIXME: what about > 0 ? # FIXME: what about > 0 ?
return ret[0]; return ret[0]
def main(): def main():
global Cnf, projectB; global Cnf, projectB
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('h',"help","Rosamund::Options::Help")]; Arguments = [('h',"help","Rosamund::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Rosamund::Options::%s" % (i)): if not Cnf.has_key("Rosamund::Options::%s" % (i)):
Cnf["Rosamund::Options::%s" % (i)] = ""; Cnf["Rosamund::Options::%s" % (i)] = ""
apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv); apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
Options = Cnf.SubTree("Rosamund::Options") Options = Cnf.SubTree("Rosamund::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
before = time.time(); before = time.time()
sys.stderr.write("[Getting info from the LDAP server..."); sys.stderr.write("[Getting info from the LDAP server...")
LDAPDn = Cnf["Emilie::LDAPDn"]; LDAPDn = Cnf["Emilie::LDAPDn"]
LDAPServer = Cnf["Emilie::LDAPServer"]; LDAPServer = Cnf["Emilie::LDAPServer"]
l = ldap.open(LDAPServer); l = ldap.open(LDAPServer)
l.simple_bind_s("",""); l.simple_bind_s("","")
Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL, Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
"(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Julia::ValidGID"]), "(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Julia::ValidGID"]),
["uid", "cn", "mn", "sn", "createtimestamp"]); ["uid", "cn", "mn", "sn", "createtimestamp"])
sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before))); sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
db_uid = {}; db_uid = {}
db_unstable_uid = {}; db_unstable_uid = {}
before = time.time(); before = time.time()
sys.stderr.write("[Getting UID info for entire archive..."); sys.stderr.write("[Getting UID info for entire archive...")
q = projectB.query("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id;"); q = projectB.query("SELECT DISTINCT u.uid FROM uid u, fingerprint f WHERE f.uid = u.id;")
sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before))); sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
for i in q.getresult(): for i in q.getresult():
db_uid[i[0]] = ""; db_uid[i[0]] = ""
before = time.time(); before = time.time()
sys.stderr.write("[Getting UID info for unstable..."); sys.stderr.write("[Getting UID info for unstable...")
q = projectB.query(""" q = projectB.query("""
SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint f, uid u
WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id WHERE f.uid = u.id AND sa.source = s.id AND sa.suite = su.id
...@@ -96,39 +96,39 @@ SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint ...@@ -96,39 +96,39 @@ SELECT DISTINCT u.uid FROM suite su, src_associations sa, source s, fingerprint
UNION UNION
SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u SELECT DISTINCT u.uid FROM suite su, bin_associations ba, binaries b, fingerprint f, uid u
WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id WHERE f.uid = u.id AND ba.bin = b.id AND ba.suite = su.id
AND su.suite_name = 'unstable' AND b.sig_fpr = f.id"""); AND su.suite_name = 'unstable' AND b.sig_fpr = f.id""")
sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before))); sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
for i in q.getresult(): for i in q.getresult():
db_unstable_uid[i[0]] = ""; db_unstable_uid[i[0]] = ""
now = time.time(); now = time.time()
for i in Attrs: for i in Attrs:
entry = i[1]; entry = i[1]
uid = entry["uid"][0]; uid = entry["uid"][0]
created = time.mktime(time.strptime(entry["createtimestamp"][0][:8], '%Y%m%d')); created = time.mktime(time.strptime(entry["createtimestamp"][0][:8], '%Y%m%d'))
diff = now - created; diff = now - created
# 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365 # 31536000 is 1 year in seconds, i.e. 60 * 60 * 24 * 365
if diff < 31536000 / 2: if diff < 31536000 / 2:
when = "Less than 6 months ago"; when = "Less than 6 months ago"
elif diff < 31536000: elif diff < 31536000:
when = "Less than 1 year ago"; when = "Less than 1 year ago"
elif diff < 31536000 * 1.5: elif diff < 31536000 * 1.5:
when = "Less than 18 months ago"; when = "Less than 18 months ago"
elif diff < 31536000 * 2: elif diff < 31536000 * 2:
when = "Less than 2 years ago"; when = "Less than 2 years ago"
elif diff < 31536000 * 3: elif diff < 31536000 * 3:
when = "Less than 3 years ago"; when = "Less than 3 years ago"
else: else:
when = "More than 3 years ago"; when = "More than 3 years ago"
name = " ".join([get_ldap_value(entry, "cn"), name = " ".join([get_ldap_value(entry, "cn"),
get_ldap_value(entry, "mn"), get_ldap_value(entry, "mn"),
get_ldap_value(entry, "sn")]); get_ldap_value(entry, "sn")])
if not db_uid.has_key(uid): if not db_uid.has_key(uid):
print "NONE %s (%s) %s" % (uid, name, when); print "NONE %s (%s) %s" % (uid, name, when)
else: else:
if not db_unstable_uid.has_key(uid): if not db_unstable_uid.has_key(uid):
print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when); print "NOT_UNSTABLE %s (%s) %s" % (uid, name, when)
############################################################ ############################################################
......
...@@ -36,10 +36,10 @@ import utils ...@@ -36,10 +36,10 @@ import utils
################################################################################ ################################################################################
projectB = None; projectB = None
Cnf = None; Cnf = None
Logger = None; Logger = None
Options = None; Options = None
################################################################################ ################################################################################
...@@ -52,7 +52,7 @@ Write out ed-style diffs to Packages/Source lists ...@@ -52,7 +52,7 @@ Write out ed-style diffs to Packages/Source lists
-p name for the patch (defaults to current time) -p name for the patch (defaults to current time)
-n take no action -n take no action
""" """
sys.exit(exit_code); sys.exit(exit_code)
def tryunlink(file): def tryunlink(file):
...@@ -286,9 +286,9 @@ def genchanges(Options, outdir, oldfile, origfile, maxdiffs = 14): ...@@ -286,9 +286,9 @@ def genchanges(Options, outdir, oldfile, origfile, maxdiffs = 14):
def main(): def main():
global Cnf, Options, Logger global Cnf, Options, Logger
os.umask(0002); os.umask(0002)
Cnf = utils.get_conf(); Cnf = utils.get_conf()
Arguments = [ ('h', "help", "Tiffani::Options::Help"), Arguments = [ ('h', "help", "Tiffani::Options::Help"),
('c', None, "Tiffani::Options::CanonicalPath", "hasArg"), ('c', None, "Tiffani::Options::CanonicalPath", "hasArg"),
('p', "patchname", "Tiffani::Options::PatchName", "hasArg"), ('p', "patchname", "Tiffani::Options::PatchName", "hasArg"),
...@@ -296,10 +296,10 @@ def main(): ...@@ -296,10 +296,10 @@ def main():
('d', "tmpdir", "Tiffani::Options::TempDir", "hasArg"), ('d', "tmpdir", "Tiffani::Options::TempDir", "hasArg"),
('m', "maxdiffs", "Tiffani::Options::MaxDiffs", "hasArg"), ('m', "maxdiffs", "Tiffani::Options::MaxDiffs", "hasArg"),
('n', "n-act", "Tiffani::Options::NoAct"), ('n', "n-act", "Tiffani::Options::NoAct"),
]; ]
suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Tiffani::Options"); Options = Cnf.SubTree("Tiffani::Options")
if Options.has_key("Help"): usage(); if Options.has_key("Help"): usage()
maxdiffs = Options.get("MaxDiffs::Default", "14") maxdiffs = Options.get("MaxDiffs::Default", "14")
maxpackages = Options.get("MaxDiffs::Packages", maxdiffs) maxpackages = Options.get("MaxDiffs::Packages", maxdiffs)
...@@ -340,11 +340,11 @@ def main(): ...@@ -340,11 +340,11 @@ def main():
else: else:
components = [] components = []
suite_suffix = Cnf.Find("Dinstall::SuiteSuffix"); suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
if components and suite_suffix: if components and suite_suffix:
longsuite = suite + "/" + suite_suffix; longsuite = suite + "/" + suite_suffix
else: else:
longsuite = suite; longsuite = suite
tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite)) tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
...@@ -353,8 +353,8 @@ def main(): ...@@ -353,8 +353,8 @@ def main():
elif AptCnf.has_key("bindirectory::%s" % (tree)): elif AptCnf.has_key("bindirectory::%s" % (tree)):
sections = AptCnf["bindirectory::%s::Sections" % (tree)].split() sections = AptCnf["bindirectory::%s::Sections" % (tree)].split()
else: else:
aptcnf_filename = os.path.basename(utils.which_apt_conf_file()); aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename); print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
continue continue
for architecture in architectures: for architecture in architectures:
......
...@@ -123,20 +123,20 @@ def print_sha1_files (tree, files): ...@@ -123,20 +123,20 @@ def print_sha1_files (tree, files):
def main (): def main ():
global Cnf, AptCnf, projectB, out global Cnf, AptCnf, projectB, out
out = sys.stdout; out = sys.stdout
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('h',"help","Ziyi::Options::Help")]; Arguments = [('h',"help","Ziyi::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Ziyi::Options::%s" % (i)): if not Cnf.has_key("Ziyi::Options::%s" % (i)):
Cnf["Ziyi::Options::%s" % (i)] = ""; Cnf["Ziyi::Options::%s" % (i)] = ""
suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv) suites = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Ziyi::Options") Options = Cnf.SubTree("Ziyi::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
AptCnf = apt_pkg.newConfiguration() AptCnf = apt_pkg.newConfiguration()
apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file()) apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file())
...@@ -169,11 +169,11 @@ def main (): ...@@ -169,11 +169,11 @@ def main ():
else: else:
components = [] components = []
suite_suffix = Cnf.Find("Dinstall::SuiteSuffix"); suite_suffix = Cnf.Find("Dinstall::SuiteSuffix")
if components and suite_suffix: if components and suite_suffix:
longsuite = suite + "/" + suite_suffix; longsuite = suite + "/" + suite_suffix
else: else:
longsuite = suite; longsuite = suite
tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite)) tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite))
...@@ -182,8 +182,8 @@ def main (): ...@@ -182,8 +182,8 @@ def main ():
elif AptCnf.has_key("bindirectory::%s" % (tree)): elif AptCnf.has_key("bindirectory::%s" % (tree)):
pass pass
else: else:
aptcnf_filename = os.path.basename(utils.which_apt_conf_file()); aptcnf_filename = os.path.basename(utils.which_apt_conf_file())
print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename); print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename)
continue continue
print Cnf["Dir::Root"] + tree + "/Release" print Cnf["Dir::Root"] + tree + "/Release"
...@@ -238,15 +238,15 @@ def main (): ...@@ -238,15 +238,15 @@ def main ():
release = open(relpath, "w") release = open(relpath, "w")
#release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w") #release = open(longsuite.replace("/","_") + "_" + arch + "_" + sec + "_Release", "w")
except IOError: except IOError:
utils.fubar("Couldn't write to " + relpath); utils.fubar("Couldn't write to " + relpath)
release.write("Archive: %s\n" % (suite)) release.write("Archive: %s\n" % (suite))
if version != "": if version != "":
release.write("Version: %s\n" % (version)) release.write("Version: %s\n" % (version))
if suite_suffix: if suite_suffix:
release.write("Component: %s/%s\n" % (suite_suffix,sec)); release.write("Component: %s/%s\n" % (suite_suffix,sec))
else: else:
release.write("Component: %s\n" % (sec)); release.write("Component: %s\n" % (sec))
release.write("Origin: %s\n" % (origin)) release.write("Origin: %s\n" % (origin))
release.write("Label: %s\n" % (label)) release.write("Label: %s\n" % (label))
if notautomatic != "": if notautomatic != "":
......
此差异已折叠。
...@@ -45,17 +45,17 @@ ...@@ -45,17 +45,17 @@
################################################################################ ################################################################################
import commands, ldap, pg, re, sys, time; import commands, ldap, pg, re, sys, time
import apt_pkg; import apt_pkg
import db_access, utils; import db_access, utils
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
re_gpg_fingerprint = re.compile(r"^\s+Key fingerprint = (.*)$", re.MULTILINE); re_gpg_fingerprint = re.compile(r"^\s+Key fingerprint = (.*)$", re.MULTILINE)
re_debian_address = re.compile(r"^.*<(.*)@debian\.org>$", re.MULTILINE); re_debian_address = re.compile(r"^.*<(.*)@debian\.org>$", re.MULTILINE)
################################################################################ ################################################################################
...@@ -69,148 +69,148 @@ Syncs fingerprint and uid tables with a debian.org LDAP DB ...@@ -69,148 +69,148 @@ Syncs fingerprint and uid tables with a debian.org LDAP DB
################################################################################ ################################################################################
def get_ldap_value(entry, value): def get_ldap_value(entry, value):
ret = entry.get(value); ret = entry.get(value)
if not ret: if not ret:
return ""; return ""
else: else:
# FIXME: what about > 0 ? # FIXME: what about > 0 ?
return ret[0]; return ret[0]
def main(): def main():
global Cnf, projectB; global Cnf, projectB
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('h',"help","Emilie::Options::Help")]; Arguments = [('h',"help","Emilie::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Emilie::Options::%s" % (i)): if not Cnf.has_key("Emilie::Options::%s" % (i)):
Cnf["Emilie::Options::%s" % (i)] = ""; Cnf["Emilie::Options::%s" % (i)] = ""
apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv); apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
Options = Cnf.SubTree("Emilie::Options") Options = Cnf.SubTree("Emilie::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
#before = time.time(); #before = time.time()
#sys.stderr.write("[Getting info from the LDAP server..."); #sys.stderr.write("[Getting info from the LDAP server...")
LDAPDn = Cnf["Emilie::LDAPDn"]; LDAPDn = Cnf["Emilie::LDAPDn"]
LDAPServer = Cnf["Emilie::LDAPServer"]; LDAPServer = Cnf["Emilie::LDAPServer"]
l = ldap.open(LDAPServer); l = ldap.open(LDAPServer)
l.simple_bind_s("",""); l.simple_bind_s("","")
Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL, Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL,
"(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Julia::ValidGID"]), "(&(keyfingerprint=*)(gidnumber=%s))" % (Cnf["Julia::ValidGID"]),
["uid", "keyfingerprint"]); ["uid", "keyfingerprint"])
#sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before))); #sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)))
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
# Sync LDAP with DB # Sync LDAP with DB
db_fin_uid = {}; db_fin_uid = {}
ldap_fin_uid_id = {}; ldap_fin_uid_id = {}
q = projectB.query(""" q = projectB.query("""
SELECT f.fingerprint, f.id, u.uid FROM fingerprint f, uid u WHERE f.uid = u.id SELECT f.fingerprint, f.id, u.uid FROM fingerprint f, uid u WHERE f.uid = u.id
UNION SELECT f.fingerprint, f.id, null FROM fingerprint f where f.uid is null"""); UNION SELECT f.fingerprint, f.id, null FROM fingerprint f where f.uid is null""")
for i in q.getresult(): for i in q.getresult():
(fingerprint, fingerprint_id, uid) = i; (fingerprint, fingerprint_id, uid) = i
db_fin_uid[fingerprint] = (uid, fingerprint_id); db_fin_uid[fingerprint] = (uid, fingerprint_id)
for i in Attrs: for i in Attrs:
entry = i[1]; entry = i[1]
fingerprints = entry["keyFingerPrint"]; fingerprints = entry["keyFingerPrint"]
uid = entry["uid"][0]; uid = entry["uid"][0]
uid_id = db_access.get_or_set_uid_id(uid); uid_id = db_access.get_or_set_uid_id(uid)
for fingerprint in fingerprints: for fingerprint in fingerprints:
ldap_fin_uid_id[fingerprint] = (uid, uid_id); ldap_fin_uid_id[fingerprint] = (uid, uid_id)
if db_fin_uid.has_key(fingerprint): if db_fin_uid.has_key(fingerprint):
(existing_uid, fingerprint_id) = db_fin_uid[fingerprint]; (existing_uid, fingerprint_id) = db_fin_uid[fingerprint]
if not existing_uid: if not existing_uid:
q = projectB.query("UPDATE fingerprint SET uid = %s WHERE id = %s" % (uid_id, fingerprint_id)); q = projectB.query("UPDATE fingerprint SET uid = %s WHERE id = %s" % (uid_id, fingerprint_id))
print "Assigning %s to 0x%s." % (uid, fingerprint); print "Assigning %s to 0x%s." % (uid, fingerprint)
else: else:
if existing_uid != uid: if existing_uid != uid:
utils.fubar("%s has %s in LDAP, but projectB says it should be %s." % (uid, fingerprint, existing_uid)); utils.fubar("%s has %s in LDAP, but projectB says it should be %s." % (uid, fingerprint, existing_uid))
# Try to update people who sign with non-primary key # Try to update people who sign with non-primary key
q = projectB.query("SELECT fingerprint, id FROM fingerprint WHERE uid is null"); q = projectB.query("SELECT fingerprint, id FROM fingerprint WHERE uid is null")
for i in q.getresult(): for i in q.getresult():
(fingerprint, fingerprint_id) = i; (fingerprint, fingerprint_id) = i
cmd = "gpg --no-default-keyring --keyring=%s --keyring=%s --fingerprint %s" \ cmd = "gpg --no-default-keyring --keyring=%s --keyring=%s --fingerprint %s" \
% (Cnf["Dinstall::PGPKeyring"], Cnf["Dinstall::GPGKeyring"], % (Cnf["Dinstall::PGPKeyring"], Cnf["Dinstall::GPGKeyring"],
fingerprint); fingerprint)
(result, output) = commands.getstatusoutput(cmd); (result, output) = commands.getstatusoutput(cmd)
if result == 0: if result == 0:
m = re_gpg_fingerprint.search(output); m = re_gpg_fingerprint.search(output)
if not m: if not m:
print output print output
utils.fubar("0x%s: No fingerprint found in gpg output but it returned 0?\n%s" % (fingerprint, utils.prefix_multi_line_string(output, " [GPG output:] "))); utils.fubar("0x%s: No fingerprint found in gpg output but it returned 0?\n%s" % (fingerprint, utils.prefix_multi_line_string(output, " [GPG output:] ")))
primary_key = m.group(1); primary_key = m.group(1)
primary_key = primary_key.replace(" ",""); primary_key = primary_key.replace(" ","")
if not ldap_fin_uid_id.has_key(primary_key): if not ldap_fin_uid_id.has_key(primary_key):
utils.fubar("0x%s (from 0x%s): no UID found in LDAP" % (primary_key, fingerprint)); utils.fubar("0x%s (from 0x%s): no UID found in LDAP" % (primary_key, fingerprint))
(uid, uid_id) = ldap_fin_uid_id[primary_key]; (uid, uid_id) = ldap_fin_uid_id[primary_key]
q = projectB.query("UPDATE fingerprint SET uid = %s WHERE id = %s" % (uid_id, fingerprint_id)); q = projectB.query("UPDATE fingerprint SET uid = %s WHERE id = %s" % (uid_id, fingerprint_id))
print "Assigning %s to 0x%s." % (uid, fingerprint); print "Assigning %s to 0x%s." % (uid, fingerprint)
else: else:
extra_keyrings = ""; extra_keyrings = ""
for keyring in Cnf.ValueList("Emilie::ExtraKeyrings"): for keyring in Cnf.ValueList("Emilie::ExtraKeyrings"):
extra_keyrings += " --keyring=%s" % (keyring); extra_keyrings += " --keyring=%s" % (keyring)
cmd = "gpg --keyring=%s --keyring=%s %s --list-key %s" \ cmd = "gpg --keyring=%s --keyring=%s %s --list-key %s" \
% (Cnf["Dinstall::PGPKeyring"], Cnf["Dinstall::GPGKeyring"], % (Cnf["Dinstall::PGPKeyring"], Cnf["Dinstall::GPGKeyring"],
extra_keyrings, fingerprint); extra_keyrings, fingerprint)
(result, output) = commands.getstatusoutput(cmd); (result, output) = commands.getstatusoutput(cmd)
if result != 0: if result != 0:
cmd = "gpg --keyserver=%s --allow-non-selfsigned-uid --recv-key %s" % (Cnf["Emilie::KeyServer"], fingerprint); cmd = "gpg --keyserver=%s --allow-non-selfsigned-uid --recv-key %s" % (Cnf["Emilie::KeyServer"], fingerprint)
(result, output) = commands.getstatusoutput(cmd); (result, output) = commands.getstatusoutput(cmd)
if result != 0: if result != 0:
print "0x%s: NOT found on keyserver." % (fingerprint); print "0x%s: NOT found on keyserver." % (fingerprint)
print cmd print cmd
print result print result
print output print output
continue; continue
else: else:
cmd = "gpg --list-key %s" % (fingerprint); cmd = "gpg --list-key %s" % (fingerprint)
(result, output) = commands.getstatusoutput(cmd); (result, output) = commands.getstatusoutput(cmd)
if result != 0: if result != 0:
print "0x%s: --list-key returned error after --recv-key didn't." % (fingerprint); print "0x%s: --list-key returned error after --recv-key didn't." % (fingerprint)
print cmd print cmd
print result print result
print output print output
continue; continue
m = re_debian_address.search(output); m = re_debian_address.search(output)
if m: if m:
guess_uid = m.group(1); guess_uid = m.group(1)
else: else:
guess_uid = "???"; guess_uid = "???"
name = " ".join(output.split('\n')[0].split()[3:]); name = " ".join(output.split('\n')[0].split()[3:])
print "0x%s -> %s -> %s" % (fingerprint, name, guess_uid); print "0x%s -> %s -> %s" % (fingerprint, name, guess_uid)
# FIXME: make me optionally non-interactive # FIXME: make me optionally non-interactive
# FIXME: default to the guessed ID # FIXME: default to the guessed ID
uid = None; uid = None
while not uid: while not uid:
uid = utils.our_raw_input("Map to which UID ? "); uid = utils.our_raw_input("Map to which UID ? ")
Attrs = l.search_s(LDAPDn,ldap.SCOPE_ONELEVEL,"(uid=%s)" % (uid), ["cn","mn","sn"]) Attrs = l.search_s(LDAPDn,ldap.SCOPE_ONELEVEL,"(uid=%s)" % (uid), ["cn","mn","sn"])
if not Attrs: if not Attrs:
print "That UID doesn't exist in LDAP!" print "That UID doesn't exist in LDAP!"
uid = None; uid = None
else: else:
entry = Attrs[0][1]; entry = Attrs[0][1]
name = " ".join([get_ldap_value(entry, "cn"), name = " ".join([get_ldap_value(entry, "cn"),
get_ldap_value(entry, "mn"), get_ldap_value(entry, "mn"),
get_ldap_value(entry, "sn")]); get_ldap_value(entry, "sn")])
prompt = "Map to %s - %s (y/N) ? " % (uid, name.replace(" "," ")); prompt = "Map to %s - %s (y/N) ? " % (uid, name.replace(" "," "))
yn = utils.our_raw_input(prompt).lower(); yn = utils.our_raw_input(prompt).lower()
if yn == "y": if yn == "y":
uid_id = db_access.get_or_set_uid_id(uid); uid_id = db_access.get_or_set_uid_id(uid)
projectB.query("UPDATE fingerprint SET uid = %s WHERE id = %s" % (uid_id, fingerprint_id)); projectB.query("UPDATE fingerprint SET uid = %s WHERE id = %s" % (uid_id, fingerprint_id))
print "Assigning %s to 0x%s." % (uid, fingerprint); print "Assigning %s to 0x%s." % (uid, fingerprint)
else: else:
uid = None; uid = None
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
############################################################ ############################################################
......
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
################################################################################ ################################################################################
import pg, pwd, sys; import pg, pwd, sys
import utils; import utils
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
################################################################################ ################################################################################
def usage (exit_code=0): def usage (exit_code=0):
...@@ -53,66 +53,66 @@ Sync PostgreSQL's users with system users. ...@@ -53,66 +53,66 @@ Sync PostgreSQL's users with system users.
################################################################################ ################################################################################
def main (): def main ():
global Cnf, projectB; global Cnf, projectB
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('n', "no-action", "Julia::Options::No-Action"), Arguments = [('n', "no-action", "Julia::Options::No-Action"),
('q', "quiet", "Julia::Options::Quiet"), ('q', "quiet", "Julia::Options::Quiet"),
('v', "verbose", "Julia::Options::Verbose"), ('v', "verbose", "Julia::Options::Verbose"),
('h', "help", "Julia::Options::Help")]; ('h', "help", "Julia::Options::Help")]
for i in [ "no-action", "quiet", "verbose", "help" ]: for i in [ "no-action", "quiet", "verbose", "help" ]:
if not Cnf.has_key("Julia::Options::%s" % (i)): if not Cnf.has_key("Julia::Options::%s" % (i)):
Cnf["Julia::Options::%s" % (i)] = ""; Cnf["Julia::Options::%s" % (i)] = ""
arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
Options = Cnf.SubTree("Julia::Options") Options = Cnf.SubTree("Julia::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
elif arguments: elif arguments:
utils.warn("julia takes no non-option arguments."); utils.warn("julia takes no non-option arguments.")
usage(1); usage(1)
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
valid_gid = int(Cnf.get("Julia::ValidGID","")); valid_gid = int(Cnf.get("Julia::ValidGID",""))
passwd_unames = {}; passwd_unames = {}
for entry in pwd.getpwall(): for entry in pwd.getpwall():
uname = entry[0]; uname = entry[0]
gid = entry[3]; gid = entry[3]
if valid_gid and gid != valid_gid: if valid_gid and gid != valid_gid:
if Options["Verbose"]: if Options["Verbose"]:
print "Skipping %s (GID %s != Valid GID %s)." % (uname, gid, valid_gid); print "Skipping %s (GID %s != Valid GID %s)." % (uname, gid, valid_gid)
continue; continue
passwd_unames[uname] = ""; passwd_unames[uname] = ""
postgres_unames = {}; postgres_unames = {}
q = projectB.query("SELECT usename FROM pg_user"); q = projectB.query("SELECT usename FROM pg_user")
ql = q.getresult(); ql = q.getresult()
for i in ql: for i in ql:
uname = i[0]; uname = i[0]
postgres_unames[uname] = ""; postgres_unames[uname] = ""
known_postgres_unames = {}; known_postgres_unames = {}
for i in Cnf.get("Julia::KnownPostgres","").split(","): for i in Cnf.get("Julia::KnownPostgres","").split(","):
uname = i.strip(); uname = i.strip()
known_postgres_unames[uname] = ""; known_postgres_unames[uname] = ""
keys = postgres_unames.keys() keys = postgres_unames.keys()
keys.sort(); keys.sort()
for uname in keys: for uname in keys:
if not passwd_unames.has_key(uname)and not known_postgres_unames.has_key(uname): if not passwd_unames.has_key(uname)and not known_postgres_unames.has_key(uname):
print "W: %s is in Postgres but not the passwd file or list of known Postgres users." % (uname); print "W: %s is in Postgres but not the passwd file or list of known Postgres users." % (uname)
keys = passwd_unames.keys() keys = passwd_unames.keys()
keys.sort(); keys.sort()
for uname in keys: for uname in keys:
if not postgres_unames.has_key(uname): if not postgres_unames.has_key(uname):
if not Options["Quiet"]: if not Options["Quiet"]:
print "Creating %s user in Postgres." % (uname); print "Creating %s user in Postgres." % (uname)
if not Options["No-Action"]: if not Options["No-Action"]:
q = projectB.query('CREATE USER "%s"' % (uname)); q = projectB.query('CREATE USER "%s"' % (uname))
####################################################################################### #######################################################################################
......
...@@ -20,14 +20,14 @@ ...@@ -20,14 +20,14 @@
################################################################################ ################################################################################
import pg, sys; import pg, sys
import utils, db_access; import utils, db_access
import apt_pkg; import apt_pkg
################################################################################ ################################################################################
Cnf = None; Cnf = None
projectB = None; projectB = None
################################################################################ ################################################################################
...@@ -42,136 +42,136 @@ Initalizes some tables in the projectB database based on the config file. ...@@ -42,136 +42,136 @@ Initalizes some tables in the projectB database based on the config file.
def get (c, i): def get (c, i):
if c.has_key(i): if c.has_key(i):
return "'%s'" % (c[i]); return "'%s'" % (c[i])
else: else:
return "NULL"; return "NULL"
def main (): def main ():
global Cnf, projectB; global Cnf, projectB
Cnf = utils.get_conf() Cnf = utils.get_conf()
Arguments = [('h',"help","Alyson::Options::Help")]; Arguments = [('h',"help","Alyson::Options::Help")]
for i in [ "help" ]: for i in [ "help" ]:
if not Cnf.has_key("Alyson::Options::%s" % (i)): if not Cnf.has_key("Alyson::Options::%s" % (i)):
Cnf["Alyson::Options::%s" % (i)] = ""; Cnf["Alyson::Options::%s" % (i)] = ""
apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv); apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
Options = Cnf.SubTree("Alyson::Options") Options = Cnf.SubTree("Alyson::Options")
if Options["Help"]: if Options["Help"]:
usage(); usage()
projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])); projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
db_access.init(Cnf, projectB); db_access.init(Cnf, projectB)
# archive # archive
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM archive"); projectB.query("DELETE FROM archive")
for name in Cnf.SubTree("Archive").List(): for name in Cnf.SubTree("Archive").List():
Archive = Cnf.SubTree("Archive::%s" % (name)); Archive = Cnf.SubTree("Archive::%s" % (name))
origin_server = get(Archive, "OriginServer"); origin_server = get(Archive, "OriginServer")
description = get(Archive, "Description"); description = get(Archive, "Description")
projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description)); projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# architecture # architecture
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM architecture"); projectB.query("DELETE FROM architecture")
for arch in Cnf.SubTree("Architectures").List(): for arch in Cnf.SubTree("Architectures").List():
description = Cnf["Architectures::%s" % (arch)]; description = Cnf["Architectures::%s" % (arch)]
projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description)); projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# component # component
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM component"); projectB.query("DELETE FROM component")
for name in Cnf.SubTree("Component").List(): for name in Cnf.SubTree("Component").List():
Component = Cnf.SubTree("Component::%s" % (name)); Component = Cnf.SubTree("Component::%s" % (name))
description = get(Component, "Description"); description = get(Component, "Description")
if Component.get("MeetsDFSG").lower() == "true": if Component.get("MeetsDFSG").lower() == "true":
meets_dfsg = "true"; meets_dfsg = "true"
else: else:
meets_dfsg = "false"; meets_dfsg = "false"
projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg)); projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# location # location
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM location"); projectB.query("DELETE FROM location")
for location in Cnf.SubTree("Location").List(): for location in Cnf.SubTree("Location").List():
Location = Cnf.SubTree("Location::%s" % (location)); Location = Cnf.SubTree("Location::%s" % (location))
archive_id = db_access.get_archive_id(Location["Archive"]); archive_id = db_access.get_archive_id(Location["Archive"])
type = Location.get("type"); type = Location.get("type")
if type == "legacy-mixed": if type == "legacy-mixed":
projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"])); projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"]))
elif type == "legacy" or type == "pool": elif type == "legacy" or type == "pool":
for component in Cnf.SubTree("Component").List(): for component in Cnf.SubTree("Component").List():
component_id = db_access.get_component_id(component); component_id = db_access.get_component_id(component)
projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" % projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
(location, component_id, archive_id, type)); (location, component_id, archive_id, type))
else: else:
utils.fubar("E: type '%s' not recognised in location %s." % (type, location)); utils.fubar("E: type '%s' not recognised in location %s." % (type, location))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# suite # suite
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM suite") projectB.query("DELETE FROM suite")
for suite in Cnf.SubTree("Suite").List(): for suite in Cnf.SubTree("Suite").List():
Suite = Cnf.SubTree("Suite::%s" %(suite)) Suite = Cnf.SubTree("Suite::%s" %(suite))
version = get(Suite, "Version"); version = get(Suite, "Version")
origin = get(Suite, "Origin"); origin = get(Suite, "Origin")
description = get(Suite, "Description"); description = get(Suite, "Description")
projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)" projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)"
% (suite.lower(), version, origin, description)); % (suite.lower(), version, origin, description))
for architecture in Cnf.ValueList("Suite::%s::Architectures" % (suite)): for architecture in Cnf.ValueList("Suite::%s::Architectures" % (suite)):
architecture_id = db_access.get_architecture_id (architecture); architecture_id = db_access.get_architecture_id (architecture)
if architecture_id < 0: if architecture_id < 0:
utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite)); utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite))
projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id)); projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# override_type # override_type
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM override_type"); projectB.query("DELETE FROM override_type")
for type in Cnf.ValueList("OverrideType"): for type in Cnf.ValueList("OverrideType"):
projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type)); projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# priority # priority
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM priority"); projectB.query("DELETE FROM priority")
for priority in Cnf.SubTree("Priority").List(): for priority in Cnf.SubTree("Priority").List():
projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)])); projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
# section # section
projectB.query("BEGIN WORK"); projectB.query("BEGIN WORK")
projectB.query("DELETE FROM section"); projectB.query("DELETE FROM section")
for component in Cnf.SubTree("Component").List(): for component in Cnf.SubTree("Component").List():
if Cnf["Natalie::ComponentPosition"] == "prefix": if Cnf["Natalie::ComponentPosition"] == "prefix":
suffix = ""; suffix = ""
if component != "main": if component != "main":
prefix = component + '/'; prefix = component + '/'
else: else:
prefix = ""; prefix = ""
else: else:
prefix = ""; prefix = ""
component = component.replace("non-US/", ""); component = component.replace("non-US/", "")
if component != "main": if component != "main":
suffix = '/' + component; suffix = '/' + component
else: else:
suffix = ""; suffix = ""
for section in Cnf.ValueList("Section"): for section in Cnf.ValueList("Section"):
projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix)); projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix))
projectB.query("COMMIT WORK"); projectB.query("COMMIT WORK")
################################################################################ ################################################################################
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -121,12 +121,12 @@ for f in functionality: ...@@ -121,12 +121,12 @@ for f in functionality:
def main(): def main():
if len(sys.argv) == 0: if len(sys.argv) == 0:
print "err, argc == 0? how is that possible?" print "err, argc == 0? how is that possible?"
sys.exit(1); sys.exit(1)
elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == "--help"): elif len(sys.argv) == 1 or (len(sys.argv) == 2 and sys.argv[1] == "--help"):
print "Sub commands:" print "Sub commands:"
for f in functionality: for f in functionality:
print " %-23s %s" % (f[0], f[1]) print " %-23s %s" % (f[0], f[1])
sys.exit(0); sys.exit(0)
else: else:
# should set PATH based on sys.argv[0] maybe # should set PATH based on sys.argv[0] maybe
# possibly should set names based on sys.argv[0] too # possibly should set names based on sys.argv[0] too
...@@ -148,10 +148,10 @@ def main(): ...@@ -148,10 +148,10 @@ def main():
cmdname = match[0] cmdname = match[0]
elif len(match) > 1: elif len(match) > 1:
print "ambiguous command: %s" % ", ".join(match) print "ambiguous command: %s" % ", ".join(match)
sys.exit(1); sys.exit(1)
else: else:
print "unknown command \"%s\"" % (cmdname) print "unknown command \"%s\"" % (cmdname)
sys.exit(1); sys.exit(1)
func = names[cmdname] func = names[cmdname]
x = __import__(func[0]) x = __import__(func[0])
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册