import fnmatch
from lxml import etree
import treecutter.constants as const
+from treecutter.docbook import Docbook
import re
class Directory():
def __init__(self):
self._cwd = u'.'
self._tree = []
- self._basepath = re.compile('[/\w\._-]*/\w+',re.UNICODE)
+ self._basepath = re.compile('[/\w\._-]*/[\w-]+',re.UNICODE)
def scan(self):
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)