Adding fonts directory to resources.
[treecutter.git] / treecutter / sitemap.py
old mode 100755 (executable)
new mode 100644 (file)
index 11467de..e7a2e4b
@@ -1,21 +1,14 @@
 #!/usr/bin/python
 import os
-import fnmatch
-import subprocess
-import amara
 import re
-import tempfile
-import errno
-import time
-import argparse
 import shutil
-import pygraphviz as pgv
-import glob
 import gettext
-import shutil
+import tempfile
 from amara import bindery
-from amara.xslt import transform
-from Cheetah.Template import Template
+from time import time
+from treecutter.trie import Trie
+from treecutter.link import Link
+from treecutter.tools import ssh_cmd, publish, mkdir_p
 
 class Sitemap():
     """Class keeping the internal site structure"""
@@ -25,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))
@@ -48,11 +42,12 @@ class Sitemap():
     def set(self):
         return set(link.link() for link in self._tree)
 
-    def process(self):
-        t1 = time.time()
+    def process(self, style):
+        t1 = time()
+        print "Prepareing the input"
         for link in self._tree:
             link.prepare()
-        t2 = time.time()
+        t2 = time()
         print "Prepare  [%5.2f s]" % (round(t2-t1,2))
         for link in self._tree:
             self._sitelang = self._sitelang.union(set(link.languages()))
@@ -60,23 +55,23 @@ class Sitemap():
             if tran != 'en':
                 self._tranlang[tran] = gettext.translation('iso_639_3',
                                                            languages=[tran])
-        t3 = time.time()
+        t3 = time()
         print "Language [%5.2f s]" % (round(t3-t2,2))
         for link in self._tree:
-            link.render()
-        t4 = time.time()
+            link.render(style)
+        t4 = time()
         print "Render   [%5.2f s]" % (round(t4-t3,2))
         for link in self._tree:
-            link.template(self)
-        t5 = time.time()
+            link.template(self, style, self._tmptarget)
+        t5 = time()
         print "Template [%5.2f s]" % (round(t5-t4,2))
-        t6 = time.time()
+        t6 = time()
         res = set()
         cwd = os.getcwd()
         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))
@@ -85,8 +80,8 @@ 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)
-        t7 = time.time()
+            sitmaplink.page(l).template(self,style,self._tmptarget)
+        t7 = time()
         print "Sitemap  [%5.2f s]" % (round(t7-t6,2))
 
     def graph(self):
@@ -110,10 +105,10 @@ class Sitemap():
         html += "</ul>"
         return html
 
-    def publish(self):
-        ssh_cmd(args.output,"mkdir -p")
-        publish(tmptarget, args.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")
+    def publish(self,output,style):
+        ssh_cmd(output,"mkdir -p")
+        publish(self._tmptarget, output)
+        for res in ["css","images","js","fonts","favicon.ico"]:
+            if (os.path.exists(style+res)):
+                publish(style+res, output)
+        ssh_cmd(output,"chmod a+rx")