]> git.decadent.org.uk Git - dak.git/commitdiff
Initial pass at dak web server
authorMark Hymers <mhy@debian.org>
Wed, 20 Nov 2013 19:58:46 +0000 (19:58 +0000)
committerMark Hymers <mhy@debian.org>
Thu, 31 Jul 2014 21:18:06 +0000 (22:18 +0100)
Signed-off-by: Mark Hymers <mhy@debian.org>
dakweb/__init__.py [new file with mode: 0644]
dakweb/dakwebserver.py [new file with mode: 0755]
dakweb/queries/__init__.py [new file with mode: 0644]
dakweb/queries/source.py [new file with mode: 0644]
dakweb/webregister.py [new file with mode: 0644]

diff --git a/dakweb/__init__.py b/dakweb/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/dakweb/dakwebserver.py b/dakweb/dakwebserver.py
new file mode 100755 (executable)
index 0000000..181a2e7
--- /dev/null
@@ -0,0 +1,41 @@
+#!/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()
diff --git a/dakweb/queries/__init__.py b/dakweb/queries/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/dakweb/queries/source.py b/dakweb/queries/source.py
new file mode 100644 (file)
index 0000000..d65283f
--- /dev/null
@@ -0,0 +1,37 @@
+#!/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)
+
diff --git a/dakweb/webregister.py b/dakweb/webregister.py
new file mode 100644 (file)
index 0000000..d7e7990
--- /dev/null
@@ -0,0 +1,25 @@
+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']