projects
/
treecutter.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
xml: change from amara to lxml
[treecutter.git]
/
treecutter
/
sitemap.py
diff --git
a/treecutter/sitemap.py
b/treecutter/sitemap.py
index e85c6906c831ddd9a6b69ac827ae1c93096f46cd..a8612f23b9ba9b1c1955bd370af771b59a008b9f 100644
(file)
--- a/
treecutter/sitemap.py
+++ b/
treecutter/sitemap.py
@@
-4,8
+4,10
@@
import re
import shutil
import gettext
import tempfile
import shutil
import gettext
import tempfile
-from amara import bindery
+from lxml import etree
+from lxml.builder import ElementMaker
from time import time
from time import time
+from treecutter import constants as const
from treecutter.trie import Trie
from treecutter.link import Link
from treecutter.tools import ssh_cmd, publish, mkdir_p
from treecutter.trie import Trie
from treecutter.link import Link
from treecutter.tools import ssh_cmd, publish, mkdir_p
@@
-16,10
+18,14
@@
class Sitemap():
self._file = 'sitemap.txt'
self._tree = Trie()
self._sitelang = set()
self._file = 'sitemap.txt'
self._tree = Trie()
self._sitelang = set()
- self._isocode =
bindery
.parse('/usr/share/xml/iso-codes/iso_639_3.xml')
+ self._isocode =
etree
.parse('/usr/share/xml/iso-codes/iso_639_3.xml')
self._tranlang = {}
self._tmptarget = tempfile.mkdtemp()+'/'
self._tranlang = {}
self._tmptarget = tempfile.mkdtemp()+'/'
+ # The sitemap uses a trie structure to keep track of links
+ # A link represents the path to the document and the link
+ # representing the text on the site.
+ # A link can have several pages in different languages.
def add_link(self, link):
tokens = filter(None,re.split(r'(^/[\w-]*/|[\w-]*/)',link))
self._tree.add(tokens,Link(link))
def add_link(self, link):
tokens = filter(None,re.split(r'(^/[\w-]*/|[\w-]*/)',link))
self._tree.add(tokens,Link(link))
@@
-39,9
+45,13
@@
class Sitemap():
except IOError, what_error:
print 'INFO: Could not read sitemap.txt - one will be created'
except IOError, what_error:
print 'INFO: Could not read sitemap.txt - one will be created'
+ # Create a set of the current tree for comparison with the
+ # directory scan
def set(self):
return set(link.link() for link in self._tree)
def set(self):
return set(link.link() for link in self._tree)
+ # Main driver in the application processing the documents
+ # in the collected sitemap
def process(self, style):
t1 = time()
print "Prepareing the input"
def process(self, style):
t1 = time()
print "Prepareing the input"
@@
-67,7
+77,7
@@
class Sitemap():
print "Template [%5.2f s]" % (round(t5-t4,2))
t6 = time()
res = set()
print "Template [%5.2f s]" % (round(t5-t4,2))
t6 = time()
res = set()
- cwd = os.getcwd()
+ # Collect all files used by the documents
for link in self._tree:
res = res.union(link.resources())
for f in res:
for link in self._tree:
res = res.union(link.resources())
for f in res:
@@
-75,6
+85,8
@@
class Sitemap():
mkdir_p(os.path.dirname(outfile))
shutil.copyfile(f,outfile)
print "Resources[%5.2f s]" % (round(t6-t5,2))
mkdir_p(os.path.dirname(outfile))
shutil.copyfile(f,outfile)
print "Resources[%5.2f s]" % (round(t6-t5,2))
+ # TODO: Improve the sitemap, it is a page that is generated from
+ # the ground up and added a bit adhoc.
sitmaplink = Link('/sitemap')
for l in self._sitelang:
sitmaplink.add_page((l,'/sitemap.'+l+'.xml'))
sitmaplink = Link('/sitemap')
for l in self._sitelang:
sitmaplink.add_page((l,'/sitemap.'+l+'.xml'))
@@
-91,24
+103,25
@@
class Sitemap():
return self._tree.menu(lang,page,cssclass)
def lang_menu(self,lang,link):
return self._tree.menu(lang,page,cssclass)
def lang_menu(self,lang,link):
- html = "<ul>"
+ html = ElementMaker(namespace=const.HTML_NS)
+ menu = html.ul()
for l in link.languages():
isoxml = u"//iso_639_3_entry[@*='"+l+"']"
for l in link.languages():
isoxml = u"//iso_639_3_entry[@*='"+l+"']"
- ln = self._isocode.x
ml_select(isoxml)[0].name
+ ln = self._isocode.x
path(isoxml)[0].get('name')
if lang != 'en':
ln = self._tranlang[lang].gettext(ln)
p = link.link()
if p[-1] == '/':
p = p +'index'
p = p+'.'+l
if lang != 'en':
ln = self._tranlang[lang].gettext(ln)
p = link.link()
if p[-1] == '/':
p = p +'index'
p = p+'.'+l
-
html += '<li><a href="%s" hreflang="%s">%s</a></li>' % (p, l, ln
)
- html += "</ul>"
- return
html
+
li = html.li(html.a(ln,href=p,hreflang=l)
)
+ menu.append(li)
+ return
etree.tostring(menu,encoding='UTF-8',pretty_print=False)
def publish(self,output,style):
ssh_cmd(output,"mkdir -p")
publish(self._tmptarget, output)
def publish(self,output,style):
ssh_cmd(output,"mkdir -p")
publish(self._tmptarget, output)
- for res in ["css","images","js","favicon.ico"]:
+ for res in ["css","images","js","f
onts","f
avicon.ico"]:
if (os.path.exists(style+res)):
publish(style+res, output)
ssh_cmd(output,"chmod a+rx")
if (os.path.exists(style+res)):
publish(style+res, output)
ssh_cmd(output,"chmod a+rx")