Add ancestors support to HTTP storage
authorW. Trevor King <wking@drexel.edu>
Mon, 18 Jan 2010 19:05:59 +0000 (14:05 -0500)
committerW. Trevor King <wking@drexel.edu>
Mon, 18 Jan 2010 19:05:59 +0000 (14:05 -0500)
libbe/command/serve.py
libbe/storage/http.py

index 5dbd2b415ad527d2b383d4301178b56cf166bf5a..c4669003755524b3ad899f60a600690da21cfa13 100644 (file)
@@ -66,7 +66,9 @@ class BERequestHandler (server.BaseHTTPRequestHandler):
         data = self.parse_query(query)
 
         try:
-            if path == ['children']:
+            if path == ['ancestors']:
+                content,ctype = self.handle_ancestors(data)
+            elif path == ['children']:
                 content,ctype = self.handle_children(data)
             elif len(path) > 1 and path[0] == 'get':
                 content,ctype = self.handle_get('/'.join(path[1:]), data)
@@ -180,6 +182,21 @@ class BERequestHandler (server.BaseHTTPRequestHandler):
         self.send_response(200)
         return (None,None)
 
+    def handle_ancestors(self, data):
+        if not 'id' in data:
+            self.send_error(406, 'Missing query key id')
+            raise _HandlerError()
+        elif data['id'] == 'None':
+            data['id'] = None
+        id = data['id']
+        if not 'revision' in data or data['revision'] == 'None':
+            data['revision'] = None
+        revision = data['revision']
+        content = '\n'.join(self.s.ancestors(id, revision))
+        ctype = 'application/octet-stream'
+        self.send_response(200)
+        return content,ctype
+
     def handle_children(self, data):
         if not 'id' in data:
             self.send_error(406, 'Missing query key id')
index 0792b1ef749b47923bd42c7d59271b08754129d9..f7b031662e3ebdfa54055b8da32bd3eed954bdf0 100644 (file)
@@ -142,6 +142,13 @@ class HTTP (base.VersionedStorage):
             url, get=False,
             data_dict={'id':id, 'recursive':True})
 
+    def _ancestors(self, id=None, revision=None):
+        url = urlparse.urljoin(self.repo, 'ancestors')
+        page,final_url,info = get_post_url(
+            url, get=True,
+            data_dict={'id':id, 'revision':revision})
+        return page.strip('\n').splitlines()
+
     def _children(self, id=None, revision=None):
         url = urlparse.urljoin(self.repo, 'children')
         page,final_url,info = get_post_url(