本文整理汇总了Python中daklib.config.Config.find方法的典型用法代码示例。如果您正苦于以下问题:Python Config.find方法的具体用法?Python Config.find怎么用?Python Config.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类daklib.config.Config
的用法示例。
在下文中一共展示了Config.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_byhash
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def clean_byhash(now_date, session):
cnf = Config()
suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
Logger.log(["Cleaning out unused by-hash files..."])
q = session.execute("""
DELETE FROM hashfile h
USING suite s, archive a
WHERE s.id = h.suite_id
AND a.id = s.archive_id
AND h.unreferenced + a.stayofexecution < CURRENT_TIMESTAMP
RETURNING a.path, s.suite_name, h.path""")
count = q.rowcount
if not Options["No-Action"]:
for base, suite, path in q:
filename = os.path.join(base, 'dists', suite, suite_suffix, path)
try:
os.unlink(filename)
except OSError as exc:
if exc.errno != errno.ENOENT:
raise
Logger.log(['database referred to non-existing file', filename])
else:
Logger.log(['delete hashfile', suite, path])
session.commit()
if count > 0:
Logger.log(["total", count])
示例2: check
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def check(self, upload):
cnf = Config()
future_cutoff = time.time() + cnf.find_i('Dinstall::FutureTimeTravelGrace', 24*3600)
past_cutoff = time.mktime(time.strptime(cnf.find('Dinstall::PastCutoffYear', '1975'), '%Y'))
class TarTime(object):
def __init__(self):
self.future_files = dict()
self.past_files = dict()
def callback(self, member, data):
if member.mtime > future_cutoff:
self.future_files[member.name] = member.mtime
elif member.mtime < past_cutoff:
self.past_files[member.name] = member.mtime
def format_reason(filename, direction, files):
reason = "{0}: has {1} file(s) with a timestamp too far in the {2}:\n".format(filename, len(files), direction)
for fn, ts in files.iteritems():
reason += " {0} ({1})".format(fn, time.ctime(ts))
return reason
for binary in upload.changes.binaries:
filename = binary.hashed_file.filename
path = os.path.join(upload.directory, filename)
deb = apt_inst.DebFile(path)
tar = TarTime()
deb.control.go(tar.callback)
if tar.future_files:
raise Reject(format_reason(filename, 'future', tar.future_files))
if tar.past_files:
raise Reject(format_reason(filename, 'past', tar.past_files))
示例3: suite_path
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def suite_path(self):
"""
Absolute path to the suite-specific files.
"""
cnf = Config()
suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
return os.path.join(self.suite.archive.path, 'dists',
self.suite.suite_name, suite_suffix)
示例4: suite_release_path
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def suite_release_path(self):
"""
Absolute path where Release files are physically stored.
This should be a path that sorts after the dists/ directory.
"""
cnf = Config()
suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
return os.path.join(self.suite.archive.path, 'zzz-dists',
self.suite.suite_name, suite_suffix)
示例5: main
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def main():
cnf = Config()
Arguments = [
("h", "help", "Override::Options::Help"),
("c", "check", "Override::Options::Check"),
("d", "done", "Override::Options::Done", "HasArg"),
("n", "no-action", "Override::Options::No-Action"),
("s", "suite", "Override::Options::Suite", "HasArg"),
]
for i in ["help", "check", "no-action"]:
if not cnf.has_key("Override::Options::%s" % (i)):
cnf["Override::Options::%s" % (i)] = ""
if not cnf.has_key("Override::Options::Suite"):
cnf["Override::Options::Suite"] = "unstable"
arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
Options = cnf.subtree("Override::Options")
if Options["Help"]:
usage()
session = DBConn().session()
if not arguments:
utils.fubar("package name is a required argument.")
package = arguments.pop(0)
suite_name = Options["Suite"]
if arguments and len(arguments) > 2:
utils.fubar("Too many arguments")
suite = get_suite(suite_name, session)
if suite is None:
utils.fubar("Unknown suite '{0}'".format(suite_name))
if arguments and len(arguments) == 1:
# Determine if the argument is a priority or a section...
arg = arguments.pop()
q = session.execute(
"""
SELECT ( SELECT COUNT(*) FROM section WHERE section = :arg ) AS secs,
( SELECT COUNT(*) FROM priority WHERE priority = :arg ) AS prios
""",
{"arg": arg},
)
r = q.fetchall()
if r[0][0] == 1:
arguments = (arg, ".")
elif r[0][1] == 1:
arguments = (".", arg)
else:
utils.fubar("%s is not a valid section or priority" % (arg))
# Retrieve current section/priority...
oldsection, oldsourcesection, oldpriority = None, None, None
for packagetype in ["source", "binary"]:
eqdsc = "!="
if packagetype == "source":
eqdsc = "="
q = session.execute(
"""
SELECT priority.priority AS prio, section.section AS sect, override_type.type AS type
FROM override, priority, section, suite, override_type
WHERE override.priority = priority.id
AND override.type = override_type.id
AND override_type.type %s 'dsc'
AND override.section = section.id
AND override.package = :package
AND override.suite = suite.id
AND suite.suite_name = :suite_name
"""
% (eqdsc),
{"package": package, "suite_name": suite_name},
)
if q.rowcount == 0:
continue
if q.rowcount > 1:
utils.fubar("%s is ambiguous. Matches %d packages" % (package, q.rowcount))
r = q.fetchone()
if packagetype == "binary":
oldsection = r[1]
oldpriority = r[0]
else:
oldsourcesection = r[1]
oldpriority = "source"
if not oldpriority and not oldsourcesection:
utils.fubar("Unable to find package %s" % (package))
if oldsection and oldsourcesection and oldsection != oldsourcesection:
# When setting overrides, both source & binary will become the same section
utils.warn("Source is in section '%s' instead of '%s'" % (oldsourcesection, oldsection))
if not oldsection:
oldsection = oldsourcesection
if not arguments:
#.........这里部分代码省略.........
示例6: main
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def main ():
global Options
cnf = Config()
Arguments = [('h',"help","Rm::Options::Help"),
('a',"architecture","Rm::Options::Architecture", "HasArg"),
('b',"binary", "Rm::Options::Binary"),
('B',"binary-only", "Rm::Options::Binary-Only"),
('c',"component", "Rm::Options::Component", "HasArg"),
('C',"carbon-copy", "Rm::Options::Carbon-Copy", "HasArg"), # Bugs to Cc
('d',"done","Rm::Options::Done", "HasArg"), # Bugs fixed
('D',"do-close","Rm::Options::Do-Close"),
('R',"rdep-check", "Rm::Options::Rdep-Check"),
('m',"reason", "Rm::Options::Reason", "HasArg"), # Hysterical raisins; -m is old-dinstall option for rejection reason
('n',"no-action","Rm::Options::No-Action"),
('p',"partial", "Rm::Options::Partial"),
('s',"suite","Rm::Options::Suite", "HasArg"),
('S',"source-only", "Rm::Options::Source-Only"),
]
for i in [ "architecture", "binary", "binary-only", "carbon-copy", "component",
"done", "help", "no-action", "partial", "rdep-check", "reason",
"source-only", "Do-Close" ]:
if not cnf.has_key("Rm::Options::%s" % (i)):
cnf["Rm::Options::%s" % (i)] = ""
if not cnf.has_key("Rm::Options::Suite"):
cnf["Rm::Options::Suite"] = "unstable"
arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
Options = cnf.subtree("Rm::Options")
if Options["Help"]:
usage()
session = DBConn().session()
# Sanity check options
if not arguments:
utils.fubar("need at least one package name as an argument.")
if Options["Architecture"] and Options["Source-Only"]:
utils.fubar("can't use -a/--architecture and -S/--source-only options simultaneously.")
if ((Options["Binary"] and Options["Source-Only"])
or (Options["Binary"] and Options["Binary-Only"])
or (Options["Binary-Only"] and Options["Source-Only"])):
utils.fubar("Only one of -b/--binary, -B/--binary-only and -S/--source-only can be used.")
if Options.has_key("Carbon-Copy") and not Options.has_key("Done"):
utils.fubar("can't use -C/--carbon-copy without also using -d/--done option.")
if Options["Architecture"] and not Options["Partial"]:
utils.warn("-a/--architecture implies -p/--partial.")
Options["Partial"] = "true"
if Options["Do-Close"] and not Options["Done"]:
utils.fubar("No.")
if (Options["Do-Close"]
and (Options["Binary"] or Options["Binary-Only"] or Options["Source-Only"])):
utils.fubar("No.")
# Force the admin to tell someone if we're not doing a 'dak
# cruft-report' inspired removal (or closing a bug, which counts
# as telling someone).
if not Options["No-Action"] and not Options["Carbon-Copy"] \
and not Options["Done"] and Options["Reason"].find("[auto-cruft]") == -1:
utils.fubar("Need a -C/--carbon-copy if not closing a bug and not doing a cruft removal.")
# Process -C/--carbon-copy
#
# Accept 3 types of arguments (space separated):
# 1) a number - assumed to be a bug number, i.e. [email protected]
# 2) the keyword 'package' - cc's [email protected] for every argument
# 3) contains a '@' - assumed to be an email address, used unmofidied
#
carbon_copy = []
for copy_to in utils.split_args(Options.get("Carbon-Copy")):
if copy_to.isdigit():
if cnf.has_key("Dinstall::BugServer"):
carbon_copy.append(copy_to + "@" + cnf["Dinstall::BugServer"])
else:
utils.fubar("Asked to send mail to #%s in BTS but Dinstall::BugServer is not configured" % copy_to)
elif copy_to == 'package':
for package in arguments:
if cnf.has_key("Dinstall::PackagesServer"):
carbon_copy.append(package + "@" + cnf["Dinstall::PackagesServer"])
if cnf.has_key("Dinstall::TrackingServer"):
carbon_copy.append(package + "@" + cnf["Dinstall::TrackingServer"])
elif '@' in copy_to:
carbon_copy.append(copy_to)
else:
utils.fubar("Invalid -C/--carbon-copy argument '%s'; not a bug number, 'package' or email address." % (copy_to))
if Options["Binary"]:
field = "b.package"
else:
field = "s.source"
con_packages = "AND %s IN (%s)" % (field, ", ".join([ repr(i) for i in arguments ]))
(con_suites, con_architectures, con_components, check_source) = \
utils.parse_args(Options)
# Additional suite checks
suite_ids_list = []
#.........这里部分代码省略.........
示例7: generate_release_files
# 需要导入模块: from daklib.config import Config [as 别名]
# 或者: from daklib.config.Config import find [as 别名]
def generate_release_files(self):
"""
Generate Release files for the given suite
@type suite: string
@param suite: Suite name
"""
suite = self.suite
session = object_session(suite)
architectures = get_suite_architectures(suite.suite_name, skipall=True, skipsrc=True, session=session)
# Attribs contains a tuple of field names and the database names to use to
# fill them in
attribs = ( ('Origin', 'origin'),
('Label', 'label'),
('Suite', 'release_suite_output'),
('Version', 'version'),
('Codename', 'codename'),
('Changelogs', 'changelog_url'),
)
# A "Sub" Release file has slightly different fields
subattribs = ( ('Archive', 'suite_name'),
('Origin', 'origin'),
('Label', 'label'),
('Version', 'version') )
# Boolean stuff. If we find it true in database, write out "yes" into the release file
boolattrs = ( ('NotAutomatic', 'notautomatic'),
('ButAutomaticUpgrades', 'butautomaticupgrades') )
cnf = Config()
suite_suffix = cnf.find("Dinstall::SuiteSuffix", "")
outfile = os.path.join(suite.archive.path, 'dists', suite.suite_name, suite_suffix, "Release")
out = open(outfile + ".new", "w")
for key, dbfield in attribs:
# Hack to skip NULL Version fields as we used to do this
# We should probably just always ignore anything which is None
if key in ("Version", "Changelogs") and getattr(suite, dbfield) is None:
continue
out.write("%s: %s\n" % (key, getattr(suite, dbfield)))
out.write("Date: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()))))
if suite.validtime:
validtime=float(suite.validtime)
out.write("Valid-Until: %s\n" % (time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime(time.time()+validtime))))
for key, dbfield in boolattrs:
if getattr(suite, dbfield, False):
out.write("%s: yes\n" % (key))
out.write("Architectures: %s\n" % (" ".join([a.arch_string for a in architectures])))
components = [ c.component_name for c in suite.components ]
out.write("Components: %s\n" % (" ".join(components)))
# For exact compatibility with old g-r, write out Description here instead
# of with the rest of the DB fields above
if getattr(suite, 'description') is not None:
out.write("Description: %s\n" % suite.description)
for comp in components:
for dirpath, dirnames, filenames in os.walk(os.path.join(suite.archive.path, "dists", suite.suite_name, suite_suffix, comp), topdown=True):
if not re_gensubrelease.match(dirpath):
continue
subfile = os.path.join(dirpath, "Release")
subrel = open(subfile + '.new', "w")
for key, dbfield in subattribs:
if getattr(suite, dbfield) is not None:
subrel.write("%s: %s\n" % (key, getattr(suite, dbfield)))
for key, dbfield in boolattrs:
if getattr(suite, dbfield, False):
subrel.write("%s: yes\n" % (key))
subrel.write("Component: %s%s\n" % (suite_suffix, comp))
# Urgh, but until we have all the suite/component/arch stuff in the DB,
# this'll have to do
arch = os.path.split(dirpath)[-1]
if arch.startswith('binary-'):
arch = arch[7:]
subrel.write("Architecture: %s\n" % (arch))
subrel.close()
os.rename(subfile + '.new', subfile)
# Now that we have done the groundwork, we want to get off and add the files with
# their checksums to the main Release file
#.........这里部分代码省略.........