[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Git][ftp-team/dak][master] 2 commits: dakweb: create /source/by_metadata



Title: GitLab

Joerg Jaspert pushed to branch master at Debian FTP Team / dak

Commits:

1 changed file:

Changes:

  • dakweb/queries/source.py
    ... ... @@ -10,7 +10,7 @@ from sqlalchemy import or_
    10 10
     import bottle
    
    11 11
     import json
    
    12 12
     
    
    13
    -from daklib.dbconn import DBConn, DBSource, Suite, DSCFile, PoolFile
    
    13
    +from daklib.dbconn import DBConn, DBSource, Suite, DSCFile, PoolFile, SourceMetadata, MetadataKey
    
    14 14
     from dakweb.webregister import QueryRegister
    
    15 15
     
    
    16 16
     
    
    ... ... @@ -203,3 +203,39 @@ def all_sources():
    203 203
         return json.dumps(ret)
    
    204 204
     
    
    205 205
     QueryRegister().register_path('/all_sources', all_sources)
    
    206
    +
    
    207
    +
    
    208
    +@bottle.route('/source/by_metadata/<key>')
    
    209
    +def source_by_metadata(key=None):
    
    210
    +    """
    
    211
    +
    
    212
    +    Finds all Debian source packages which have the specified metadata set.
    
    213
    +
    
    214
    +    E.g., to find out the Maintainer of all source packages, query
    
    215
    +    /source/by_metadata/Maintainer.
    
    216
    +
    
    217
    +    @type key: string
    
    218
    +    @param key: Metadata key to search for.
    
    219
    +
    
    220
    +    @rtype: dictionary
    
    221
    +    @return: A list of dictionaries of
    
    222
    +             - source
    
    223
    +             - metadata value
    
    224
    +    """
    
    225
    +
    
    226
    +    if not key:
    
    227
    +        return bottle.HTTPError(503, 'Metadata key not specified.')
    
    228
    +
    
    229
    +    s = DBConn().session()
    
    230
    +    q = s.query(DBSource.source, SourceMetadata.value)
    
    231
    +    q = q.join(SourceMetadata).join(MetadataKey)
    
    232
    +    q = q.filter(MetadataKey.key == key)
    
    233
    +    ret = []
    
    234
    +    for p in q:
    
    235
    +        ret.append({'source': p.source,
    
    236
    +                    'metadata_value': p.value})
    
    237
    +    s.close()
    
    238
    +
    
    239
    +    return json.dumps(ret)
    
    240
    +
    
    241
    +QueryRegister().register_path('/source/by_metadata', source_by_metadata)


  • Reply to: