5 import treecutter.constants as const
6 from treecutter.docbook import Docbook
8 from itertools import chain
11 """Class containing the state of the directory with articles"""
14 self._translations = []
16 self._basepath = re.compile('[/\w\._-]*/[\w-]+',re.UNICODE)
18 def translations(self, directory):
19 paths = (self._cwd, directory)
20 for dirname, dirnames, filenames in chain.from_iterable(os.walk(path) for path in paths):
21 for filename in filenames:
22 if fnmatch.fnmatch(filename, '*.xlf'):
23 file_ = os.path.join(dirname,filename)
24 self._translations.append(file_)
25 return self._translations
28 def scan(self, draftflag, levelflag):
29 for dirname, dirnames, filenames in os.walk(self._cwd):
30 for filename in filenames:
31 if fnmatch.fnmatch(filename, '*.xml'):
32 file_ = os.path.join(dirname,filename)
34 (title, menu) = doc.title()
35 draft = doc.status() == "draft"
36 level = doc.userlevel()
38 # doc = etree.parse(file_)
39 # title = doc.xpath(u'/db:article/db:info/db:title',namespaces=const.XPATH)
40 # menu = doc.xpath(u'/db:article/db:info/db:titleabbrev',namespaces=const.XPATH)
41 # draft = doc.xpath(u'/db:article[@status="draft"]',namespaces=const.XPATH)
42 if draft and draftflag:
44 if title and menu and not draft and level <= levelflag:
45 base = self._basepath.match(file_).group()
46 link = base.replace('index','')[1:]
47 self._tree.append(link)
50 return set(self._tree)