本文整理汇总了Python中daklib.dbconn.DBConn类的典型用法代码示例。如果您正苦于以下问题:Python DBConn类的具体用法?Python DBConn怎么用?Python DBConn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBConn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: suites
def suites():
"""
Give information about all known suites.
@maps: name maps to Suite: in the release file
@maps: codename maps to Codename: in the release file.
@maps: dakname is an internal name and should not be relied upon.
@rtype: list of dictionaries
@return: Dictionaries made out of
- name
- codename
- dakname
- archive
- architectures
- components
"""
s = DBConn().session()
q = s.query(Suite)
q = q.order_by(Suite.suite_name)
ret = []
for p in q:
ret.append({'name': p.release_suite_output,
'codename': p.codename,
'dakname': p.suite_name,
'archive': p.archive.archive_name,
'architectures': [x.arch_string for x in p.architectures],
'components': [x.component_name for x in p.components]})
s.close()
bottle.response.content_type = 'application/json; charset=UTF-8'
return json.dumps(ret)
示例2: sources_in_suite
def sources_in_suite(suite=None):
"""
Returns all source packages and their versions in a given suite.
@since: December 2014
@type suite: string
@param suite: Name of the suite.
@see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
@rtype: list of dictionaries
@return: Dictionaries made out of
- source
- version
"""
if suite is None:
return bottle.HTTPError(503, 'Suite not specified.')
s = DBConn().session()
q = s.query(DBSource).join(Suite, DBSource.suites)
q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite))
ret = []
for p in q:
ret.append({'source': p.source,
'version': p.version})
s.close()
return json.dumps(ret)
示例3: export_external_signature_requests
def export_external_signature_requests(session, path):
tbl_arch = DBConn().tbl_architecture
tbl_ba = DBConn().tbl_bin_associations
tbl_bin = DBConn().tbl_binaries
tbl_esr = DBConn().tbl_external_signature_requests
tbl_suite = DBConn().tbl_suite
query = sql.select([tbl_bin.c.package, tbl_suite.c.suite_name, tbl_suite.c.codename, tbl_arch.c.arch_string, sql.func.max(tbl_bin.c.version)]) \
.select_from(tbl_esr.join(tbl_suite).join(tbl_ba, tbl_ba.c.id == tbl_esr.c.association_id).join(tbl_bin).join(tbl_arch)) \
.group_by(tbl_bin.c.package, tbl_suite.c.suite_name, tbl_suite.c.codename, tbl_arch.c.arch_string)
requests = session.execute(query)
data = {
'packages': [
{
'package': row[0],
'suite': row[1],
'codename': row[2],
'architecture': row[3],
'version': row[4],
}
for row in requests],
}
with open(path, 'w') as fh:
json.dump(data, fh, indent=2)
示例4: source_by_metadata
def source_by_metadata(key=None):
"""
Finds all Debian source packages which have the specified metadata set.
E.g., to find out the Maintainer of all source packages, query
/source/by_metadata/Maintainer.
@type key: string
@param key: Metadata key to search for.
@rtype: dictionary
@return: A list of dictionaries of
- source
- metadata value
"""
if not key:
return bottle.HTTPError(503, 'Metadata key not specified.')
s = DBConn().session()
q = s.query(DBSource.source, SourceMetadata.value)
q = q.join(SourceMetadata).join(MetadataKey)
q = q.filter(MetadataKey.key == key)
ret = []
for p in q:
ret.append({'source': p.source,
'metadata_value': p.value})
s.close()
return json.dumps(ret)
示例5: sha256sum_in_archive
def sha256sum_in_archive(sha256sum=None):
"""
Check if files with matching sha256sums are known to the archive.
@since: June 2018
@type sha256sum: string
@param sha256sum: SHA256 sum of the file.
@rtype: list of dictionaries
@return: Dictionaries made out of
- filename
- sha256sum
- component
"""
if sha256sum is None:
return bottle.HTTPError(503, 'sha256sum not specified.')
s = DBConn().session()
q = s.query(PoolFile)
q = q.filter(PoolFile.sha256sum == sha256sum)
ret = []
for p in q:
ret.append({'filename': p.filename,
'component': p.component.component_name,
'sha256sum': p.sha256sum})
s.close()
bottle.response.content_type = 'application/json; charset=UTF-8'
return json.dumps(ret)
示例6: main
def main():
global Cnf
Cnf = utils.get_conf()
Arguments = [('h',"help","Queue-Report::Options::Help"),
('n',"new","Queue-Report::Options::New"),
('8','822',"Queue-Report::Options::822"),
('s',"sort","Queue-Report::Options::Sort", "HasArg"),
('a',"age","Queue-Report::Options::Age", "HasArg"),
('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
('d',"directories","Queue-Report::Options::Directories", "HasArg")]
for i in [ "help" ]:
if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
Cnf["Queue-Report::Options::%s" % (i)] = ""
apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
Options = Cnf.subtree("Queue-Report::Options")
if Options["Help"]:
usage()
if Cnf.has_key("Queue-Report::Options::New"):
header()
queue_names = []
if Cnf.has_key("Queue-Report::Options::Directories"):
for i in Cnf["Queue-Report::Options::Directories"].split(","):
queue_names.append(i)
elif Cnf.has_key("Queue-Report::Directories"):
queue_names = Cnf.value_list("Queue-Report::Directories")
else:
queue_names = [ "byhand", "new" ]
if Cnf.has_key("Queue-Report::Options::Rrd"):
rrd_dir = Cnf["Queue-Report::Options::Rrd"]
elif Cnf.has_key("Dir::Rrd"):
rrd_dir = Cnf["Dir::Rrd"]
else:
rrd_dir = None
f = None
if Cnf.has_key("Queue-Report::Options::822"):
# Open the report file
f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
session = DBConn().session()
for queue_name in queue_names:
queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).first()
if queue is not None:
process_queue(queue, f, rrd_dir)
else:
utils.warn("Cannot find queue %s" % queue_name)
if Cnf.has_key("Queue-Report::Options::822"):
f.close()
if Cnf.has_key("Queue-Report::Options::New"):
footer()
示例7: binary_by_metadata
def binary_by_metadata(key=None):
"""
Finds all Debian binary packages which have the specified metadata set.
E.g., to find out the Go import paths of all Debian Go packages, query
/binary/by_metadata/Go-Import-Path.
@type key: string
@param key: Metadata key to search for.
@rtype: dictionary
@return: A list of dictionaries of
- binary
- source
- metadata value
"""
if not key:
return bottle.HTTPError(503, 'Metadata key not specified.')
s = DBConn().session()
q = s.query(DBBinary.package, DBSource.source, SourceMetadata.value)
q = q.join(DBSource).join(SourceMetadata).join(MetadataKey)
q = q.filter(MetadataKey.key == key)
q = q.group_by(DBBinary.package, DBSource.source, SourceMetadata.value)
ret = []
for p in q:
ret.append({'binary': p.package,
'source': p.source,
'metadata_value': p.value})
s.close()
bottle.response.content_type = 'application/json; charset=UTF-8'
return json.dumps(ret)
示例8: table_row
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
示例9: table_row
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"
if not len(session.query(DBSource).filter_by(source = source).all()):
trclass += " binNEW"
session.commit()
if row_number % 2 != 0:
print "<tr class=\"%s even\">" % (trclass)
else:
print "<tr class=\"%s odd\">" % (trclass)
if "binNEW" in trclass:
print "<td class=\"package\">%s</td>" % (source)
else:
print "<td class=\"package\"><a href=\"http://packages.qa.debian.org/%(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\">%s</td>" % (last_mod)
(name, mail) = maint.split(":", 1)
print "<td class=\"upload-data\">"
print "<span class=\"maintainer\">Maintainer: <a href=\"http://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=\"http://qa.debian.org/developer.php?login=%s\">%s</a></span><br/>" % (utils.html_escape(mail), utils.html_escape(name))
if sponsor:
try:
(login, domain) = sponsor.split("@", 1)
print "<span class=\"sponsor\">Sponsor: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a>@debian.org</span><br/>" % (utils.html_escape(login), utils.html_escape(login))
except Exception as e:
pass
print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
print "</td>"
print "<td class=\"closes\">"
for close in closes:
print "<a href=\"http://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
示例10: per_arch_space_use
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]))
示例11: generate_packages
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)
示例12: acl_set_fingerprints
def acl_set_fingerprints(acl_name, entries):
session = DBConn().session()
acl = session.query(ACL).filter_by(name=acl_name).one()
acl.fingerprints.clear()
for entry in entries:
entry = entry.strip()
if entry.startswith('#') or len(entry) == 0:
continue
fps = get_fingerprint(entry, session)
if len(fps) == 0:
print("Unknown key for '{0}'".format(entry))
else:
acl.fingerprints.update(fps)
session.commit()
示例13: binary_metadata_keys
def binary_metadata_keys():
"""
List all possible metadata keys
@rtype: dictionary
@return: A list of metadata keys
"""
s = DBConn().session()
q = s.query(MetadataKey)
ret = []
for p in q:
ret.append(p.key)
s.close()
bottle.response.content_type = 'application/json; charset=UTF-8'
return json.dumps(ret)
示例14: acl_export_per_source
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()
示例15: generate_sources
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)