本文整理汇总了Python中daklib.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
def init (self):
cnf = Config()
arguments = [('h', "help", "Update-DB::Options::Help")]
for i in [ "help" ]:
if not cnf.has_key("Update-DB::Options::%s" % (i)):
cnf["Update-DB::Options::%s" % (i)] = ""
arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)
options = cnf.subtree("Update-DB::Options")
if options["Help"]:
self.usage()
elif arguments:
utils.warn("dak update-db takes no arguments.")
self.usage(exit_code=1)
try:
if os.path.isdir(cnf["Dir::Lock"]):
lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'dinstall.lock'), os.O_RDWR | os.O_CREAT)
fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
else:
utils.warn("Lock directory doesn't exist yet - not locking")
except IOError as e:
if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.")
self.update_db()
示例2: main
def main():
cnf = Config()
arguments = [('h',"help", "%s::%s" % (options_prefix,"Help")),
('q',"quiet", "%s::%s" % (options_prefix,"Quiet")),
('v',"verbose", "%s::%s" % (options_prefix,"Verbose")),
]
args = apt_pkg.parse_commandline(cnf.Cnf, arguments,sys.argv)
num_threads = 1
if len(args) > 0:
usage(1)
if cnf.has_key("%s::%s" % (options_prefix,"Help")):
usage(0)
level=logging.INFO
if cnf.has_key("%s::%s" % (options_prefix,"Quiet")):
level=logging.ERROR
elif cnf.has_key("%s::%s" % (options_prefix,"Verbose")):
level=logging.DEBUG
logging.basicConfig( level=level,
format='%(asctime)s %(levelname)s %(message)s',
stream = sys.stderr )
ImportNewFiles()
示例3: init
def init(self):
cnf = Config()
arguments = [('h', "help", "Update-DB::Options::Help"),
("y", "yes", "Update-DB::Options::Yes")]
for i in ["help"]:
key = "Update-DB::Options::%s" % i
if key not in cnf:
cnf[key] = ""
arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)
options = cnf.subtree("Update-DB::Options")
if options["Help"]:
self.usage()
elif arguments:
utils.warn("dak update-db takes no arguments.")
self.usage(exit_code=1)
try:
if os.path.isdir(cnf["Dir::Lock"]):
lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'daily.lock'), os.O_RDONLY | os.O_CREAT)
fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
else:
utils.warn("Lock directory doesn't exist yet - not locking")
except IOError as e:
if e.errno in (errno.EACCES, errno.EAGAIN):
utils.fubar("Couldn't obtain lock, looks like archive is doing something, try again later.")
self.update_db()
示例4: clean_byhash
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])
示例5: init
def init(session):
global cnf, Options
cnf = Config()
Arguments = [
("h", "help", "Show-New::Options::Help"),
("p", "html-path", "Show-New::HTMLPath", "HasArg"),
("q", "queue", "Show-New::Options::Queue", "HasArg"),
]
for i in ["help"]:
if not cnf.has_key("Show-New::Options::%s" % (i)):
cnf["Show-New::Options::%s" % (i)] = ""
changesnames = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
Options = cnf.subtree("Show-New::Options")
if Options["help"]:
usage()
queue_names = Options.find("Queue", "new").split(",")
uploads = (
session.query(PolicyQueueUpload)
.join(PolicyQueueUpload.policy_queue)
.filter(PolicyQueue.queue_name.in_(queue_names))
.join(PolicyQueueUpload.changes)
.order_by(DBChange.source)
)
if len(changesnames) > 0:
uploads = uploads.filter(DBChange.changesname.in_(changesnames))
return uploads
示例6: main
def main():
cnf = Config()
Arguments = [('h', "help", "External-Overrides::Options::Help"),
('f', 'force', 'External-Overrides::Options::Force')]
args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
try:
Options = cnf.subtree("External-Overrides::Options")
except KeyError:
Options = {}
if "Help" in Options:
usage()
force = False
if "Force" in Options and Options["Force"]:
force = True
logger = daklog.Logger('external-overrides')
command = args[0]
if command in ('import', 'i'):
external_overrides_import(args[1], args[2], args[3], sys.stdin, force)
elif command in ('copy', 'c'):
external_overrides_copy(args[1], args[2], force)
else:
print("E: Unknown commands.")
示例7: _do_bts_versiontracking
def _do_bts_versiontracking(self):
cnf = Config()
fs = self.transaction.fs
btsdir = cnf.get('Dir::BTSVersionTrack')
if btsdir is None or btsdir == '':
return
base = os.path.join(btsdir, self.changes.filename[:-8])
# version history
sourcedir = self.unpacked_source()
if sourcedir is not None:
fh = open(os.path.join(sourcedir, 'debian', 'changelog'), 'r')
versions = fs.create("{0}.versions".format(base), mode=0o644)
for line in fh.readlines():
if re_changelog_versions.match(line):
versions.write(line)
fh.close()
versions.close()
# binary -> source mapping
debinfo = fs.create("{0}.debinfo".format(base), mode=0o644)
for binary in self.changes.binaries:
control = binary.control
source_package, source_version = binary.source
line = " ".join([control['Package'], control['Version'], control['Architecture'], source_package, source_version])
print >>debinfo, line
debinfo.close()
示例8: main
def main():
global Options, Logger
cnf = Config()
session = DBConn().session()
Arguments = [('h', "help", "Archive-Dedup-Pool::Options::Help")]
apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
for i in ["help"]:
key = "Archive-Dedup-Pool::Options::%s" % i
if key not in cnf:
cnf[key] = ""
Options = cnf.subtree("Archive-Dedup-Pool::Options")
if Options["Help"]:
usage()
Logger = daklog.Logger("archive-dedup-pool")
dedup(session)
Logger.close()
示例9: action_sync_package
def action_sync_package(self, fingerprint, section, session):
cnf = Config()
allowed_keyrings = cnf.value_list('Command::Sync::AdminKeyrings')
if fingerprint.keyring.keyring_name not in allowed_keyrings:
raise CommandError('Key {0} is not allowed to sync Debian packages.'.format(fingerprint.fingerprint))
if 'Packages' not in section or 'Suite' not in section or 'Component' not in section:
raise CommandError('Invalid commands: Section is missing.')
packages_str = section['Packages']
suite = section['Suite']
component = section['Component']
if " " in packages_str:
packages = packages_str.split(" ")
else:
packages = [packages_str]
for pkg in packages:
p = subprocess.Popen(["sync-debian-package", "-i", suite, "staging", component, pkg], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()
if p.returncode is not 0:
self.result.append("Failed syncing: {0} from {1} ({2})".format(pkg, suite, component))
out_str = ""
if output[0] != None:
out_str = output[0]
if output[1] != None:
out_str += output[1]
self.result.append(" - Error: {0}".format(out_str))
else:
self.result.append("Synced package: {0} from {1} ({2})".format(pkg, suite, component))
示例10: sign_release_dir
def sign_release_dir(suite, dirname):
cnf = Config()
if cnf.has_key("Dinstall::SigningKeyring"):
keyring = "--secret-keyring \"%s\"" % cnf["Dinstall::SigningKeyring"]
if cnf.has_key("Dinstall::SigningPubKeyring"):
keyring += " --keyring \"%s\"" % cnf["Dinstall::SigningPubKeyring"]
arguments = "--no-options --batch --no-tty --armour --personal-digest-preferences=SHA256"
relname = os.path.join(dirname, 'Release')
dest = os.path.join(dirname, 'Release.gpg')
if os.path.exists(dest):
os.unlink(dest)
inlinedest = os.path.join(dirname, 'InRelease')
if os.path.exists(inlinedest):
os.unlink(inlinedest)
defkeyid=""
for keyid in suite.signingkeys or []:
defkeyid += "--local-user %s " % keyid
os.system("gpg %s %s %s --detach-sign <%s >>%s" %
(keyring, defkeyid, arguments, relname, dest))
os.system("gpg %s %s %s --clearsign <%s >>%s" %
(keyring, defkeyid, arguments, relname, inlinedest))
示例11: main
def main():
global Options, Logger
cnf = Config()
Arguments = [('h', "help", "Obsolete::Options::Help"),
('s', "suite", "Obsolete::Options::Suite", "HasArg"),
('n', "no-action", "Obsolete::Options::No-Action"),
('f', "force", "Obsolete::Options::Force")]
cnf['Obsolete::Options::Help'] = ''
cnf['Obsolete::Options::No-Action'] = ''
cnf['Obsolete::Options::Force'] = ''
apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
Options = cnf.subtree("Obsolete::Options")
if Options['Help']:
usage()
if 'Suite' not in Options:
query_suites = DBConn().session().query(Suite)
suites = [suite.suite_name for suite in query_suites.all()]
cnf['Obsolete::Options::Suite'] = ','.join(suites)
Logger = daklog.Logger("dominate")
session = DBConn().session()
for suite_name in utils.split_args(Options['Suite']):
suite = session.query(Suite).filter_by(suite_name = suite_name).one()
if not suite.untouchable or Options['Force']:
doDaDoDa(suite.suite_id, session)
if Options['No-Action']:
session.rollback()
else:
session.commit()
Logger.close()
示例12: do_update
def do_update(self):
"""
Add missing PrimaryMirror field to archive table
"""
print __doc__
try:
cnf = Config()
c = self.db.cursor()
c.execute("ALTER TABLE archive ADD COLUMN primary_mirror TEXT")
c.execute("SELECT id, name FROM archive")
query = "UPDATE archive SET primary_mirror = %s WHERE id = %s"
for a_id, a_name in c.fetchall():
if cnf.has_key('Archive::%s::PrimaryMirror' % a_name):
primloc = cnf['Archive::%s::PrimaryMirror' % a_name]
print "Setting archive %s PrimaryMirror to %s" % (a_name, primloc)
c.execute(query, [primloc, a_id])
c.execute("UPDATE config SET value = '63' WHERE name = 'db_revision'")
self.db.commit()
except psycopg2.ProgrammingError as msg:
self.db.rollback()
raise DBUpdateError('Unable to apply sick update 63, rollback issued. Error message : %s' % (str(msg)))
示例13: main
def main():
cnf = Config()
Arguments = [
('h', "help", "Copy-Installer::Options::Help"),
('s', "source", "Copy-Installer::Options::Source", "HasArg"),
('d', "destination", "Copy-Installer::Options::Destination", "HasArg"),
('n', "no-action", "Copy-Installer::Options::No-Action"),
]
for option in ["help", "source", "destination", "no-action"]:
key = "Copy-Installer::Options::%s" % option
if key not in cnf:
cnf[key] = ""
extra_arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
Options = cnf.subtree("Copy-Installer::Options")
if Options["Help"]:
usage()
if len(extra_arguments) != 1:
usage(1)
initializer = {"version": extra_arguments[0]}
if Options["Source"] != "":
initializer["source"] = Options["Source"]
if Options["Destination"] != "":
initializer["dest"] = Options["Destination"]
copier = InstallerCopier(**initializer)
print(copier.get_message())
if Options["No-Action"]:
print('Do nothing because --no-action has been set.')
else:
copier.do_copy()
print('Installer has been copied successfully.')
示例14: action_dm_migrate
def action_dm_migrate(self, fingerprint, section, session):
self._action_dm_admin_common(fingerprint, section, session)
cnf = Config()
acl_name = cnf.get('Command::DM::ACL', 'dm')
acl = session.query(ACL).filter_by(name=acl_name).one()
fpr_hash_from = section['From'].translate(None, ' ')
fpr_from = session.query(Fingerprint).filter_by(fingerprint=fpr_hash_from).first()
if fpr_from is None:
self.result.append('Unknown fingerprint (From): {0}\nNo action taken.'.format(fpr_hash_from))
return
fpr_hash_to = section['To'].translate(None, ' ')
fpr_to = session.query(Fingerprint).filter_by(fingerprint=fpr_hash_to).first()
if fpr_to is None:
self.result.append('Unknown fingerprint (To): {0}\nNo action taken.'.format(fpr_hash_to))
return
if fpr_to.keyring is None or fpr_to.keyring.keyring_name not in cnf.value_list('Command::DM::Keyrings'):
self.result.append('Key (To) {0} is not in DM keyring.\nNo action taken.'.format(fpr_to.fingerprint))
return
self.log.log(['dm-migrate', 'from={0}'.format(fpr_hash_from), 'to={0}'.format(fpr_hash_to)])
sources = []
for entry in session.query(ACLPerSource).filter_by(acl=acl, fingerprint=fpr_from):
self.log.log(['dm-migrate', 'from={0}'.format(fpr_hash_from), 'to={0}'.format(fpr_hash_to), 'source={0}'.format(entry.source)])
entry.fingerprint = fpr_to
sources.append(entry.source)
self.result.append('Migrated {0} to {1}.\n{2} acl entries changed: {3}'.format(fpr_hash_from, fpr_hash_to, len(sources), ", ".join(sources)))
session.commit()
示例15: sign_release_dir
def sign_release_dir(suite, dirname):
cnf = Config()
if cnf.has_key("Dinstall::SigningKeyring"):
keyring = "--secret-keyring \"%s\"" % cnf["Dinstall::SigningKeyring"]
if cnf.has_key("Dinstall::SigningPubKeyring"):
keyring += " --keyring \"%s\"" % cnf["Dinstall::SigningPubKeyring"]
arguments = "--no-options --batch --no-tty --armour"
relname = os.path.join(dirname, 'Release')
dest = os.path.join(dirname, 'Release.gpg')
if os.path.exists(dest):
os.unlink(dest)
inlinedest = os.path.join(dirname, 'InRelease')
if os.path.exists(inlinedest):
os.unlink(inlinedest)
# We can only use one key for inline signing so use the first one in
# the array for consistency
firstkey = True
for keyid in suite.signingkeys:
defkeyid = "--default-key %s" % keyid
os.system("gpg %s %s %s --detach-sign <%s >>%s" %
(keyring, defkeyid, arguments, relname, dest))
if firstkey:
os.system("gpg %s %s %s --clearsign <%s >>%s" %
(keyring, defkeyid, arguments, relname, inlinedest))
firstkey = False