Fixing the def main function, properly calling it from treecutter.
[treecutter.git] / treecutter / main.py
index ba09eaf801d080d523ade9dcbc640f24d1675f51..b53a92fc8618165fad4c013b4e2a7a9aeb295309 100644 (file)
@@ -5,36 +5,41 @@ import argparse
 from treecutter.directory import Directory
 from treecutter.sitemap import Sitemap
 
-parser = argparse.ArgumentParser(description='Process docbook article tree.')
-parser.add_argument('--style', nargs='?',
-                    default=os.path.dirname(os.getcwd())+'/style/default/')
-parser.add_argument('--output', nargs='?',
-                    default=os.path.dirname(os.getcwd())+'/htdocs/')
-args = parser.parse_args()
+def main():
+    parser = argparse.ArgumentParser(description='Process docbook article tree.')
+    parser.add_argument('--style', nargs='?',
+                        default=os.path.dirname(os.getcwd())+'/style/default/')
+    parser.add_argument('--output', nargs='?',
+                        default=os.path.dirname(os.getcwd())+'/htdocs/')
+    args = parser.parse_args()
 
-ts = time.time()
-dir_ = Directory()
-sitemap = Sitemap()
+    ts = time.time()
+    dir_ = Directory()
+    sitemap = Sitemap()
 
-dir_.scan()
-sitemap.read_map()
+    dir_.scan()
+    sitemap.read_map()
 
-missing = dir_.set() - sitemap.set()
-removed = sitemap.set() - dir_.set()
-for page in removed:
-    print page+' pages missing!!'
-for page in missing:
-    print 'adding missing page '+page
-    sitemap.add_link(page)
-if len(missing)+len(removed) != 0:
-    print 'writing new sitemap - please adjust if needed'
-    sitemap.write_map()
-sitemap.graph()
+    missing = dir_.set() - sitemap.set()
+    removed = sitemap.set() - dir_.set()
+    for page in removed:
+        print page+' pages missing!!'
+    for page in missing:
+        print 'adding missing page '+page
+        sitemap.add_link(page)
+    if len(missing)+len(removed) != 0:
+        print 'writing new sitemap - please adjust if needed'
+        sitemap.write_map()
+    sitemap.graph()
 
-sitemap.process(args.style)
+    sitemap.process(args.style)
 
-t1 = time.time()
-sitemap.publish(args.output,args.style)
-t2 = time.time()
-print "Publish  [%5.2f s]" % (round(t2-t1,2))
-print "Total    [%5.2f s]" % (round(t2-ts,2))
+    t1 = time.time()
+    sitemap.publish(args.output,args.style)
+    t2 = time.time()
+    print "Publish  [%5.2f s]" % (round(t2-t1,2))
+    print "Total    [%5.2f s]" % (round(t2-ts,2))
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())