This phase was to clean up the use of output and style in several places.
Now passed as arguments to the sections where it is needed.
Tempfile creation also localized.
u'xi': u'http://www.w3.org/2001/XInclude',
u'xl': u'http://www.w3.org/1999/xlink',
u'html' : u'http://www.w3.org/1999/xhtml'}
+
for filename in filenames:
if fnmatch.fnmatch(filename, '*.xml'):
file_ = os.path.join(dirname,filename)
- doc = bindery.parse(file_, prefixes=PREFIXES)
+ doc = bindery.parse(file_, prefixes=const.PREFIXES)
title = doc.xml_select(u'/db:article/db:info/db:title')
menu = doc.xml_select(u'/db:article/db:info/db:titleabbrev')
if title and menu:
p.append(page.language())
return p
- def render(self):
+ def render(self, style):
for page in self._pages:
- page.render()
+ page.render(style)
- def template(self,sitemap):
+ def template(self,sitemap,style,tdir):
for page in self._pages:
- page.template(sitemap)
+ page.template(sitemap,style,tdir)
def page(self,lang):
for page in self._pages:
default=os.path.dirname(os.getcwd())+'/htdocs/')
args = parser.parse_args()
-style_xslt = args.style+"docbook.xsl"
-outputdir = args.output
-
-tmptarget = tempfile.mkdtemp()+'/'
-
-MAXLEVEL = 10000
-
ts = time.time()
dir_ = Directory()
sitemap = Sitemap()
sitemap.write_map()
sitemap.graph()
-sitemap.process()
+sitemap.process(args.style)
t1 = time.time()
-sitemap.publish()
+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))
self._rendered_article = art
def prepare(self):
- self._doc = bindery.parse(self._file, prefixes=PREFIXES)
+ self._doc = bindery.parse(self._file, prefixes=const.PREFIXES)
if self._doc.xml_select(u'/db:article/db:info/db:title'):
self._title = unicode(self._doc.article.info.title)
if self._doc.xml_select(u'/db:article/db:info/db:titleabbrev'):
if code:
for c in code:
(p, ext) = os.path.splitext(c.href)
- if ext in valid_scripts:
+ if ext in const.valid_scripts:
exe = []
exe.append(os.path.join(os.path.abspath(dirname)+'/'+c.href))
if c.xml_select(u"//xi:include[@accept-language]"):
if os.path.isfile(im):
self._resources.append(im)
- def render(self):
+ def render(self, style):
# amara can not handle the docbook stylesheets
# xmlarticle = transform(doc,style_xslt)
cwd = os.getcwd()
tfi.write(self._doc.xml_encode(omit_xml_declaration=True))
tfi.close()
# cmd = ["saxon-xslt-xinclude","-o",outfile,infile,style_xslt]
- cmd = ["xsltproc","--xinclude","--output",outfile,style_xslt,infile]
+ cmd = ["xsltproc","--xinclude","--output",outfile,style+"docbook.xsl",infile]
retcode = subprocess.call(cmd)
if retcode:
print 'Error: '+' '.join(cmd)+' Returncode ['+str(retcode)+']'
os.remove(outfile)
os.chdir(cwd)
- def template(self,sitemap):
+ def template(self,sitemap,style,tdir):
htmlmenu = sitemap.gen_menu(self._lang,None,"menu")
levelmenu = sitemap.gen_menu(self._lang,self,"tree")
langmenu = sitemap.lang_menu(self._lang,self._link)
- template = Template(file=args.style+'index.'+self._lang+'.html.tmpl',
+ template = Template(file=style+'index.'+self._lang+'.html.tmpl',
searchList=[{'title':self._title},
{'menu':htmlmenu},
{'article':self._rendered_article},
{'levelmenu':levelmenu},
{'langmenu':langmenu}])
- outfile = tmptarget+'html'.join(self._file.rsplit('xml',1))
+ outfile = tdir+'html'.join(self._file.rsplit('xml',1))
mkdir_p(os.path.dirname(outfile))
out = open(outfile, 'w')
out.write(str(template))
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))
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()
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()
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))
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))
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")