main: changes to time, commments
[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     args = parser.parse_args()
16
17     ts = time()
18     dir_ = Directory()
19     sitemap = Sitemap()
20
21     # Scanning current directory and subdirectory for docbook articles
22     dir_.scan()
23     # Reading the sitemap.txt building a Trie structure
24     sitemap.read_map()
25
26     # Comparing the current state of the dir with the sitemap
27     missing = dir_.set() - sitemap.set()
28     removed = sitemap.set() - dir_.set()
29     for page in removed:
30         print page+' pages missing!!'
31     for page in missing:
32         print 'adding missing page '+page
33         sitemap.add_link(page)
34     if len(missing)+len(removed) != 0:
35         print 'writing new sitemap - please adjust if needed'
36         sitemap.write_map()
37
38     # Generate a pygraphviz image of the site (TODO: currently not used)
39     sitemap.graph()
40     # Start processing the docbook articles to static html
41     sitemap.process(args.style)
42
43     # Publish static html and style data (css, images, fonts) to destination dir
44     t1 = time()
45     sitemap.publish(args.output,args.style)
46     t2 = time()
47     print "Publish  [%5.2f s]" % (round(t2-t1,2))
48     print "Total    [%5.2f s]" % (round(t2-ts,2))
49     return 0
50
51 if __name__ == "__main__":
52     sys.exit(main())