Add .changed support to HTTP storage backend.
authorW. Trevor King <wking@drexel.edu>
Mon, 18 Jan 2010 19:22:11 +0000 (14:22 -0500)
committerW. Trevor King <wking@drexel.edu>
Mon, 18 Jan 2010 19:22:11 +0000 (14:22 -0500)
Also work around urlparse.parse_qs location in Python <= 2.5.

libbe/command/serve.py
libbe/storage/http.py

index c4669003755524b3ad899f60a600690da21cfa13..26be6c1a6c8316c1ed587c7e1b20e3baedce1793 100644 (file)
@@ -19,6 +19,13 @@ import posixpath
 import urllib
 import urlparse
 
+try:
+    # Python >= 2.6
+    from urlparse import parse_qs
+except ImportError:
+    # Python <= 2.5
+    from cgi import parse_qs
+
 import libbe
 import libbe.command
 import libbe.command.util
@@ -74,6 +81,8 @@ class BERequestHandler (server.BaseHTTPRequestHandler):
                 content,ctype = self.handle_get('/'.join(path[1:]), data)
             elif path == ['revision-id']:
                 content,ctype = self.handle_revision_id(data)
+            elif path == ['changed']:
+                content,ctype = self.handle_changed(data)
             elif path == ['version']:
                 content,ctype = self.handle_version(data)
             else:
@@ -263,6 +272,16 @@ class BERequestHandler (server.BaseHTTPRequestHandler):
         self.send_response(200)
         return content,ctype
 
+    def handle_changed(self, data):
+        if not 'revision' in data or data['revision'] == 'None':
+            data['revision'] = None
+        revision = data['revision']
+        add,mod,rem = self.s.changed(revision)
+        content = '\n\n'.join(['\n'.join(p) for p in (add,mod,rem)])
+        ctype = 'application/octet-stream'
+        self.send_response(200)
+        return content,ctype
+
     def handle_version(self, data):
         if not 'revision' in data or data['revision'] == 'None':
             data['revision'] = None
@@ -287,7 +306,7 @@ class BERequestHandler (server.BaseHTTPRequestHandler):
     def parse_query(self, query):
         if len(query) == 0:
             return {}
-        data = urlparse.parse_qs(
+        data = parse_qs(
             query, keep_blank_values=True, strict_parsing=True)
         for k,v in data.items():
             if len(v) == 1:
index f7b031662e3ebdfa54055b8da32bd3eed954bdf0..2de2affb2011b41f622f6f62668bc145cf73e061 100644 (file)
@@ -234,6 +234,15 @@ class HTTP (base.VersionedStorage):
             raise base.InvalidID(id)
         return page.rstrip('\n')
 
+    def changed(self, revision=None):
+        url = urlparse.urljoin(self.repo, 'changed')
+        page,final_url,info = get_post_url(
+            url, get=True,
+            data_dict={'revision':revision})
+        lines = page.strip('\n')
+        new,mod,rem = [p.splitlines() for p in page.split('\n\n')]
+        return (new, mod, rem)
+
     def check_storage_version(self):
         version = self.storage_version()
         if version != libbe.storage.STORAGE_VERSION: