import fnmatch
from lxml import etree
import treecutter.constants as const
+from treecutter.docbook import Docbook
import re
+from itertools import chain
class Directory():
"""Class containing the state of the directory with articles"""
def __init__(self):
self._cwd = u'.'
+ self._translations = []
self._tree = []
self._basepath = re.compile('[/\w\._-]*/[\w-]+',re.UNICODE)
- def scan(self):
+ def translations(self, directory):
+ paths = (self._cwd, directory)
+ for dirname, dirnames, filenames in chain.from_iterable(os.walk(path) for path in paths):
+ for filename in filenames:
+ if fnmatch.fnmatch(filename, '*.xlf'):
+ file_ = os.path.join(dirname,filename)
+ self._translations.append(file_)
+ return self._translations
+
+
+ def scan(self, draftflag, levelflag):
for dirname, dirnames, filenames in os.walk(self._cwd):
for filename in filenames:
if fnmatch.fnmatch(filename, '*.xml'):
file_ = os.path.join(dirname,filename)
- doc = etree.parse(file_)
- title = doc.xpath(u'/db:article/db:info/db:title',namespaces=const.XPATH)
- menu = doc.xpath(u'/db:article/db:info/db:titleabbrev',namespaces=const.XPATH)
- if title and menu:
+ doc = Docbook(file_)
+ (title, menu) = doc.title()
+ draft = doc.status() == "draft"
+ level = doc.userlevel()
+
+# doc = etree.parse(file_)
+# title = doc.xpath(u'/db:article/db:info/db:title',namespaces=const.XPATH)
+# menu = doc.xpath(u'/db:article/db:info/db:titleabbrev',namespaces=const.XPATH)
+# draft = doc.xpath(u'/db:article[@status="draft"]',namespaces=const.XPATH)
+ if draft and draftflag:
+ draft = False
+ if title and menu and not draft and level <= levelflag:
base = self._basepath.match(file_).group()
link = base.replace('index','')[1:]
self._tree.append(link)