language: added full translation support
[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 from treecutter.tools import translate
8
9 def main():
10
11     parser = argparse.ArgumentParser(description='Process docbook article tree.')
12     parser.add_argument('--style', nargs='?',
13                         default=os.path.dirname(os.getcwd())+'/style/default/')
14     parser.add_argument('--output', nargs='?',
15                         default=os.path.dirname(os.getcwd())+'/htdocs/')
16     parser.add_argument('--subdir', nargs='?',
17                         default='')
18     parser.add_argument('--draft', action='store_true')
19     parser.add_argument('--level', type=int, choices=[1, 2, 3, 4, 5], default=0)
20
21     args = parser.parse_args()
22
23     ts = time()
24     print "--= Treecutter =--"
25     dir_ = Directory()
26     t1 = time()
27     totrans = dir_.translations(args.style)
28     print "Translate [%d] : [" % (len(totrans)),
29     translate(totrans)
30     print "]"
31     t2 = time()
32     print "Translate[%5.2f s]" % (round(t2-t1,2))
33
34
35     sitemap = Sitemap(args)
36
37     # Scanning current directory and subdirectory for docbook articles
38     dir_.scan(args.draft, args.level)
39     # Reading the sitemap.txt building a Trie structure
40     sitemap.read_map()
41
42     # Comparing the current state of the dir with the sitemap
43     dirset = dir_.set()
44     missing = dirset - sitemap.set()
45     removed = sitemap.set() - dirset
46     for page in removed:
47         print page+' page not availible in this config'
48     for page in missing:
49         print 'adding missing page '+page
50         sitemap.add_link(page)
51     if len(missing) != 0:
52         print 'writing new sitemap - please adjust if needed'
53         sitemap.write_map()
54
55     dirsitemap = Sitemap(args)
56     for l in sitemap.linklist():
57         if l in dirset:
58             dirsitemap.add_link(l)
59
60
61     # Generate a pygraphviz image of the site (TODO: currently not used)
62     dirsitemap.graph()
63     # Start processing the docbook articles to static html
64     dirsitemap.process()
65
66     # Publish static html and style data (css, images, fonts) to destination dir
67     t1 = time()
68     dirsitemap.publish()
69     t2 = time()
70     print "Publish  [%5.2f s]" % (round(t2-t1,2))
71     print "Total    [%5.2f s]" % (round(t2-ts,2))
72     return 0
73
74 if __name__ == "__main__":
75     sys.exit(main())