12 import pygraphviz as pgv
16 from amara import bindery
17 from amara.xslt import transform
18 from Cheetah.Template import Template
21 """Class keeping the internal site structure"""
23 self._file = 'sitemap.txt'
25 self._sitelang = set()
26 self._isocode = bindery.parse('/usr/share/xml/iso-codes/iso_639_3.xml')
29 def add_link(self, link):
30 tokens = filter(None,re.split(r'(^/[\w-]*/|[\w-]*/)',link))
31 self._tree.add(tokens,Link(link))
34 f = open(self._file,'w')
35 f.write('\n'.join(link.link() for link in self._tree))
41 sml = f.read().split()
45 except IOError, what_error:
46 print 'INFO: Could not read sitemap.txt - one will be created'
49 return set(link.link() for link in self._tree)
53 for link in self._tree:
56 print "Prepare [%5.2f s]" % (round(t2-t1,2))
57 for link in self._tree:
58 self._sitelang = self._sitelang.union(set(link.languages()))
59 for tran in self._sitelang:
61 self._tranlang[tran] = gettext.translation('iso_639_3',
64 print "Language [%5.2f s]" % (round(t3-t2,2))
65 for link in self._tree:
68 print "Render [%5.2f s]" % (round(t4-t3,2))
69 for link in self._tree:
72 print "Template [%5.2f s]" % (round(t5-t4,2))
76 for link in self._tree:
77 res = res.union(link.resources())
80 mkdir_p(os.path.dirname(outfile))
81 shutil.copyfile(f,outfile)
82 print "Resources[%5.2f s]" % (round(t6-t5,2))
83 sitmaplink = Link('/sitemap')
84 for l in self._sitelang:
85 sitmaplink.add_page((l,'/sitemap.'+l+'.xml'))
86 for l in self._sitelang:
87 sitmaplink.page(l).set_article(self.gen_menu(l,None,"tree sitemap"))
88 sitmaplink.page(l).template(self)
90 print "Sitemap [%5.2f s]" % (round(t7-t6,2))
95 def gen_menu(self,lang,page,cssclass):
96 return self._tree.menu(lang,page,cssclass)
98 def lang_menu(self,lang,link):
100 for l in link.languages():
101 isoxml = u"//iso_639_3_entry[@*='"+l+"']"
102 ln = self._isocode.xml_select(isoxml)[0].name
104 ln = self._tranlang[lang].gettext(ln)
109 html += '<li><a href="%s" hreflang="%s">%s</a></li>' % (p, l, ln)
114 ssh_cmd(args.output,"mkdir -p")
115 publish(tmptarget, args.output)
116 for res in ["css","images","js","favicon.ico"]:
117 if (os.path.exists(args.style+res)):
118 publish(args.style+res, args.output)
119 ssh_cmd(args.output,"chmod a+rx")