###
# mw - VCS-like nonsense for MediaWiki websites
-# Copyright (C) 2009 Ian Weller <ian@ianweller.org>
+# Copyright (C) 2010 Ian Weller <ian@ianweller.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
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()
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
# create cache/pages/
os.mkdir(os.path.join(self.location, 'cache', 'pages'), 0755)
- def pagedict_add(self, pagename, pageid):
+ def pagedict_add(self, pagename, pageid, currentrv):
fd = file(os.path.join(self.location, 'cache', 'pagedict'), 'r+')
pagedict = json.loads(fd.read())
- pagedict[pagename] = int(pageid)
+ pagedict[pagename] = {'id': int(pageid), 'currentrv': int(currentrv)}
fd.seek(0)
fd.write(json.dumps(pagedict))
fd.truncate()
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()]
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)]