1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 from vstorage import DocumentNotFound
9 from wiki import settings
11 class DocumentStorage(object):
12 def __init__(self, path):
13 self.vstorage = vstorage.VersionedStorage(path)
15 def get(self, name, revision = None):
17 text = self.vstorage.page_text(name)
19 text = self.vstorage.revision_text(name, revision)
20 return Document(self, name = name, text = text)
22 def put(self, document, author, comment, parent):
23 self.vstorage.save_text(
24 title = document.name,
30 def delete(self, name, author, comment):
31 self.vstorage.delete_page(name, author, comment)
34 return list(self.vstorage.all_pages())
36 def history(self, title):
37 return list(self.vstorage.page_history(title))
39 def _info(self, name):
40 return self.vstorage.page_meta(name)
43 class Document(object):
44 META_REGEX = re.compile(r'\s*<!--\s(.*?)-->', re.DOTALL | re.MULTILINE)
46 def __init__(self, storage, **kwargs):
47 self.storage = storage
48 for attr, value in kwargs.iteritems():
49 setattr(self, attr, value)
53 return self.storage._info(self.name)[0]
54 except DocumentNotFound:
59 return re.sub(self.META_REGEX, '', self.text, 1)
64 m = re.match(self.META_REGEX, self.text)
66 for line in m.group(1).split('\n'):
68 k, v = line.split(':', 1)
69 result[k.strip()] = v.strip()
76 return DocumentStorage(settings.REPOSITORY_PATH)