本文整理汇总了Python中daklib.dbconn.DBConn.close方法的典型用法代码示例。如果您正苦于以下问题:Python DBConn.close方法的具体用法?Python DBConn.close怎么用?Python DBConn.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类daklib.dbconn.DBConn
的用法示例。
在下文中一共展示了DBConn.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: suites
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
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: binary_by_metadata
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
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)
示例3: acl_export_per_source
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [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()
示例4: source_by_metadata
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
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: sources_in_suite
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
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)
示例6: sha256sum_in_archive
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
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)
示例7: binary_metadata_keys
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
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)
示例8: dsc_in_suite
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
def dsc_in_suite(suite=None, source=None):
"""
Find all dsc files for a given source package name 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.
@type source: string
@param source: Source package to query for.
@rtype: list of dictionaries
@return: Dictionaries made out of
- version
- component
- filename
- filesize
- sha256sum
"""
if suite is None:
return bottle.HTTPError(503, 'Suite not specified.')
if source is None:
return bottle.HTTPError(503, 'Source package not specified.')
s = DBConn().session()
q = s.query(DSCFile).join(PoolFile)
q = q.join(DBSource).join(Suite, DBSource.suites)
q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite))
q = q.filter(DBSource.source == source)
q = q.filter(PoolFile.filename.endswith('.dsc'))
ret = []
for p in q:
ret.append({'version': p.source.version,
'component': p.poolfile.component.component_name,
'filename': p.poolfile.filename,
'filesize': p.poolfile.filesize,
'sha256sum': p.poolfile.sha256sum})
s.close()
bottle.response.content_type = 'application/json; charset=UTF-8'
return json.dumps(ret)
示例9: archives
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
def archives():
"""
Give information about all known archives (sets of suites)
@rtype: dict
return: list of dictionaries
"""
s = DBConn().session()
q = s.query(Archive)
q = q.order_by(Archive.archive_name)
ret = []
for a in q:
ret.append({'name': a.archive_name,
'suites': [x.suite_name for x in a.suites]})
s.close()
return json.dumps(ret)
示例10: all_sources
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
def all_sources():
"""
Returns all source packages and their versions known to the archive
(this includes NEW).
@rtype: list of dictionaries
@return: Dictionaries made out of
- source
- version
"""
s = DBConn().session()
q = s.query(DBSource)
ret = []
for p in q:
ret.append({'source': p.source,
'version': p.version})
s.close()
return json.dumps(ret)
示例11: file_in_archive
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
def file_in_archive(filepattern=None):
"""
Check if a file pattern is known to the archive. Note that the
patterns are matched against the location of the files in the
pool, so for %tmux_2.3-1.dsc it will return t/tmux/tmux_2.3-1.dsc
as filename.
@since: October 2016
@type filepattern: string
@param filepattern: Pattern of the filenames to match. SQL LIKE
statement wildcard matches are supported, that
is % for zero, one or more characters, _ for a
single character match.
@rtype: list of dictionaries
@return: Dictionaries made out of
- filename
- sha256sum
- component
"""
if filepattern is None:
return bottle.HTTPError(503, 'Filepattern not specified.')
s = DBConn().session()
q = s.query(PoolFile)
q = q.filter(PoolFile.filename.like(filepattern))
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)
示例12: get_provides
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [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
示例13: main
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [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())
示例14: list_packages
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [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()
示例15: read_number
# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import close [as 别名]
def read_number():
session = DBConn().session()
result = session.query("foo").from_statement("select 7 as foo").scalar()
sleep(0.1)
session.close()
return result