def getTranslator(doc): """Find a translator for the given document.""" # find the language lang = doc.getVar('LANG') if not lang: lang, _ = locale.getdefaultlocale() sys.stderr.write("INFO: using default language: " + lang + "\n") nlang = string.lower(lang).replace('-', '_') # look for the local version path = os.path.join(doc.getVar('THOT_BASE'), "langs") mod = common.loadModule(nlang, path) if mod: return mod.getTranslator(doc, nlang) # look for the global version comps = nlang.split('_') if comps[0] == 'en': return DefaultTranslator() else: mod = common.loadModule(comps[0], path) if mod: return mod.getTranslator(doc, comps[0]) else: sys.stderr.write('WARNING: cannot find language ' + nlang + "\n") return DefaultTranslator()
def use(self, name): """Use a module in the current parser.""" if name in self.used_mods: return path = self.doc.getVar("THOT_USE_PATH") mod = common.loadModule(name, path) if mod: self.used_mods.append(mod) mod.init(self) # new syntax? if mod.__dict__.has_key("__syntax__"): lines = [] words = [] if mod.__dict__.has_key("__lines__"): lines = mod.__lines__ if mod.__dict__.has_key("__words__"): words = mod.__words__ self.setSyntax( [(l[0], re.compile(l[1])) for l in lines], [(w[0], w[1]) for w in words]) # simple extension else: if mod.__dict__.has_key("__lines__"): for line in mod.__lines__: self.addLine((line[0], re.compile(line[1]))) if mod.__dict__.has_key("__words__"): for word in mod.__words__: self.addWord((word[0], word[1])) else: common.onError('cannot load module %s' % name)
def use(self, name): """Use a module in the current parser.""" if name in self.used_mods: return path = self.doc.getVar("THOT_USE_PATH") mod = common.loadModule(name, path) if mod: self.used_mods.append(mod) mod.init(self) # new syntax? if mod.__dict__.has_key("__syntax__"): lines = [] words = [] if mod.__dict__.has_key("__lines__"): lines = mod.__lines__ if mod.__dict__.has_key("__words__"): words = mod.__words__ self.setSyntax([(l[0], re.compile(l[1])) for l in lines], [(w[0], w[1]) for w in words]) # simple extension else: if mod.__dict__.has_key("__lines__"): for line in mod.__lines__: self.addLine((line[0], re.compile(line[1]))) if mod.__dict__.has_key("__words__"): for word in mod.__words__: self.addWord((word[0], word[1])) else: common.onError('cannot load module %s' % name)
env["THOT_DOC_DIR"] = os.path.dirname(args[0]) if not env["THOT_DOC_DIR"]: env["THOT_DOC_DIR"] = "." if options.defines: for d in options.defines: p = d.find('=') if p == -1: common.onError('-D' + d + ' must follow syntax -Didentifier=value') else: env[d[:p]] = d[p + 1:] # open the output document = doc.Document(env) out_name = env["THOT_OUT_TYPE"] out_path = os.path.join(document.env["THOT_BASE"], "backs") out_driver = common.loadModule(out_name, out_path) if not out_driver: common.onError('cannot find %s back-end' % out_name) # Parse the file man = tparser.Manager(document) if out_driver.__dict__.has_key("init"): out_driver.init(man) if options.uses: for u in options.uses: man.use(u) man.parse(input, env['THOT_FILE']) # dump the parsed document if options.dump: document.dump("")
env["THOT_DOC_DIR"] = os.path.dirname(args[0]) if not env["THOT_DOC_DIR"]: env["THOT_DOC_DIR"] = "." if options.defines: for d in options.defines: p = d.find('=') if p == -1: common.onError('-D' + d + ' must follow syntax -Didentifier=value') else: env[d[:p]] = d[p+1:] # open the output document = doc.Document(env) out_name = env["THOT_OUT_TYPE"] out_path = os.path.join(document.env["THOT_BASE"], "backs") out_driver = common.loadModule(out_name, out_path) if not out_driver: common.onError('cannot find %s back-end' % out_name) # Parse the file man = tparser.Manager(document) if out_driver.__dict__.has_key("init"): out_driver.init(man) if options.uses: for u in options.uses: man.use(u) man.parse(input, env['THOT_FILE']) # dump the parsed document if options.dump: document.dump("")
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os import os.path import back import common import cgi ZIP = common.Command("zip", "unzip unavaible to build the final archive", common.ERROR_FAIL) # get the html module out_path = os.path.dirname(__file__) html = common.loadModule("html", out_path) if not html: common.onError("cannot found html backend !") # SCORM generator class ScormGenerator(html.Generator): def __init__(self, doc): html.Generator.__init__(self, doc) def genTitle(self): """No title.""" pass def genContent(self, max=7, out=False): """No content."""