--- /dev/null
+#!/usr/bin/python
+
+# Main script to run the dakweb server and also
+# to provide the list_paths and path_help functions
+
+from sqlalchemy import or_
+import bottle
+from daklib.dbconn import DBConn, DBSource, Suite, DSCFile, PoolFile
+import json
+
+from dakweb.webregister import QueryRegister
+
+@bottle.route('/')
+def root_path():
+ """Returns a useless welcome message"""
+ return json.dumps('Use the /list_paths path to list all available paths')
+QueryRegister().register_path('/', root_path)
+
+@bottle.route('/list_paths')
+def list_paths():
+ """Returns a list of available paths"""
+ return json.dumps(QueryRegister().get_paths())
+QueryRegister().register_path('/list_paths', list_paths)
+
+@bottle.route('/path_help/<path>')
+def path_help(path=None):
+
+ if path is None:
+ return bottle.HTTPError(503, 'Path not specified.')
+
+ return json.dumps(QueryRegister().get_path_help(path))
+QueryRegister().register_path('/path_help', list_paths)
+
+# Import our other methods
+from queries.source import *
+
+print "Connecting"
+# Set up our initial database connection
+d = DBConn()
+#bottle.run(host='localhost', port=8765)
+bottle.run()
--- /dev/null
+#!/usr/bin/python
+
+from sqlalchemy import or_
+import bottle
+import json
+
+from daklib.dbconn import DBConn, DBSource, Suite, DSCFile, PoolFile
+from dakweb.webregister import QueryRegister
+
+@bottle.route('/dsc_in_suite/<suite>/<source>')
+def dsc_in_suite(suite=None, source=None):
+ """
+ Find all dsc files for a given source package name in a given suite.
+
+ suite and source must be supplied
+ """
+ if suite is None:
+ return bottle.HTTPError(503, 'Suite not specified.')
+ if source is None:
+ return bottle.HTTPError(503, 'Source package not specified.')
+
+ s = DBConn().session()
+ q = s.query(DSCFile).join(PoolFile)
+ q = q.join(DBSource).join(Suite, DBSource.suites)
+ q = q.filter(or_(Suite.suite_name == suite, Suite.codename == suite))
+ q = q.filter(DBSource.source == source)
+ q = q.filter(PoolFile.filename.endswith('.dsc'))
+ ret = []
+ for p in q:
+ ret.append({'version': p.source.version,
+ 'component': p.poolfile.component.component_name,
+ 'filename': p.poolfile.filename})
+
+ return json.dumps(ret)
+
+QueryRegister().register_path('/dsc_in_suite', dsc_in_suite)
+
--- /dev/null
+class QueryRegister(object):
+ __shared_state = {}
+
+ def __init__(self, *args, **kwargs):
+ self.__dict__ = self.__shared_state
+
+ if not getattr(self, 'initialised', False):
+ self.initialised = True
+
+ # Dictionary of query paths to help mappings
+ self.queries = {}
+
+ def register_path(self, path, func):
+ self.queries[path] = func.__doc__
+
+ def get_paths(self):
+ return sorted(self.queries.keys())
+
+ def get_path_help(self, path):
+ # We always register with the leading /
+ if not path.startswith('/'):
+ path = '/' + path
+ return self.queries.get(path, 'Unknown path')
+
+__all__ = ['QueryRegister']