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(
19 title = document.name,
25 def delete(self, name, author, comment):
26 self.vstorage.delete_page(name, author, comment)
29 return list(self.vstorage.all_pages())
31 def history(self, title):
32 return list(self.vstorage.page_history(title))
34 def _info(self, name):
35 return self.vstorage.page_meta(name)
38 class Document(object):
39 META_REGEX = re.compile(r'\s*<!--\s(.*?)-->', re.DOTALL | re.MULTILINE)
41 def __init__(self, storage, **kwargs):
42 self.storage = storage
43 for attr, value in kwargs.iteritems():
44 setattr(self, attr, value)
48 return self.storage._info(self.name)[0]
49 except DocumentNotFound:
54 return re.sub(self.META_REGEX, '', self.text, 1)
59 m = re.match(self.META_REGEX, self.text)
61 for line in m.group(1).split('\n'):
63 k, v = line.split(':', 1)
64 result[k.strip()] = v.strip()
71 return DocumentStorage(settings.REPOSITORY_PATH)