def generate_site(db): utils.mkdirp(confstatic.generate_path) print "<ul><li>"+_("Copie des fichiers latex, de style, ainsi que vos pages personnelles et vos images")+"</li>" ## Updates the latex file (useful for pdf files) #met à jour le latex (utile pour les pdf) try: shutil.rmtree(os.path.join(confstatic.generate_path,"latex")) shutil.copytree(confstatic.latex_path, os.path.join(confstatic.generate_path,"latex")) except OSError: pass ## Updates the style #met à jour le style try: utils.mkdirp(os.path.join(confstatic.generate_path,"styles")) shutil.copytree(os.path.join("styles",conf_general.style), os.path.join(confstatic.generate_path,"styles",conf_general.style)) except OSError: pass ## Updates common #met à jour common try: shutil.copytree(os.path.join("styles","common"), os.path.join(confstatic.generate_path,"styles","common")) except OSError: pass ## Updates personal page #met à jour le perso try: shutil.rmtree(os.path.join(confstatic.generate_path,"perso")) shutil.copytree(os.path.join(confstatic.config_path,"perso"), os.path.join(confstatic.generate_path,"perso")) except OSError: pass confstatic.generating = True confstatic.build_url = confstatic.build_url_for_generation tpages = db.table(confstatic.pages_database_prefix) pages = tpages.select() last_cwd = os.getcwd() try: while True: p = pages.next() print "<li>"+((_("Génération de la page %s: ")+"\"%s\"") % (p["page_id"],p["page_title"]))+"</li>" sys.stdout.flush() generate_page(p["page_id"], {}, db) except StopIteration: os.chdir(last_cwd) shutil.copy(os.path.join(confstatic.generate_path,confstatic.build_url({"page":confstatic.default_page_name+".html"})), os.path.join(confstatic.generate_path,"index.html")) shutil.copy(os.path.join(confstatic.generate_path,confstatic.build_url({"page":confstatic.default_page_name+".html"})), os.path.join(confstatic.generate_path,"index.htm")) shutil.copy(os.path.join("styles","favicon.png"), os.path.join(confstatic.generate_path,"styles","favicon.png")) shutil.copy(os.path.join("styles","comfort_thumb.png"), os.path.join(confstatic.generate_path,"styles","comfort_thumb.png")) shutil.copy(os.path.join(confstatic.config_path,"database"), os.path.join(confstatic.generate_path,".database")) shutil.copy(os.path.join(confstatic.config_path,"conf_general.py"), os.path.join(confstatic.generate_path,".conf_general.py")) print "</ul>"
def generate_content_xml(self, args): """ Génère les boutons du menu """ menu=self.db.table(self.database_prefix+"_items"). select(cond=[],order=[("id",True)]) str = "<itemizedlist>\n" in_submenu = False count = 0 for e in menu: if e["is_comfort"]!=0: url = confstatic.build_url({"page":urllib.quote(e["item_link"])+".html"}) else: url = confstatic.get_pages_url(e["item_link"]) if e["item_depth"] == 1 and not in_submenu: str += "\n\t<itemizedlist>" in_submenu = True elif e["item_depth"] == 0 and not in_submenu and count > 0: str += "</listitem>\n" in_submenu = False elif e["item_depth"] == 1 and in_submenu: str += "</listitem>\n" in_submenu = True elif e["item_depth"] == 0 and in_submenu: str += "</listitem></itemizedlist></listitem>\n" in_submenu = False str += ("""<listitem><ulink url=\"%s\">%s</ulink>\n""" )%(url, utils.sanitize(e["item_text"])) count += 1 if not in_submenu: str += "</listitem>\n" in_submenu = False elif in_submenu: str += "</listitem></itemizedlist></listitem>\n" in_submenu = False str += "</itemizedlist>" return str
except template_manager.TMException, e: print _("Error initializing templates engine : %s") % e.__str__() sys.exit(1) except Exception, e: print "Unexpected exception ", e print sys.exc_info() ## Link to the database forwarded to modules that require it #on fait suivre la connexion à la base de données aux modules qui en ont #besoin mm.forward_db_init(db) ## XHTML generation #et on génère le XHTML x = tm.generate_xhtml() fname = confstatic.build_url(args) f = open(os.path.join(confstatic.generate_path,fname), "w") f.write(x) f.close() if utils.pdf_ok(): args["pdf"] = "1" tm.generate_pdf(redir=False) def generate_site(db): utils.mkdirp(confstatic.generate_path) print "<ul><li>"+_("Copie des fichiers latex, de style, ainsi que vos pages personnelles et vos images")+"</li>" ## Updates the latex file (useful for pdf files) #met à jour le latex (utile pour les pdf)
def generate_xhtml(self): """Génération XHTML""" self.generate_header() self.generate_body("xhtml") xhtml_string = self.do_xslt("xhtml") # petit hack dégueulasse : on vire les id ajoutés par lxml qui servent à rien # et changent trop souvent même quand on n'a rien changé dans la page # et donc pourraient générer des conflits qui n'existent pas exp = re.compile(' id="id[0-9]{7}"') xhtml_string = exp.sub('', xhtml_string) i = xhtml_string.index("<div class=\"titlepage\"") #le premier xhtml_string = xhtml_string[:i+22] + " id=\"ie6hack\">" + "<div class=\"sitename\">" + utils.htmlentities(conf_general.title.decode("utf-8")) + "</div>" + xhtml_string[i+23:] i = xhtml_string.index("</head>") fav = confstatic.get_favicon_url() xhtml_string = xhtml_string[:i] + """ <link rel="shortcut icon" href="%s" type="image/x-icon" /> <link rel="icon" href="%s" type="image/x-icon" /> <script type="text/javascript"> sfHover = function() { var sfEls = document.getElementById("Menu").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { //this.className+=" sfhover"; this.className = "sfhover"; } sfEls[i].onmouseout=function() { //this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); this.className = ""; } } } if (window.attachEvent) window.attachEvent("onload", sfHover); </script>""" % (fav,fav) + xhtml_string[i:] args2 = self.args.copy() args2["pdf"] = "1" args2["page"] = self.page+".html" # # if utils.pdf_ok(): # urlpdf = " <a href=\""+confstatic.build_url(args2)+"\">"+_("Version PDF")+"</a>" # else: # urlpdf = "" # # i = xhtml_string.index("</body>") # l1 = """<a href="http://graal.ens-lyon.fr/comfort/"> # <img src="../styles/comfort_thumb.png" style="border-width: 0; margin-top: -31px;" /> # Powered by CoMFoRT !</a>   """ # if confstatic.generating: # l2 = "" # else: # l2 = """ # <a href="admin.py?id=modpage&page_id=%s">%s</a>   # <a href="admin.py">%s</a> # """ % (urllib.quote(self.page), _("Modifier cette page"), _("Panneau d'administration")) # # xhtml_string = xhtml_string[:i] + """ # <div class=\"feet\"> # %s # %s # %s # </div> # """ % (l1, l2, urlpdf) + xhtml_string[i:] count=0 if utils.pdf_ok(): count+=1 if confstatic.generating: count+=1 else: count+=2 width=100/count if utils.pdf_ok(): urlpdf = """<div style=\"width:%d%%; float: left; text-align: center;\"><a href=\"%s\">%s</a></div>"""%(width,confstatic.build_url(args2),_("Version PDF")) else: urlpdf = "" i = xhtml_string.index("</body>") if confstatic.generating: logo = """ <div class="comfort"> <a href="http://graal.ens-lyon.fr/comfort/"> <img src="styles/comfort_thumb.png" style="border-width: 0;" alt="logo de CoMFoRT"/> <br />CoMFoRT </a> </div>""" link = """ <div style=\"text-align: center; width=%d%%; float: left;\"> <a href=\"http://graal.ens-lyon.fr/comfort/\">Powered by CoMFoRT !</a> </div>"""%(width) else: logo = """ <div class="comfort"> <a href="http://graal.ens-lyon.fr/comfort/"> <img src="../styles/comfort_thumb.png" style="border-width: 0;" alt="logo CoMFoRT"/><br /> Powered by CoMFoRT ! </a> </div>""" link = """ <div style=\"float: left; text-align:center; width:%d%%;\"><a href="admin.py?id=modpage&page_id=%s">%s</a></div> <div style=\"float: left; text-align:center; width:%d%%;\"><a href="admin.py">%s</a></div> """ %(width, urllib.quote(self.page), _("Modifier cette page"), width, _("Panneau d'administration")) if not conf_general.display_logo: logo = "" xhtml_string = xhtml_string[:i] + """ %s <div class="feet"> %s %s <div class="spacer"> </div> </div> """ % (logo, link, urlpdf) + xhtml_string[i:] return xhtml_string
def generate_pdf(self, redir=True): """Génération format PDF.""" utils.mkdirp(confstatic.generate_path) self.generate_header() self.generate_body("pdf") if conf_general.pdfmode == "fop": fo_string = self.do_xslt("pdf") (fd, fname) = tempfile.mkstemp(suffix=".xml", text=True) f = os.fdopen(fd, "w") f.write(fo_string) f.close() args2 = self.args.copy() args2["pdf"] = "1" p = subprocess.Popen([confstatic.fop_path, "-fo", fname, "-pdf", os.path.join(confstatic.generate_path, confstatic.build_url(args2))], stdout=subprocess.PIPE, stderr=subprocess.PIPE) r = p.wait() if r: utils.error_page(_("""Impossible de lancer FOP. Code de retour d'erreur : %d. Voici la sortie standard : %s Voici la sortie d'erreur : %s Le fichier xml %s a été gardé (à joindre à tout rapport de bug) """ % (r, p.stdout.read(), p.stderr.read(), fname))) if not r: os.remove(fname) elif conf_general.pdfmode == "latex": (fd, fname) = tempfile.mkstemp(suffix=".xml", text=True) f = os.fdopen(fd, "w") f.write(self.doc_string) f.close() args2 = self.args.copy() args2["pdf"] = "1" if os.name == "nt": dblpath = confstatic.nt_python_path+"python.exe" else: dblpath = confstatic.dblatex_path() p = subprocess.Popen([dblpath, "--pdf", "-s", "db2latex", "-o", os.path.join(confstatic.generate_path, confstatic.build_url(args2)), fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) r = p.wait() if r: utils.error_page(_("""Erreur au lancement de DBLatex. Les raisons possibles sont : - utilisation d'un GIF animé (déconseillé) ; - oubli d'un sous-titre. - mauvais droits (supprimez /tmp/comfortlog (ou c:\\Windows\\TEMP\\comfortlog), rechargez la page, et regardez le contenu du fichier Si vous ne pouvez pas faire autrement, utilisez FOP (à changer dans la configuration). Code de retour d'erreur : %d. Sortie standard : %s Sortie d'erreur : %s Le fichier XML cité ci-dessus a été conservé, donnez-le nous pour tout rapport de bug""" % (r, p.stdout.read(), p.stderr.read()))) if not r: os.remove(fname) if redir and not r: utils.redir("%s/%s" % (confstatic.generate_url,confstatic.build_url(args2)))