3 from vstorage import DocumentNotFound
4 from wiki import settings
6 class DocumentStorage(object):
7 def __init__(self, path):
8 self.vstorage = vstorage.VersionedStorage(path)
10 def get(self, name, revision = None):
12 text = self.vstorage.page_text(name)
14 text = self.vstorage.revision_text(name, revision)
15 return Document(self, name = name, text = text)
17 def put(self, document, author, comment, parent):
18 self.vstorage.save_text(document.name, document.text, author, comment, parent)
20 def delete(self, name, author, comment):
21 self.vstorage.delete_page(name, author, comment)
24 return list(self.vstorage.all_pages())
26 def history(self, title):
27 return list(self.vstorage.page_history(title))
29 def _info(self, name):
30 return self.vstorage.page_meta(name)
33 class Document(object):
34 META_REGEX = re.compile(r'\s*<!--\s(.*?)-->', re.DOTALL | re.MULTILINE)
36 def __init__(self, storage, **kwargs):
37 self.storage = storage
38 for attr, value in kwargs.iteritems():
39 setattr(self, attr, value)
43 return self.storage._info(self.name)[0]
44 except DocumentNotFound:
49 return re.sub(self.META_REGEX, '', self.text, 1)
54 m = re.match(self.META_REGEX, self.text)
56 for line in m.group(1).split('\n'):
58 k, v = line.split(':', 1)
59 result[k.strip()] = v.strip()
65 # Every time somebody says "let's have a global variable", God kills a kitten.
66 storage = DocumentStorage(settings.REPOSITORY_PATH)