]> git.decadent.org.uk Git - dak.git/blob - dakweb/queries/source.py
Instead of doing our own (bad) help, simply use existing epydoc foo and redirect...
[dak.git] / dakweb / queries / source.py
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
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     return json.dumps(ret)
61
62 QueryRegister().register_path('/dsc_in_suite', dsc_in_suite)
63
64
65 @bottle.route('/sources_in_suite/<suite>')
66 def sources_in_suite(suite=None):
67     """
68     Returns all source packages and their versions in a given suite.
69
70     @since: December 2014
71
72     @type suite: string
73     @param suite: Name of the suite.
74     @see: L{I{suites}<dakweb.queries.suite.suites>} on how to receive a list of valid suites.
75
76     @rtype: list of dictionaries
77     @return: Dictionaries made out of
78              - source
79              - version
80     """
81     if suite is None:
82         return bottle.HTTPError(503, 'Suite not specified.')
83
84     s = DBConn().session()
85     q = s.query(DBSource).join(Suite, DBSource.suites)
86     q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite))
87     ret = []
88     for p in q:
89         ret.append({'source':    p.source,
90                     'version':   p.version})
91
92     s.close()
93
94     return json.dumps(ret)
95
96 QueryRegister().register_path('/sources_in_suite', sources_in_suite)
97
98
99 @bottle.route('/all_sources')
100 def all_sources():
101     """
102     Returns all source packages and their versions known to the archive
103     (this includes NEW).
104
105     @rtype: list of dictionaries
106     @return: Dictionaries made out of
107              - source
108              - version
109     """
110
111     s = DBConn().session()
112     q = s.query(DBSource)
113     ret = []
114     for p in q:
115         ret.append({'source':    p.source,
116                     'version':   p.version})
117
118     s.close()
119
120     return json.dumps(ret)
121
122 QueryRegister().register_path('/all_sources', all_sources)