本文整理汇总了Python中daklib.dbconn.DBConn.execute方法的典型用法代码示例。如果您正苦于以下问题:Python DBConn.execute方法的具体用法?Python DBConn.execute怎么用?Python DBConn.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类daklib.dbconn.DBConn
的用法示例。
在下文中一共展示了DBConn.execute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: per_arch_space_use
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def per_arch_space_use():
session = DBConn().session()
q = session.execute("""
SELECT a.arch_string as Architecture, sum(f.size) AS sum
FROM files f, binaries b, architecture a
WHERE a.id=b.architecture AND f.id=b.file
GROUP BY a.arch_string ORDER BY sum""").fetchall()
for j in q:
print("%-15.15s %s" % (j[0], j[1]))
print()
q = session.execute("SELECT sum(size) FROM files WHERE filename ~ '.(diff.gz|tar.gz|dsc)$'").fetchall()
print("%-15.15s %s" % ("Source", q[0][0]))
示例2: acl_export_per_source
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def acl_export_per_source(acl_name):
session = DBConn().session()
acl = session.query(ACL).filter_by(name=acl_name).one()
query = r"""
SELECT
f.fingerprint,
(SELECT COALESCE(u.name, '') || ' <' || u.uid || '>'
FROM uid u
JOIN fingerprint f2 ON u.id = f2.uid
WHERE f2.id = f.id) AS name,
STRING_AGG(
a.source
|| COALESCE(' (' || (SELECT fingerprint FROM fingerprint WHERE id = a.created_by_id) || ')', ''),
E',\n ' ORDER BY a.source)
FROM acl_per_source a
JOIN fingerprint f ON a.fingerprint_id = f.id
LEFT JOIN uid u ON f.uid = u.id
WHERE a.acl_id = :acl_id
GROUP BY f.id, f.fingerprint
ORDER BY name
"""
for row in session.execute(query, {'acl_id': acl.id}):
print("Fingerprint:", row[0])
print("Uid:", row[1])
print("Allow:", row[2])
print()
session.rollback()
session.close()
示例3: generate_translations
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def generate_translations(suite_id, component_id):
global _translations_query
from daklib.filewriter import TranslationFileWriter
from daklib.dbconn import DBConn, Suite, Component
from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
session = DBConn().session()
suite = session.query(Suite).get(suite_id)
component = session.query(Component).get(component_id)
writer_args = {
'archive': suite.archive.path,
'suite': suite.suite_name,
'component': component.component_name,
'language': 'en',
}
if suite.i18n_compression is not None:
writer_args['compression'] = suite.i18n_compression
writer = TranslationFileWriter(**writer_args)
output = writer.open()
r = session.execute(_translations_query, {"suite": suite_id, "component": component_id})
for (stanza,) in r:
print >>output, stanza
writer.close()
message = ["generate-translations", suite.suite_name, component.component_name]
session.rollback()
return (PROC_STATUS_SUCCESS, message)
示例4: generate_sources
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def generate_sources(suite_id, component_id):
global _sources_query
from daklib.filewriter import SourcesFileWriter
from daklib.dbconn import Component, DBConn, OverrideType, Suite
from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
session = DBConn().session()
dsc_type = session.query(OverrideType).filter_by(overridetype='dsc').one().overridetype_id
suite = session.query(Suite).get(suite_id)
component = session.query(Component).get(component_id)
overridesuite_id = suite.get_overridesuite().suite_id
writer_args = {
'archive': suite.archive.path,
'suite': suite.suite_name,
'component': component.component_name
}
if suite.indices_compression is not None:
writer_args['compression'] = suite.indices_compression
writer = SourcesFileWriter(**writer_args)
output = writer.open()
# run query and write Sources
r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "component_name": component.component_name, "dsc_type": dsc_type, "overridesuite": overridesuite_id})
for (stanza,) in r:
print >>output, stanza
print >>output, ""
writer.close()
message = ["generate sources", suite.suite_name, component.component_name]
session.rollback()
return (PROC_STATUS_SUCCESS, message)
示例5: table_row
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
global row_number
trclass = "sid"
session = DBConn().session()
for dist in distribution:
if dist == "experimental":
trclass = "exp"
query = '''SELECT source
FROM source_suite
WHERE source = :source
AND suite_name IN ('unstable', 'experimental')'''
if not session.execute(query, {'source': source}).rowcount:
trclass += " sourceNEW"
session.commit()
if row_number % 2 != 0:
print("<tr class=\"%s even\">" % (trclass))
else:
print("<tr class=\"%s odd\">" % (trclass))
if "sourceNEW" in trclass:
print("<td class=\"package\">%s</td>" % (source))
else:
print("<td class=\"package\"><a href=\"https://tracker.debian.org/pkg/%(source)s\">%(source)s</a></td>" % {'source': source})
print("<td class=\"version\">")
for vers in version.split():
print("<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers)))
print("</td>")
print("<td class=\"arch\">%s</td>" % (arch))
print("<td class=\"distribution\">")
for dist in distribution:
print("%s<br/>" % (dist))
print("</td>")
print("<td class=\"age\"><abbr title=\"%s\">%s</abbr></td>" % (
datetime.datetime.utcfromtimestamp(int(time.time()) - last_mod).strftime('%a, %d %b %Y %T UTC'),
time_pp(last_mod),
))
(name, mail) = maint.split(":", 1)
print("<td class=\"upload-data\">")
print("<span class=\"maintainer\">Maintainer: <a href=\"https://qa.debian.org/developer.php?login=%s\">%s</a></span><br/>" % (utils.html_escape(mail), utils.html_escape(name)))
(name, mail) = changedby.split(":", 1)
print("<span class=\"changed-by\">Changed-By: <a href=\"https://qa.debian.org/developer.php?login=%s\">%s</a></span><br/>" % (utils.html_escape(mail), utils.html_escape(name)))
if sponsor:
print("<span class=\"sponsor\">Sponsor: <a href=\"https://qa.debian.org/developer.php?login=%s\">%s</a>@debian.org</span><br/>" % (utils.html_escape(sponsor), utils.html_escape(sponsor)))
print("<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint))
print("</td>")
print("<td class=\"closes\">")
for close in closes:
print("<a href=\"https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close)))
print("</td></tr>")
row_number += 1
示例6: generate_packages
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def generate_packages(suite_id, component_id, architecture_id, type_name):
global _packages_query
from daklib.filewriter import PackagesFileWriter
from daklib.dbconn import Architecture, Component, DBConn, OverrideType, Suite
from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
session = DBConn().session()
arch_all_id = session.query(Architecture).filter_by(arch_string='all').one().arch_id
type_id = session.query(OverrideType).filter_by(overridetype=type_name).one().overridetype_id
suite = session.query(Suite).get(suite_id)
component = session.query(Component).get(component_id)
architecture = session.query(Architecture).get(architecture_id)
overridesuite_id = suite.get_overridesuite().suite_id
include_long_description = suite.include_long_description
# We currently filter out the "Tag" line. They are set by external
# overrides and NOT by the maintainer. And actually having it set by
# maintainer means we output it twice at the moment -> which breaks
# dselect.
metadata_skip = ["Section", "Priority", "Tag"]
if include_long_description:
metadata_skip.append("Description-md5")
writer_args = {
'archive': suite.archive.path,
'suite': suite.suite_name,
'component': component.component_name,
'architecture': architecture.arch_string,
'debtype': type_name
}
if suite.indices_compression is not None:
writer_args['compression'] = suite.indices_compression
writer = PackagesFileWriter(**writer_args)
output = writer.open()
r = session.execute(_packages_query, {"archive_id": suite.archive.archive_id,
"suite": suite_id, "component": component_id, 'component_name': component.component_name,
"arch": architecture_id, "type_id": type_id, "type_name": type_name, "arch_all": arch_all_id,
"overridesuite": overridesuite_id, "metadata_skip": metadata_skip,
"include_long_description": 'true' if include_long_description else 'false'})
for (stanza,) in r:
print >>output, stanza
print >>output, ""
writer.close()
message = ["generate-packages", suite.suite_name, component.component_name, architecture.arch_string]
session.rollback()
return (PROC_STATUS_SUCCESS, message)
示例7: acl_allow
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def acl_allow(acl_name, fingerprint, sources):
tbl = DBConn().tbl_acl_per_source
session = DBConn().session()
acl_id = session.query(ACL).filter_by(name=acl_name).one().id
fingerprint_id = session.query(Fingerprint).filter_by(fingerprint=fingerprint).one().fingerprint_id
# TODO: check that fpr is in ACL
data = [
{
'acl_id': acl_id,
'fingerprint_id': fingerprint_id,
'source': source,
'reason': 'set by {} via CLI'.format(os.environ.get('USER', '(unknown)')),
}
for source in sources
]
session.execute(tbl.insert(), data)
session.commit()
示例8: acl_deny
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def acl_deny(acl_name, fingerprint, sources):
tbl = DBConn().tbl_acl_per_source
session = DBConn().session()
acl_id = session.query(ACL).filter_by(name=acl_name).one().id
fingerprint_id = session.query(Fingerprint).filter_by(fingerprint=fingerprint).one().fingerprint_id
# TODO: check that fpr is in ACL
for source in sources:
result = session.execute(tbl.delete().where(tbl.c.acl_id == acl_id).where(tbl.c.fingerprint_id == fingerprint_id).where(tbl.c.source == source))
if result.rowcount < 1:
print("W: Tried to deny uploads of '{}', but was not allowed before.".format(source))
session.commit()
示例9: get_provides
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def get_provides(suite):
provides = set()
session = DBConn().session()
query = '''SELECT DISTINCT value
FROM binaries_metadata m
JOIN bin_associations b
ON b.bin = m.bin_id
WHERE key_id = (
SELECT key_id
FROM metadata_keys
WHERE key = 'Provides' )
AND b.suite = (
SELECT id
FROM suite
WHERE suite_name = '%(suite)s'
OR codename = '%(suite)s')''' % \
{'suite': suite}
for p in session.execute(query):
for e in p:
for i in e.split(','):
provides.add(i.strip())
session.close()
return provides
示例10: number_of_packages
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def number_of_packages():
arches = {}
arch_ids = {}
suites = {}
suite_ids = {}
d = {}
session = DBConn().session()
# Build up suite mapping
for i in session.query(Suite).all():
suites[i.suite_id] = i.suite_name
suite_ids[i.suite_name] = i.suite_id
# Build up architecture mapping
for i in session.query(Architecture).all():
arches[i.arch_id] = i.arch_string
arch_ids[i.arch_string] = i.arch_id
# Pre-create the dictionary
for suite_id in suites.keys():
d[suite_id] = {}
for arch_id in arches.keys():
d[suite_id][arch_id] = 0
# Get the raw data for binaries
# Simultate 'GROUP by suite, architecture' with a dictionary
# XXX: Why don't we just get the DB to do this?
for i in session.execute("""SELECT suite, architecture, COUNT(suite)
FROM bin_associations
LEFT JOIN binaries ON bin = binaries.id
GROUP BY suite, architecture""").fetchall():
d[i[0]][i[1]] = i[2]
# Get the raw data for source
arch_id = arch_ids["source"]
for i in session.execute('SELECT suite, COUNT(suite) FROM src_associations GROUP BY suite').fetchall():
(suite_id, count) = i
d[suite_id][arch_id] = d[suite_id][arch_id] + count
## Print the results
# Setup
suite_list = suites.values()
suite_id_list = []
suite_arches = {}
for suite in suite_list:
suite_id = suite_ids[suite]
suite_arches[suite_id] = {}
for arch in get_suite_architectures(suite):
suite_arches[suite_id][arch.arch_string] = ""
suite_id_list.append(suite_id)
output_list = [output_format(i) for i in suite_list]
longest_suite = longest(output_list)
arch_list = arches.values()
arch_list.sort()
longest_arch = longest(arch_list)
# Header
output = (" " * longest_arch) + " |"
for suite in output_list:
output = output + suite.center(longest_suite) + " |"
output = output + "\n" + (len(output) * "-") + "\n"
# per-arch data
arch_list = arches.values()
arch_list.sort()
longest_arch = longest(arch_list)
for arch in arch_list:
arch_id = arch_ids[arch]
output = output + arch.center(longest_arch) + " |"
for suite_id in suite_id_list:
if arch in suite_arches[suite_id]:
count = "%d" % d[suite_id][arch_id]
else:
count = "-"
output = output + count.rjust(longest_suite) + " |"
output = output + "\n"
print(output)
示例11: main
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def main():
from daklib.config import Config
from daklib import daklog
cnf = Config()
Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
('a','archive','Generate-Packages-Sources::Options::Archive','HasArg'),
('s',"suite","Generate-Packages-Sources::Options::Suite"),
('f',"force","Generate-Packages-Sources::Options::Force"),
('o','option','','ArbItem')]
suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
try:
Options = cnf.subtree("Generate-Packages-Sources::Options")
except KeyError:
Options = {}
if Options.has_key("Help"):
usage()
from daklib.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED
pool = DakProcessPool()
logger = daklog.Logger('generate-packages-sources2')
from daklib.dbconn import Component, DBConn, get_suite, Suite, Archive
session = DBConn().session()
session.execute("SELECT add_missing_description_md5()")
session.commit()
if Options.has_key("Suite"):
suites = []
for s in suite_names:
suite = get_suite(s.lower(), session)
if suite:
suites.append(suite)
else:
print "I: Cannot find suite %s" % s
logger.log(['Cannot find suite %s' % s])
else:
query = session.query(Suite).filter(Suite.untouchable == False)
if 'Archive' in Options:
query = query.join(Suite.archive).filter(Archive.archive_name==Options['Archive'])
suites = query.all()
force = Options.has_key("Force") and Options["Force"]
def parse_results(message):
# Split out into (code, msg)
code, msg = message
if code == PROC_STATUS_SUCCESS:
logger.log([msg])
elif code == PROC_STATUS_SIGNALRAISED:
logger.log(['E: Subprocess recieved signal ', msg])
else:
logger.log(['E: ', msg])
for s in suites:
component_ids = [ c.component_id for c in s.components ]
if s.untouchable and not force:
import daklib.utils
daklib.utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
for c in component_ids:
pool.apply_async(generate_sources, [s.suite_id, c], callback=parse_results)
if not s.include_long_description:
pool.apply_async(generate_translations, [s.suite_id, c], callback=parse_results)
for a in s.architectures:
if a == 'source':
continue
pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'deb'], callback=parse_results)
pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'udeb'], callback=parse_results)
pool.close()
pool.join()
# this script doesn't change the database
session.close()
logger.close()
sys.exit(pool.overall_status())
示例12: list_packages
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import execute [as 别名]
def list_packages(packages, suites=None, components=None, architectures=None, binary_types=None,
source_and_binary=False, regex=False,
format=None, highest=None):
session = DBConn().session()
try:
t = DBConn().view_package_list
comparison_operator = "~" if regex else "="
where = sql.false()
for package in packages:
where = where | t.c.package.op(comparison_operator)(package)
if source_and_binary:
where = where | t.c.source.op(comparison_operator)(package)
if suites is not None:
where = where & (t.c.suite.in_(suites) | t.c.codename.in_(suites))
if components is not None:
where = where & t.c.component.in_(components)
if architectures is not None:
where = where & t.c.architecture.in_(architectures)
if binary_types is not None:
where = where & t.c.type.in_(binary_types)
if format is None:
c_architectures = daksql.string_agg(t.c.architecture, ', ', order_by=[t.c.architecture_is_source.desc(), t.c.architecture])
query = sql.select([t.c.package, t.c.version, t.c.display_suite, c_architectures]) \
.where(where) \
.group_by(t.c.package, t.c.version, t.c.display_suite) \
.order_by(t.c.package, t.c.version, t.c.display_suite)
result = session.execute(query).fetchall()
if len(result) == 0:
raise StopIteration
lengths = {
'package': max(10, max(len(row[t.c.package]) for row in result)),
'version': max(13, max(len(row[t.c.version]) for row in result)),
'suite': max(10, max(len(row[t.c.display_suite]) for row in result))
}
format = "{0:{lengths[package]}} | {1:{lengths[version]}} | {2:{lengths[suite]}} | {3}"
for row in result:
yield format.format(row[t.c.package], row[t.c.version], row[t.c.display_suite], row[c_architectures], lengths=lengths)
elif format in ('control-suite', 'heidi'):
query = sql.select([t.c.package, t.c.version, t.c.architecture]).where(where)
result = session.execute(query)
for row in result:
yield "{0} {1} {2}".format(row[t.c.package], row[t.c.version], row[t.c.architecture])
elif format == "python":
c_architectures = daksql.string_agg(t.c.architecture, ',', order_by=[t.c.architecture_is_source.desc(), t.c.architecture])
query = sql.select([t.c.package,
t.c.version,
t.c.display_suite,
c_architectures,
t.c.source,
t.c.source_version,
t.c.component]) \
.where(where) \
.group_by(t.c.package,
t.c.version,
t.c.display_suite,
t.c.source,
t.c.component,
t.c.source_version)
result = session.execute(query).fetchall()
if len(result) == 0:
raise StopIteration
val = lambda: defaultdict(val)
ret = val()
for row in result:
ret[row[t.c.package]] \
[row[t.c.display_suite]] \
[row[t.c.version]]={'component': row[t.c.component],
'architectures': row[c_architectures].split(','),
'source': row[t.c.source],
'source_version': row[t.c.source_version]
}
yield ret
return
else:
raise ValueError("Unknown output format requested.")
if highest is not None:
query = sql.select([t.c.package, sql.func.max(t.c.version)]).where(where) \
.group_by(t.c.package).order_by(t.c.package)
result = session.execute(query)
yield ""
for row in result:
yield "{0} ({1} {2})".format(row[0], highest, row[1])
finally:
session.close()