]> git.donarmstrong.com Git - dak.git/blob - dakweb/webregister.py
Initial pass at dak web server
[dak.git] / dakweb / webregister.py
1 class QueryRegister(object):
2     __shared_state = {}
3
4     def __init__(self, *args, **kwargs):
5         self.__dict__ = self.__shared_state
6
7         if not getattr(self, 'initialised', False):
8             self.initialised = True
9
10             # Dictionary of query paths to help mappings
11             self.queries = {}
12
13     def register_path(self, path, func):
14         self.queries[path] = func.__doc__
15
16     def get_paths(self):
17         return sorted(self.queries.keys())
18
19     def get_path_help(self, path):
20         # We always register with the leading /
21         if not path.startswith('/'):
22             path = '/' + path
23         return self.queries.get(path, 'Unknown path')
24
25 __all__ = ['QueryRegister']