c685f7d3756951ea9a123c29461a52b49ad8aa06
[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     parser.add_argument('--draft', action='store_true')
18     parser.add_argument('--level', type=int, choices=[1, 2, 3, 4, 5], default=0)
19
20     args = parser.parse_args()
21
22     ts = time()
23     print "--= Treecutter =--"
24     dir_ = Directory()
25     sitemap = Sitemap(args)
26
27     # Scanning current directory and subdirectory for docbook articles
28     dir_.scan(args.draft, args.level)
29     # Reading the sitemap.txt building a Trie structure
30     sitemap.read_map()
31
32     # Comparing the current state of the dir with the sitemap
33     dirset = dir_.set()
34     missing = dirset - sitemap.set()
35     removed = sitemap.set() - dirset
36     for page in removed:
37         print page+' page not availible in this config'
38     for page in missing:
39         print 'adding missing page '+page
40         sitemap.add_link(page)
41     if len(missing) != 0:
42         print 'writing new sitemap - please adjust if needed'
43         sitemap.write_map()
44
45     dirsitemap = Sitemap(args)
46     for l in sitemap.linklist():
47         if l in dirset:
48             dirsitemap.add_link(l)
49
50
51     # Generate a pygraphviz image of the site (TODO: currently not used)
52     dirsitemap.graph()
53     # Start processing the docbook articles to static html
54     dirsitemap.process()
55
56     # Publish static html and style data (css, images, fonts) to destination dir
57     t1 = time()
58     dirsitemap.publish()
59     t2 = time()
60     print "Publish  [%5.2f s]" % (round(t2-t1,2))
61     print "Total    [%5.2f s]" % (round(t2-ts,2))
62     return 0
63
64 if __name__ == "__main__":
65     sys.exit(main())