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

Source Code for Module dakweb.queries.source

  1  """ Queries related to source packages 
  2   
  3  @contact: Debian FTPMaster <ftpmaster@debian.org> 
  4  @copyright: 2014  Mark Hymers <mhy@debian.org> 
  5  @copyright: 2014  Joerg Jaspert <joerg@debian.org> 
  6  @license: GNU General Public License version 2 or later 
  7  """ 
  8   
  9  from sqlalchemy import or_ 
 10  import bottle 
 11  import json 
 12   
 13  from daklib.dbconn import DBConn, DBSource, Suite, DSCFile, PoolFile, SourceMetadata, MetadataKey 
 14  from dakweb.webregister import QueryRegister 
15 16 17 @bottle.route('/dsc_in_suite/<suite>/<source>') 18 -def dsc_in_suite(suite=None, source=None):
19 """ 20 Find all dsc files for a given source package name in a given suite. 21 22 @since: December 2014 23 24 @type suite: string 25 @param suite: Name of the suite. 26 @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites. 27 28 @type source: string 29 @param source: Source package to query for. 30 31 @rtype: list of dictionaries 32 @return: Dictionaries made out of 33 - version 34 - component 35 - filename 36 - filesize 37 - sha256sum 38 """ 39 if suite is None: 40 return bottle.HTTPError(503, 'Suite not specified.') 41 if source is None: 42 return bottle.HTTPError(503, 'Source package not specified.') 43 44 s = DBConn().session() 45 q = s.query(DSCFile).join(PoolFile) 46 q = q.join(DBSource).join(Suite, DBSource.suites) 47 q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite)) 48 q = q.filter(DBSource.source == source) 49 q = q.filter(PoolFile.filename.endswith('.dsc')) 50 ret = [] 51 for p in q: 52 ret.append({'version': p.source.version, 53 'component': p.poolfile.component.component_name, 54 'filename': p.poolfile.filename, 55 'filesize': p.poolfile.filesize, 56 'sha256sum': p.poolfile.sha256sum}) 57 58 s.close() 59 60 bottle.response.content_type = 'application/json; charset=UTF-8' 61 return json.dumps(ret)
62 63 64 QueryRegister().register_path('/dsc_in_suite', dsc_in_suite)
65 66 67 @bottle.route('/file_in_archive/<filepattern:path>') 68 -def file_in_archive(filepattern=None):
69 """ 70 Check if a file pattern is known to the archive. Note that the 71 patterns are matched against the location of the files in the 72 pool, so for %tmux_2.3-1.dsc it will return t/tmux/tmux_2.3-1.dsc 73 as filename. 74 75 @since: October 2016 76 77 @type filepattern: string 78 79 @param filepattern: Pattern of the filenames to match. SQL LIKE 80 statement wildcard matches are supported, that 81 is % for zero, one or more characters, _ for a 82 single character match. 83 84 @rtype: list of dictionaries 85 @return: Dictionaries made out of 86 - filename 87 - sha256sum 88 - component 89 """ 90 if filepattern is None: 91 return bottle.HTTPError(503, 'Filepattern not specified.') 92 93 s = DBConn().session() 94 q = s.query(PoolFile) 95 q = q.filter(PoolFile.filename.like(filepattern)) 96 ret = [] 97 98 for p in q: 99 ret.append({'filename': p.filename, 100 'component': p.component.component_name, 101 'sha256sum': p.sha256sum}) 102 103 s.close() 104 105 bottle.response.content_type = 'application/json; charset=UTF-8' 106 return json.dumps(ret)
107 108 109 QueryRegister().register_path('/file_in_archive', file_in_archive)
110 111 112 @bottle.route('/sha256sum_in_archive/<sha256sum>') 113 -def sha256sum_in_archive(sha256sum=None):
114 """ 115 Check if files with matching sha256sums are known to the archive. 116 117 @since: June 2018 118 119 @type sha256sum: string 120 @param sha256sum: SHA256 sum of the file. 121 122 @rtype: list of dictionaries 123 @return: Dictionaries made out of 124 - filename 125 - sha256sum 126 - component 127 """ 128 if sha256sum is None: 129 return bottle.HTTPError(503, 'sha256sum not specified.') 130 131 s = DBConn().session() 132 q = s.query(PoolFile) 133 q = q.filter(PoolFile.sha256sum == sha256sum) 134 ret = [] 135 136 for p in q: 137 ret.append({'filename': p.filename, 138 'component': p.component.component_name, 139 'sha256sum': p.sha256sum}) 140 141 s.close() 142 143 bottle.response.content_type = 'application/json; charset=UTF-8' 144 return json.dumps(ret)
145 146 147 QueryRegister().register_path('/sha256sum_in_archive', sha256sum_in_archive)
148 149 150 @bottle.route('/sources_in_suite/<suite>') 151 -def sources_in_suite(suite=None):
152 """ 153 Returns all source packages and their versions in a given suite. 154 155 @since: December 2014 156 157 @type suite: string 158 @param suite: Name of the suite. 159 @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites. 160 161 @rtype: list of dictionaries 162 @return: Dictionaries made out of 163 - source 164 - version 165 """ 166 if suite is None: 167 return bottle.HTTPError(503, 'Suite not specified.') 168 169 s = DBConn().session() 170 q = s.query(DBSource).join(Suite, DBSource.suites) 171 q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite)) 172 ret = [] 173 for p in q: 174 ret.append({'source': p.source, 175 'version': p.version}) 176 177 s.close() 178 179 bottle.response.content_type = 'application/json; charset=UTF-8' 180 return json.dumps(ret)
181 182 183 QueryRegister().register_path('/sources_in_suite', sources_in_suite)
184 185 186 @bottle.route('/all_sources') 187 -def all_sources():
188 """ 189 Returns all source packages and their versions known to the archive 190 (this includes NEW). 191 192 @rtype: list of dictionaries 193 @return: Dictionaries made out of 194 - source 195 - version 196 """ 197 198 s = DBConn().session() 199 q = s.query(DBSource) 200 ret = [] 201 for p in q: 202 ret.append({'source': p.source, 203 'version': p.version}) 204 205 s.close() 206 207 bottle.response.content_type = 'application/json; charset=UTF-8' 208 return json.dumps(ret)
209 210 211 QueryRegister().register_path('/all_sources', all_sources)
212 213 214 @bottle.route('/source/by_metadata/<key>') 215 -def source_by_metadata(key=None):
216 """ 217 218 Finds all Debian source packages which have the specified metadata set. 219 220 E.g., to find out the Maintainer of all source packages, query 221 /source/by_metadata/Maintainer. 222 223 @type key: string 224 @param key: Metadata key to search for. 225 226 @rtype: dictionary 227 @return: A list of dictionaries of 228 - source 229 - metadata value 230 """ 231 232 if not key: 233 return bottle.HTTPError(503, 'Metadata key not specified.') 234 235 s = DBConn().session() 236 q = s.query(DBSource.source, SourceMetadata.value) 237 q = q.join(SourceMetadata).join(MetadataKey) 238 q = q.filter(MetadataKey.key == key) 239 ret = [] 240 for p in q: 241 ret.append({'source': p.source, 242 'metadata_value': p.value}) 243 s.close() 244 245 bottle.response.content_type = 'application/json; charset=UTF-8' 246 return json.dumps(ret)
247 248 249 QueryRegister().register_path('/source/by_metadata', source_by_metadata) 250