Refactoring, using const, removing global variables, passing some new arguments.
[treecutter.git] / treecutter / sitemap.py
index d87c5c92dbc7d9849fc945937e8ec3872c23040b..7bd81e9a1097da7bb0041c8c56b8cf6e94a4b32c 100644 (file)
@@ -18,6 +18,7 @@ class Sitemap():
         self._sitelang = set()
         self._isocode = bindery.parse('/usr/share/xml/iso-codes/iso_639_3.xml')
         self._tranlang = {}
+        self._tmptarget = tempfile.mkdtemp()+'/'
 
     def add_link(self, link):
         tokens = filter(None,re.split(r'(^/[\w-]*/|[\w-]*/)',link))
@@ -41,7 +42,7 @@ class Sitemap():
     def set(self):
         return set(link.link() for link in self._tree)
 
-    def process(self):
+    def process(self, style):
         t1 = time.time()
         for link in self._tree:
             link.prepare()
@@ -56,11 +57,11 @@ class Sitemap():
         t3 = time.time()
         print "Language [%5.2f s]" % (round(t3-t2,2))
         for link in self._tree:
-            link.render()
+            link.render(style)
         t4 = time.time()
         print "Render   [%5.2f s]" % (round(t4-t3,2))
         for link in self._tree:
-            link.template(self)
+            link.template(self, style, self._tmptarget)
         t5 = time.time()
         print "Template [%5.2f s]" % (round(t5-t4,2))
         t6 = time.time()
@@ -69,7 +70,7 @@ class Sitemap():
         for link in self._tree:
             res = res.union(link.resources())
         for f in res:
-            outfile = tmptarget+f
+            outfile = self._tmptarget+f
             mkdir_p(os.path.dirname(outfile))
             shutil.copyfile(f,outfile)
         print "Resources[%5.2f s]" % (round(t6-t5,2))
@@ -78,7 +79,7 @@ class Sitemap():
             sitmaplink.add_page((l,'/sitemap.'+l+'.xml'))
         for l in self._sitelang:
             sitmaplink.page(l).set_article(self.gen_menu(l,None,"tree sitemap"))
-            sitmaplink.page(l).template(self)
+            sitmaplink.page(l).template(self,style,self._tmptarget)
         t7 = time.time()
         print "Sitemap  [%5.2f s]" % (round(t7-t6,2))
 
@@ -103,10 +104,10 @@ class Sitemap():
         html += "</ul>"
         return html
 
-    def publish(self):
-        ssh_cmd(args.output,"mkdir -p")
-        publish(tmptarget, args.output)
+    def publish(self,output,style):
+        ssh_cmd(output,"mkdir -p")
+        publish(self._tmptarget, output)
         for res in ["css","images","js","favicon.ico"]:
-            if (os.path.exists(args.style+res)):
-                publish(args.style+res, args.output)
-        ssh_cmd(args.output,"chmod a+rx")
+            if (os.path.exists(style+res)):
+                publish(style+res, output)
+        ssh_cmd(output,"chmod a+rx")