示例#1
0
文件: generate.py 项目: vdel/CoMFoRT
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>"
示例#2
0
  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)))
示例#3
0
    def parse_wiki(self, check_links=False, generate_pdf=False, page_id="", chdir=None):
        """
      Parse le wiki en général
      - check_links: si vrai: vérifie les liens internes et renvoit les liens cassés sous la forme (pages, liens, images)
      - page_id: id de la page à parser, sert pour le répertoire où stocker la page
    """
        self.parent = WikiTree("")
        section = WikiTree("")
        self.parent.add(section)
        self.sections = [section, None, None, None, None]
        self.ul_dic = {}
        self.ol_dic = {}
        self.unknow_images = []
        self.unknow_pages = []
        self.unknow_links = []
        self.generated_latex = []
        self.check_links = check_links
        self.generate_pdf = generate_pdf
        self.latex_dir = os.path.join(confstatic.latex_path, page_id)

        self.make_section(2, "")

        utils.mkdirp(self.latex_dir)
        (self.backgnd_cl, self.foregnd_cl) = utils.latex_colors(chdir=chdir)

        while self.scanner.current_token().ttype != "eof":
            t = self.scanner.current_token()
            if t.ttype == "*":
                self.parse_ul()
            elif t.ttype == "#":
                self.parse_ol()
            elif t.ttype == "=":
                self.parse_section()
            elif t.ttype == ":":
                self.parse_tab()
            elif t.ttype == "'":
                self.current.add(self.parse_para())
            elif t.ttype == "space":
                self.current.add(self.parse_code())
            elif t.ttype == "return":
                self.scanner.next_token()
                if self.scanner.current_token().ttype == "return":
                    self.current.add(WikiTree("sbr", single=True))
            elif t.ttype == "[":
                self.current.add(self.parse_para())
            elif t.ttype == "[[":
                self.current.add(self.parse_para())
            elif t.ttype == "{{":
                self.current.add(self.parse_exposant())
            elif t.ttype == "{|":
                self.current.add(self.parse_array())
            elif t.ttype == "tag_open":
                if t.arg in format_tags + list_tags + pos_tags + dont_parse_tags:
                    self.current.add(self.parse_para())
                else:
                    self.current.add(self.parse_tag(all_tags))
            elif t.ttype == "tag":
                self.current.add(self.parse_single_tag(single_tags_para + single_tags_not_para))
            elif t.ttype == "text":
                self.current.add(self.parse_para())
            else:
                texte = ""
                if t.ttype == "]":
                    texte = "]"
                if t.ttype == "]]":
                    texte = "]]"
                if t.ttype == "|}":
                    texte = "|}"
                if t.ttype == "}}":
                    texte = "}}"
                if t.ttype == "|":
                    texte = "|"
                if t.ttype == "|-":
                    texte = "|-"
                if t.ttype == "!":
                    texte = "!"
                if t.ttype == "tag_close":
                    texte = """</%s>""" % t.arg
                self.scanner.next_token()
                if len(self.current.node) > 0:
                    tree = self.current.node[-1]
                    if tree.tag == "":
                        if tree.node[-1].tag == "para":
                            tree.node[-1].add(WikiTree("text", text=texte))
                            self.parse_para(continue_with=tree)
                        else:
                            self.current.add(WikiTree("text", text=texte))
                    else:
                        self.current.add(WikiTree("text", text=texte))
                else:
                    self.current.add(WikiTree("text", text=texte))

        remove_all = True
        images = os.listdir(self.latex_dir)
        for img in images:
            if os.path.isfile(os.path.join(self.latex_dir, img)) and not img in self.generated_latex:
                os.remove(os.path.join(self.latex_dir, img))
            else:
                remove_all = False
        if remove_all:
            try:
                os.rmdir(self.latex_dir)
            except:
                pass
示例#4
0
文件: handler.py 项目: vdel/CoMFoRT
sys.path.append(os.getcwd())

import cgi
import urllib

from conf import confstatic
sys.path = [confstatic.config_path]+sys.path

from conf import utils

try:
  import conf_general
  import conf_private
except:
  for d in [confstatic.config_path, confstatic.perso_path, confstatic.pages_path, confstatic.docs_path, ]:
    utils.mkdirp(d)
  open(os.path.join(confstatic.config_path, '__init__.py'), 'w').close()

  fconf = open(os.path.join(confstatic.config_path, "conf_general.py"), 'w+')
  fconf.write("# -*- encoding: utf-8 -*-\n\n#ATTENTION : Ce fichier est genere par interface/valid_form.py\n\n")
  fconf.write("title = \"\"\n")
  fconf.write("language = \"\"\n")
  fconf.write("style = \"officiels_serious\"\n")
  fconf.write("\n")
  fconf.write("installed = 0\n")
  fconf.write("pdfmode = \"none\"\n")
  fconf.write("adminstyle = \"admin2.css\"\n")
  fconf.write("display_logo = 0\n")
  fconf.close()

  fconf = open(os.path.join(confstatic.config_path, "conf_private.py"), 'w+')
示例#5
0
    pass


def _keep_running():
  """
  Wait for server stop signal.
  """
  file = open('running', 'w')
  file.write('1')
  file.close()

  while 1:
    time.sleep(1)

    file = open('running', 'r')
    r = file.read()
    file.close()
    if r != '1':
      break


if __name__ == '__main__':
  import sys; sys.path.append('.');
  from conf import confstatic
  from conf import utils
  utils.mkdirp(confstatic.config_path)
  os.chdir(confstatic.config_path)
  sys.path.pop()
  _launch_server('', confstatic.get_user_server_port())
  _keep_running()