当前位置: 首页>>代码示例>>Python>>正文


Python DBConn.query方法代码示例

本文整理汇总了Python中daklib.dbconn.DBConn.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBConn.query方法的具体用法?Python DBConn.query怎么用?Python DBConn.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在daklib.dbconn.DBConn的用法示例。


在下文中一共展示了DBConn.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_translations

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:abhi11,项目名称:dak,代码行数:32,代码来源:generate_packages_sources2.py

示例2: generate_sources

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:abhi11,项目名称:dak,代码行数:37,代码来源:generate_packages_sources2.py

示例3: generate_packages

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:abhi11,项目名称:dak,代码行数:53,代码来源:generate_packages_sources2.py

示例4: sources_in_suite

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:Debian,项目名称:dak,代码行数:31,代码来源:source.py

示例5: sha256sum_in_archive

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:Debian,项目名称:dak,代码行数:34,代码来源:source.py

示例6: source_by_metadata

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:Debian,项目名称:dak,代码行数:33,代码来源:source.py

示例7: main

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [as 别名]
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()
开发者ID:abhi11,项目名称:dak,代码行数:62,代码来源:queue_report.py

示例8: binary_by_metadata

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:Debian,项目名称:dak,代码行数:37,代码来源:binary.py

示例9: acl_export_per_source

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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()
开发者ID:Debian,项目名称:dak,代码行数:33,代码来源:acl.py

示例10: acl_deny

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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()
开发者ID:Debian,项目名称:dak,代码行数:18,代码来源:acl.py

示例11: suites

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:Debian,项目名称:dak,代码行数:37,代码来源:suite.py

示例12: table_row

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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"

    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
开发者ID:luther07,项目名称:dak,代码行数:57,代码来源:queue_report.py

示例13: acl_allow

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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()
开发者ID:Debian,项目名称:dak,代码行数:25,代码来源:acl.py

示例14: acl_set_fingerprints

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [as 别名]
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()
开发者ID:Debian,项目名称:dak,代码行数:19,代码来源:acl.py

示例15: binary_metadata_keys

# 需要导入模块: from daklib.dbconn import DBConn [as 别名]
# 或者: from daklib.dbconn.DBConn import query [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)
开发者ID:Debian,项目名称:dak,代码行数:19,代码来源:binary.py


注:本文中的daklib.dbconn.DBConn.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。