Added subdir argument, cleaned up arg handling
[treecutter.git] / treecutter / main.py
1 #!/usr/bin/python
2 import os
3 from time import time
4 import argparse
5 from treecutter.directory import Directory
6 from treecutter.sitemap import Sitemap
7
8 def main():
9
10     parser = argparse.ArgumentParser(description='Process docbook article tree.')
11     parser.add_argument('--style', nargs='?',
12                         default=os.path.dirname(os.getcwd())+'/style/default/')
13     parser.add_argument('--output', nargs='?',
14                         default=os.path.dirname(os.getcwd())+'/htdocs/')
15     parser.add_argument('--subdir', nargs='?',
16                         default='')
17     args = parser.parse_args()
18
19     ts = time()
20     dir_ = Directory()
21     sitemap = Sitemap(args)
22
23     # Scanning current directory and subdirectory for docbook articles
24     dir_.scan()
25     # Reading the sitemap.txt building a Trie structure
26     sitemap.read_map()
27
28     # Comparing the current state of the dir with the sitemap
29     missing = dir_.set() - sitemap.set()
30     removed = sitemap.set() - dir_.set()
31     for page in removed:
32         print page+' pages missing!!'
33     for page in missing:
34         print 'adding missing page '+page
35         sitemap.add_link(page)
36     if len(missing)+len(removed) != 0:
37         print 'writing new sitemap - please adjust if needed'
38         sitemap.write_map()
39
40     # Generate a pygraphviz image of the site (TODO: currently not used)
41     sitemap.graph()
42     # Start processing the docbook articles to static html
43     sitemap.process()
44
45     # Publish static html and style data (css, images, fonts) to destination dir
46     t1 = time()
47     sitemap.publish()
48     t2 = time()
49     print "Publish  [%5.2f s]" % (round(t2-t1,2))
50     print "Total    [%5.2f s]" % (round(t2-ts,2))
51     return 0
52
53 if __name__ == "__main__":
54     sys.exit(main())