Handle revs that don't have content
[mw] / src / mw / metadir.py
index 67e0b0950a58b95c20cf8b11542c0a4346e1234c..f02422330b0edd816687b354de146ec1ebd3eb78 100644 (file)
@@ -20,9 +20,10 @@ import ConfigParser
 import json
 import os
 import sys
-import time
+
 
 class Metadir(object):
+
     def __init__(self):
         self.me = os.path.basename(sys.argv[0])
         root = os.getcwd()
@@ -30,7 +31,7 @@ class Metadir(object):
             if '.mw' in os.listdir(root):
                 self.root = root
                 break
-            (head, tail) = os.path.split(root)
+            head = os.path.split(root)[0]
             if head == root:
                 self.root = os.getcwd()
                 break
@@ -97,16 +98,18 @@ class Metadir(object):
             pagedata = json.loads(pagedata_raw)
         rvid = int(rv['revid'])
         pagedata[rvid] = {
-                'user': rv['user'], 'timestamp': rv['timestamp'],
-                'content': rv['*'],
+                'user': rv['user'], 'timestamp': rv['timestamp']
         }
+        if '*' in rv.keys():
+            pagedata[rvid]['content'] = rv['*']
         fd.seek(0)
         fd.write(json.dumps(pagedata))
         fd.truncate()
         fd.close()
 
     def pages_get_rv_list(self, pageid):
-        pagefile = os.path.join(self.location, 'cache', 'pages', str(pageid))
+        pagefile = os.path.join(self.location, 'cache', 'pages',
+                                str(pageid['id']))
         fd = file(pagefile, 'r')
         pagedata = json.loads(fd.read())
         rvs = [int(x) for x in pagedata.keys()]
@@ -114,7 +117,8 @@ class Metadir(object):
         return rvs
 
     def pages_get_rv(self, pageid, rvid):
-        pagefile = os.path.join(self.location, 'cache', 'pages', str(pageid))
+        pagefile = os.path.join(self.location, 'cache', 'pages',
+                                str(pageid['id']))
         fd = file(pagefile, 'r')
         pagedata = json.loads(fd.read())
         return pagedata[str(rvid)]

Benjamin Mako Hill || Want to submit a patch?