Package dakweb :: Package queries :: Module binary
[hide private]
[frames] | no frames]

Source Code for Module dakweb.queries.binary

 1  """Debian binary package related queries. 
 2   
 3  @copyright: 2017 Michael Stapelberg <stapelberg@debian.org> 
 4  @copyright: 2017 Joerg Jaspert <joerg@debian.org> 
 5  @license: GNU General Public License version 2 or later 
 6  """ 
 7   
 8  import bottle 
 9  import json 
10   
11  from daklib.dbconn import DBConn, DBBinary, DBSource, SourceMetadata, MetadataKey 
12  from dakweb.webregister import QueryRegister 
13 14 15 @bottle.route('/binary/metadata_keys/') 16 -def binary_metadata_keys():
17 """ 18 List all possible metadata keys 19 20 @rtype: dictionary 21 @return: A list of metadata keys 22 """ 23 s = DBConn().session() 24 q = s.query(MetadataKey) 25 ret = [] 26 for p in q: 27 ret.append(p.key) 28 29 s.close() 30 31 bottle.response.content_type = 'application/json; charset=UTF-8' 32 return json.dumps(ret)
33 34 35 QueryRegister().register_path('/metadata_keys', binary_metadata_keys)
36 37 38 @bottle.route('/binary/by_metadata/<key>') 39 -def binary_by_metadata(key=None):
40 """ 41 42 Finds all Debian binary packages which have the specified metadata set 43 in their correspondig source package. 44 45 E.g., to find out the Go import paths of all Debian Go packages, query 46 /binary/by_metadata/Go-Import-Path. 47 48 @type key: string 49 @param key: Metadata key of the source package to search for. 50 51 @rtype: dictionary 52 @return: A list of dictionaries of 53 - binary 54 - source 55 - metadata value 56 """ 57 58 if not key: 59 return bottle.HTTPError(503, 'Metadata key not specified.') 60 61 s = DBConn().session() 62 q = s.query(DBBinary.package, DBSource.source, SourceMetadata.value) 63 q = q.join(DBSource).join(SourceMetadata).join(MetadataKey) 64 q = q.filter(MetadataKey.key == key) 65 q = q.group_by(DBBinary.package, DBSource.source, SourceMetadata.value) 66 ret = [] 67 for p in q: 68 ret.append({'binary': p.package, 69 'source': p.source, 70 'metadata_value': p.value}) 71 s.close() 72 73 bottle.response.content_type = 'application/json; charset=UTF-8' 74 return json.dumps(ret)
75 76 77 QueryRegister().register_path('/binary/by_metadata', binary_by_metadata) 78