3 from vstorage import DocumentNotFound
4 from wiki import settings
7 class DocumentStorage(object):
8 def __init__(self, path):
9 self.vstorage = vstorage.VersionedStorage(path)
11 def get(self, name, revision=None):
13 text = self.vstorage.page_text(name)
15 text = self.vstorage.revision_text(name, revision)
16 return Document(self, name=name, text=text)
18 def put(self, document, author, comment, parent):
19 self.vstorage.save_text(document.name, document.text, author, comment, parent)
21 def delete(self, name, author, comment):
22 self.vstorage.delete_page(name, author, comment)
25 return list(self.vstorage.all_pages())
27 def _info(self, name):
28 return self.vstorage.page_meta(name)
31 class Document(object):
32 META_REGEX = re.compile(r'\s*<!--\s(.*?)-->', re.DOTALL | re.MULTILINE)
34 def __init__(self, storage, **kwargs):
35 self.storage = storage
36 for attr, value in kwargs.iteritems():
37 setattr(self, attr, value)
41 return self.storage._info(self.name)[0]
42 except DocumentNotFound:
46 return re.sub(self.META_REGEX, '', self.text, 1)
51 m = re.match(self.META_REGEX, self.text)
53 for line in m.group(1).split('\n'):
55 k, v = line.split(':', 1)
56 result[k.strip()] = v.strip()
63 storage = DocumentStorage(settings.REPOSITORY_PATH)