Esempio n. 1
0
    def create_files(self):
        self.update_options()
        if self.options["location"]:
            loc = path(self.options["location"])
            if loc.basename() != self.name:
                pth_langlet = loc.joinpath(self.name)
            else:
                pth_langlet = loc
        else:
            pth_langlet = langlets_path.joinpath(self.name)

        self.new_langlet_pth = pth_langlet
        if pth_langlet.exists():
            raise IOError("Langlet directory already exists: '%s'"%pth_langlet)
        try:
            pth_langlet_module = pth_langlet.joinpath("langlet.py")

            count  = self.create_new_langlet_counter()
            lnlt_id = count*(10**4)

            pth_template = parent_path.joinpath("langlet_template")
            pth_conf = pth_template.joinpath("langlet_config.strtempl")

            pth_langlet_py = pth_template.joinpath("langlet.strtempl")
            langlet_py = ""

            pth_template.copytree(pth_langlet)

            if self.options["parent"]:
                parent_langlet   = path(loader.find_langlet(self.options["parent"])[1].__file__).dirname()
                grammar_gen_path = parent_langlet.joinpath("parsedef", "GrammarGen.g")
                grammar_gen_path.copy(pth_langlet.joinpath("parsedef", "GrammarBase.g"))
                token_gen_path = parent_langlet.joinpath("lexdef", "TokenGen.g")
                token_gen_path.copy(pth_langlet.joinpath("lexdef", "TokenBase.g"))

            # operate on destination folder...
            pth_conf = pth_langlet.joinpath("langlet_config.py")
            pth_conf_template = pth_langlet.joinpath("langlet_config.strtempl")
            with open(pth_conf,"w") as f_conf:
                f_conf.write(self.create_langlet_config_py(lnlt_id, pth_conf_template))
            pth_langlet.joinpath("run.py").rename(pth_langlet.joinpath("run_"+self.name+".py"))
            pth_langlet.joinpath("langlet_config.strtempl").remove()

            # update LANGLET_ID in lex_token.py
            pth_lex_token = pth_langlet.joinpath("lexdef","lex_token.py")
            pth_lex_token_template = path(pth_lex_token.replace(".py",".strtempl"))
            with open(pth_lex_token, "w") as f_lex:
                f_lex.write(self.update_lex_token(lnlt_id, pth_lex_token_template))

            self.create_langlet_data(pth_conf)
            pth_lex_token_template.remove()
        except Exception, e:
            print get_traceback()
            self.new_langlet_pth.rmtree()
            exit(2)
Esempio n. 2
0
 def showtraceback(self):
     self.write(get_traceback())
Esempio n. 3
0
 def showtraceback(self):
     self.write(get_traceback())