Refactoring out every class into separate files. main,tools and const are not classes.
[treecutter.git] / treecutter / directory.py
1 #!/usr/bin/python
2 import os
3 import fnmatch
4 import subprocess
5 import amara
6 import re
7 import tempfile
8 import errno
9 import time
10 import argparse
11 import shutil
12 import pygraphviz as pgv
13 import glob
14 import gettext
15 import shutil
16 from amara import bindery
17 from amara.xslt import transform
18 from Cheetah.Template import Template
19
20 class Directory():
21     """Class containing the state of the directory with articles"""
22     def __init__(self):
23         self._cwd = '.'
24         self._tree = []
25
26     def scan(self):
27         for dirname, dirnames, filenames in os.walk(self._cwd):
28             for filename in filenames:
29                 if fnmatch.fnmatch(filename, '*.xml'):
30                     file_ = os.path.join(dirname,filename)
31                     doc = bindery.parse(file_, prefixes=PREFIXES)
32                     title = doc.xml_select(u'/db:article/db:info/db:title')
33                     menu  = doc.xml_select(u'/db:article/db:info/db:titleabbrev')
34                     if title and menu:
35                         base = file_.split('.')[1]
36                         link = base.replace('index','')
37                         self._tree.append(link)
38
39     def set(self):
40         return set(self._tree)