def run (self): """ This method actually runs BibTeX with the appropriate environment variables set. """ msg.progress(_("running BibTeX on %s") % msg.simplify(self.base)) doc = {} if len(self.bib_path) != 1: doc["BIBINPUTS"] = string.join(self.bib_path + [os.getenv("BIBINPUTS", "")], ":") if len(self.bst_path) != 1: doc["BSTINPUTS"] = string.join(self.bst_path + [os.getenv("BSTINPUTS", "")], ":") if self.crossrefs is None: cmd = ["bibtex"] else: cmd = ["bibtex", "-min-crossrefs=" + self.crossrefs] cmd.append(self.doc.env.file_name(self.base)) msg.log(_("executing: %s") % " ".join(cmd), pkg="bibtex") process = Popen(cmd, stdout=PIPE, stderr=PIPE) process.communicate() if process.wait() != 0: msg.info(_("There were errors making the bibliography.")) return False self.run_needed = 0 self.doc.must_compile = 1 return True
def hook_externaldocument(loc, opt, name): aux = doc.env.find_file(name + ".aux") if aux: doc.add_source(aux) msg.log(_("dependency %s added for external references") % aux, pkg="xr") else: msg.log(_("file %s is required by xr package but not found") % aux, pkg="xr")
def hook_declareRule(self, loc, ext, type, read, command): if read in self.suffixes: return self.suffixes.insert(0, read) msg.log("*** FIXME *** rule %s -> %s [%s]" % (string.strip(ext), read, type), pkg='graphics')
def clean (): for bib in bibs.keys(): for suffix in '.aux', '.bbl', '.blg': file = bib + suffix if os.path.exists(file): msg.log(_("removing %s") % file, pkg='multibib') os.unlink(file)
def clean(self): self.doc.remove_suffixes([".pytxcode"]) pythontex_files = 'pythontex-files-' + os.path.basename( self.doc.target) if os.path.exists(pythontex_files): msg.log(_("removing tree %s") % pythontex_files) shutil.rmtree(pythontex_files)
def clean (self): """ Remove all generated files related to the index. """ for file in self.source, self.target, self.transcript: if os.path.exists(file): msg.log(_("removing %s") % file, pkg="index") os.unlink(file)
def clean(self): """ Remove all generated files related to the index. """ for file in self.source, self.target, self.transcript: if os.path.exists(file): msg.log(_("removing %s") % file, pkg="index") os.unlink(file)
def slatex_needed(target, srcs): if not exists(target): msg.log(_("File %s does not exist") % target, pkg="slatex") return 1 for src in srcs: if getmtime(target) < getmtime(src): msg.log(_("File %s older than %s") % (target, src), pkg="slatex") return 1 return 0
def hook_externaldocument(loc, opt, name): aux = doc.env.find_file(name + '.aux') if aux: doc.add_source(aux) msg.log(_("dependency %s added for external references") % aux, pkg='xr') else: msg.log(_("file %s is required by xr package but not found") % aux, pkg='xr')
def hook_externaldocument (self, loc, opt, name): aux = self.doc.env.find_file(name + '.aux') if aux: self.doc.add_source(aux) msg.log( _( "dependency %s added for external references") % aux, pkg='xr') else: msg.log(_( "file %s.aux is required by xr package but not found") % name, pkg='xr')
def post_compile (self): """ This method runs BibTeX if needed to solve undefined citations. If it was run, then force a new LaTeX compilation. """ if not self.bibtex_needed(): msg.log(_("no BibTeXing needed"), pkg="bibtex") return True return self.run()
def add_scheme_file(dict, others=[]): filename = ".Z" + str(self.count) + self.base + ".tex" path = join(self.path, filename) deps = [dict["pos"]["file"]] if others: deps.extend(others) self.doc.sources[path] = RubberDep(self, path, deps) msg.log(_("Marking %s as dependent on %s") % (path, deps), pkg = "slatex") self.count += 1
def post_compile(self): """ This method runs BibTeX if needed to solve undefined citations. If it was run, then force a new LaTeX compilation. """ if not self.bibtex_needed(): msg.log(_("no BibTeXing needed"), pkg="bibtex") return True return self.run()
def pre_compile(self): # Pre-compilation means running all needed conversions. This is not done # through the standard dependency mechanism because we do not want to # interrupt compilation when a graphic is not found. for node in self.files: if not node.making: node.make() else: msg.log("*** FIXME *** recursive making in graphics: %s" % str(node.products), pkg="graphics") return True
def add_scheme_file(dict, others=[]): filename = ".Z" + str(self.count) + self.base + ".tex" path = join(self.path, filename) deps = [dict["pos"]["file"]] if others: deps.extend(others) self.doc.sources[path] = RubberDep(self, path, deps) msg.log(_("Marking %s as dependent on %s") % (path, deps), pkg="slatex") self.count += 1
def clean(): doc.remove_suffixes([".bmt"]) base = doc.target + "." ln = len(base) for file in os.listdir("."): if file[:ln] == base: ext = file[ln:] m = re_tocext.match(ext) if m and ext[m.end() :] == "": msg.log(_("removing %s") % file, pkg="minitoc") os.unlink(file)
def post_compile(self): """ Run makeindex if needed, with appropriate options and environment. """ if not os.path.exists(self.source): msg.log(_("strange, there is no %s") % self.source, pkg="index") return True if not self.run_needed(): return True msg.progress(_("processing index %s") % msg.simplify(self.source)) if self.tool == "makeindex": cmd = ["makeindex", "-q", "-o", self.target] + self.opts cmd.extend(["-t", self.transcript]) if self.style: cmd.extend(["-s", self.style]) cmd.append(self.source) path_var = "INDEXSTYLE" elif self.tool == "xindy": cmd = ["texindy", "--quiet"] for opt in self.opts: if opt == "-g": if self.lang != "": msg.warn(_("'language' overrides 'order german'"), pkg="index") else: self.lang = "german-din" elif opt == "-l": self.modules.append("letter-ordering") msg.warn(_( "use 'module letter-ordering' instead of 'order letter'" ), pkg="index") else: msg.error("unknown option to xindy: %s" % opt, pkg="index") for mod in self.modules: cmd.extend(["--module", mod]) if self.lang: cmd.extend(["--language", self.lang]) cmd.append(self.source) path_var = "XINDY_SEARCHPATH" if self.path != []: env = {path_var: ':'.join(self.path + [os.getenv(path_var, '')])} else: env = {} if self.doc.env.execute(cmd, env): msg.error(_("could not make index %s") % self.target) return False self.doc.must_compile = 1 return True
def clean(): doc.remove_suffixes(['.bmt']) base = doc.target + '.' ln = len(base) for file in os.listdir('.'): if file[:ln] == base: ext = file[ln:] m = re_tocext.match(ext) if m and ext[m.end():] == "": msg.log(_("removing %s") % file, pkg='minitoc') os.unlink(file)
def hook_newcites(self, loc, name): self.doc.add_product(name + ".aux") bib = self.bibs[name] = rubber.biblio.BibTeXDep(self.doc, name) self.doc.hook_macro('bibliography' + name, 'a', bib.hook_bibliography) self.doc.hook_macro('bibliographystyle' + name, 'a', bib.hook_bibliographystyle) for cmd in self.defaults: bib.bib_command(*cmd) if name in self.commands: for cmd in self.commands[name]: bib.bib_command(*cmd) msg.log(_("bibliography %s registered") % name, pkg='multibib')
def hook_newcites (loc, name): bib = bibs[name] = Bibliography(doc, name) doc.hook_macro('bibliography' + name, 'a', bib.hook_bibliography) doc.hook_macro('bibliographystyle' + name, 'a', bib.hook_bibliographystyle) for cmd in defaults: bib.command(*cmd) if name in commands: for cmd in commands[name]: bib.command(*cmd) msg.log(_("bibliography %s registered") % name, pkg='multibib')
def post_compile (self): """ Run makeindex if needed, with appropriate options and environment. """ if not os.path.exists(self.source): msg.log(_("strange, there is no %s") % self.source, pkg="index") return True if not self.run_needed(): return True msg.progress(_("processing index %s") % msg.simplify(self.source)) if self.tool == "makeindex": cmd = ["makeindex", "-q", "-o", self.target] + self.opts cmd.extend(["-t", self.transcript]) if self.style: cmd.extend(["-s", self.style]) cmd.append(self.source) path_var = "INDEXSTYLE" elif self.tool == "xindy": cmd = ["texindy", "--quiet"] for opt in self.opts: if opt == "-g": if self.lang != "": msg.warn(_("'language' overrides 'order german'"), pkg="index") else: self.lang = "german-din" elif opt == "-l": self.modules.append("letter-ordering") msg.warn(_("use 'module letter-ordering' instead of 'order letter'"), pkg="index") else: msg.error("unknown option to xindy: %s" % opt, pkg="index") for mod in self.modules: cmd.extend(["--module", mod]) if self.lang: cmd.extend(["--language", self.lang]) cmd.append(self.source) path_var = "XINDY_SEARCHPATH" if self.path != []: env = { path_var: ':'.join(self.path + [os.getenv(path_var, '')]) } else: env = {} if self.doc.env.execute(cmd, env): msg.error(_("could not make index %s") % self.target) return False self.doc.must_compile = 1 return True
def hook_newcites (self, loc, name): self.doc.add_product (name + ".aux") bib = self.bibs [name] = rubber.biblio.BibTeXDep (self.doc, name) self.doc.hook_macro('bibliography' + name, 'a', bib.hook_bibliography) self.doc.hook_macro('bibliographystyle' + name, 'a', bib.hook_bibliographystyle) for cmd in self.defaults: bib.bib_command (*cmd) if name in self.commands: for cmd in self.commands [name]: bib.bib_command (*cmd) msg.log(_("bibliography %s registered") % name, pkg='multibib')
def hook_includegraphics(self, loc, starred, optional, name): # no suffixes are tried when the extension is explicit allowed_suffixes = self.suffixes options = parse_keyval(optional) if 'ext' in options: allowed_suffixes = [''] if options['ext']: name = name + options['ext'] for suffix in self.suffixes: if name[-len(suffix):] == suffix: allowed_suffixes = [''] break # If the file name looks like it contains a control sequence or a macro # argument, forget about this \includegraphics. if name.find('\\') >= 0 or name.find('#') >= 0: return # We only accept conversions from file types we don't know and cannot # produce. def check(vars): source = vars['source'] if os.path.exists( vars['target']) and self.doc.env.may_produce(source): return False if self.suffixes == ['']: return True for suffix in allowed_suffixes: if source[-len(suffix):] == suffix: return False return True node = self.doc.env.convert(name, suffixes=allowed_suffixes, prefixes=self.prefixes, check=check, context=self.doc.vars) if node: msg.log(_("graphics `%s' found") % name, pkg='graphics') for file in node.products: self.doc.add_source(file) self.files.append(node) else: msg.warn(_("graphics `%s' not found") % name, **dict(loc))
def hook_includegraphics(self, loc, starred, optional, name): # no suffixes are tried when the extension is explicit allowed_suffixes = self.suffixes options = parse_keyval(optional) if "ext" in options: allowed_suffixes = [""] if options["ext"]: name = name + options["ext"] for suffix in self.suffixes: if name[-len(suffix) :] == suffix: allowed_suffixes = [""] break # If the file name looks like it contains a control sequence or a macro # argument, forget about this \includegraphics. if name.find("\\") >= 0 or name.find("#") >= 0: return # We only accept conversions from file types we don't know and cannot # produce. def check(vars): source = vars["source"] if os.path.exists(vars["target"]) and self.doc.env.may_produce(source): return False if self.suffixes == [""]: return True for suffix in allowed_suffixes: if source[-len(suffix) :] == suffix: return False return True node = self.doc.env.convert( name, suffixes=allowed_suffixes, prefixes=self.prefixes, check=check, context=self.doc.vars ) if node: msg.log(_("graphics `%s' found") % name, pkg="graphics") for file in node.products: self.doc.add_source(file) self.files.append(node) else: msg.warn(_("graphics `%s' not found") % name, **dict(loc))
def style_changed (self): """ Read the log file if it exists and check if the style used is the one specified in the source. This supposes that the style is mentioned on a line with the form 'The style file: foo.bst'. """ blg = self.base + ".blg" if not exists(blg): return 0 log = open(blg) line = log.readline() while line != "": if line[:16] == "The style file: ": if line.rstrip()[16:-4] != self.style: msg.log(_("the bibliography style was changed"), pkg="bibtex") log.close() return 1 line = log.readline() log.close() return 0
def first_run_needed(self): """ The condition is only on the database files' modification dates, but it would be more clever to check if the results have changed. BibTeXing is also needed when the last run of BibTeX failed, and in the very particular case when the style has changed since last compilation. """ if not exists(self.base + ".aux"): return 0 if not exists(self.base + ".blg"): return 1 dtime = getmtime(self.base + ".blg") for db in self.db.values(): if getmtime(db) > dtime: msg.log(_("bibliography database %s was modified") % db, pkg="bibtex") return 1 blg = open(self.base + ".blg") for line in blg.readlines(): if re_error.search(line): blg.close() msg.log(_("last BibTeXing failed"), pkg="bibtex") return 1 blg.close() if self.style_changed(): return 1 if self.bst_file and getmtime(self.bst_file) > dtime: msg.log(_("the bibliography style file was modified"), pkg="bibtex") return 1 return 0
def first_run_needed (self): """ The condition is only on the database files' modification dates, but it would be more clever to check if the results have changed. BibTeXing is also needed when the last run of BibTeX failed, and in the very particular case when the style has changed since last compilation. """ if not exists(self.base + ".aux"): return 0 if not exists(self.base + ".blg"): return 1 dtime = getmtime(self.base + ".blg") for db in self.db.values(): if getmtime(db) > dtime: msg.log(_("bibliography database %s was modified") % db, pkg="bibtex") return 1 blg = open(self.base + ".blg") for line in blg.readlines(): if re_error.search(line): blg.close() msg.log(_("last BibTeXing failed"), pkg="bibtex") return 1 blg.close() if self.style_changed(): return 1 if self.bst_file and getmtime(self.bst_file) > dtime: msg.log(_("the bibliography style file was modified"), pkg="bibtex") return 1 return 0
def run_needed (self): """ Check if makeindex has to be run. This is the case either if the target file does not exist or if the source file has changed. """ if not os.path.exists(self.target): self.md5 = md5_file(self.source) return 1 if not self.md5: self.md5 = md5_file(self.source) msg.log(_("the index file %s is new") % self.source, pkg="index") return 1 new = md5_file(self.source) if self.md5 == new: msg.log(_("the index %s did not change") % self.source, pkg="index") return 0 self.md5 = new msg.log(_("the index %s has changed") % self.source, pkg="index") return 1
def run_needed(self): """ Check if makeindex has to be run. This is the case either if the target file does not exist or if the source file has changed. """ if not os.path.exists(self.target): self.md5 = md5_file(self.source) return 1 if not self.md5: self.md5 = md5_file(self.source) msg.log(_("the index file %s is new") % self.source, pkg="index") return 1 new = md5_file(self.source) if self.md5 == new: msg.log(_("the index %s did not change") % self.source, pkg="index") return 0 self.md5 = new msg.log(_("the index %s has changed") % self.source, pkg="index") return 1
def hook_newindex(loc, index, idx, ind): register(index, idx, ind, 'ilg') msg.log(_("index %s registered") % index, pkg='index')
def hook_declareRule(self, loc, ext, type, read, command): if read in self.suffixes: return self.suffixes.insert(0, read) msg.log("*** FIXME *** rule %s -> %s [%s]" % (string.strip(ext), read, type), pkg="graphics")
def main(self, cmdline): """ Run Rubber as a pipe for the specified command line. This dumps the standard input into a temporary file, compiles it, dumps the result on standard output, and then removes the files if requested. If an error happens while building the document, the process stops. The method returns the program's exit code. """ self.prologue = [] self.epilogue = [] self.clean = 1 self.place = "." self.path = [] self.parse_opts(cmdline) msg.log(_("This is Rubber version %s.") % version) # Put the standard input in a file initial_dir = os.getcwd() if self.place is not None and self.place != ".": self.path.insert(0, initial_dir) os.chdir(self.place) src = make_name() + ".tex" try: srcfile = open(src, "w") except IOError: msg.error(_("cannot create temporary files")) return 1 msg.progress(_("saving the input in %s") % src) dump_file(sys.stdin, srcfile) srcfile.close() # Make the document env = Environment() env.vars["cwd"] = initial_dir if env.set_source(src): msg.error(_("cannot open the temporary %s") % src) return 1 if self.include_only is not None: env.main.includeonly(self.include_only) env.make_source() for dir in self.path: env.main.do_path(dir) for cmd in self.prologue: cmd = parse_line(cmd, {}) env.main.command(cmd[0], cmd[1:], {"file": "command line"}) env.main.parse() for cmd in self.epilogue: cmd = parse_line(cmd, {}) env.main.command(cmd[0], cmd[1:], {"file": "command line"}) ret = env.final.make() if ret == ERROR: msg.info(_("There were errors.")) number = self.max_errors for err in env.final.failed().get_errors(): if number == 0: msg.info(_("More errors.")) break msg.display(**err) number -= 1 return 1 # Dump the results on standard output output = open(env.final.products[0]) dump_file(output, sys.stdout) # Clean the intermediate files if self.clean: env.final.clean() os.unlink(src) return 0
def main(self, cmdline): """ Run Rubber as a pipe for the specified command line. This dumps the standard input into a temporary file, compiles it, dumps the result on standard output, and then removes the files if requested. If an error happens while building the document, the process stops. The method returns the program's exit code. """ self.prologue = [] self.epilogue = [] self.clean = 1 self.place = "." self.path = [] self.parse_opts(cmdline) msg.log(_("This is Rubber version %s.") % version) # Put the standard input in a file initial_dir = os.getcwd() if self.place is not None and self.place != ".": self.path.insert(0, initial_dir) os.chdir(self.place) src = make_name() + ".tex" try: srcfile = open(src, 'w') except IOError: msg.error(_("cannot create temporary files")) return 1 msg.progress(_("saving the input in %s") % src) dump_file(sys.stdin, srcfile) srcfile.close() # Make the document env = Environment() env.vars["cwd"] = initial_dir if env.set_source(src): msg.error(_("cannot open the temporary %s") % src) return 1 if self.include_only is not None: env.main.includeonly(self.include_only) env.make_source() for dir in self.path: env.main.do_path(dir) for cmd in self.prologue: cmd = parse_line(cmd, {}) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) env.main.parse() for cmd in self.epilogue: cmd = parse_line(cmd, {}) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) ret = env.final.make() if ret == ERROR: msg.info(_("There were errors.")) number = self.max_errors for err in env.final.failed().get_errors(): if number == 0: msg.info(_("More errors.")) break msg.display(**err) number -= 1 return 1 # Dump the results on standard output output = open(env.final.products[0]) dump_file(output, sys.stdout) # Clean the intermediate files if self.clean: env.final.clean() os.unlink(src) return 0
def bibtex_needed(self): """ Return true if BibTeX must be run. """ if self.run_needed: return 1 msg.log(_("checking if BibTeX must be run..."), pkg="bibtex") new, dbs = self.parse_aux() # If there was a list of used citations, we check if it has # changed. If it has, we have to rerun. if self.prev_dbs is not None and self.prev_dbs != dbs: msg.log(_("the set of databases changed"), pkg="bibtex") self.prev_dbs = dbs self.used_cites = new self.undef_cites = self.list_undefs() return 1 self.prev_dbs = dbs # If there was a list of used citations, we check if it has # changed. If it has, we have to rerun. if self.used_cites: if new != self.used_cites: msg.log(_("the list of citations changed"), pkg="bibtex") self.used_cites = new self.undef_cites = self.list_undefs() return 1 self.used_cites = new # If there was a list of undefined citations, we check if it has # changed. If it has and it is not empty, we have to rerun. if self.undef_cites: new = self.list_undefs() if new == []: msg.log(_("no more undefined citations"), pkg="bibtex") self.undef_cites = new else: for cite in new: if cite in self.undef_cites: continue msg.log(_("there are new undefined citations"), pkg="bibtex") self.undef_cites = new return 1 msg.log(_("there is no new undefined citation"), pkg="bibtex") self.undef_cites = new return 0 else: self.undef_cites = self.list_undefs() # At this point we don't know if undefined citations changed. If # BibTeX has not been run before (i.e. there is no log file) we know # that it has to be run now. blg = self.base + ".blg" if not exists(blg): msg.log(_("no BibTeX log file"), pkg="bibtex") return 1 # Here, BibTeX has been run before but we don't know if undefined # citations changed. if self.undef_cites == []: msg.log(_("no undefined citations"), pkg="bibtex") return 0 log = self.doc.target + ".log" if getmtime(blg) < getmtime(log): msg.log(_("BibTeX's log is older than the main log"), pkg="bibtex") return 1 return 0
def bibtex_needed (self): """ Return true if BibTeX must be run. """ if self.run_needed: return 1 msg.log(_("checking if BibTeX must be run..."), pkg="bibtex") new, dbs = self.parse_aux() # If there was a list of used citations, we check if it has # changed. If it has, we have to rerun. if self.prev_dbs is not None and self.prev_dbs != dbs: msg.log(_("the set of databases changed"), pkg="bibtex") self.prev_dbs = dbs self.used_cites = new self.undef_cites = self.list_undefs() return 1 self.prev_dbs = dbs # If there was a list of used citations, we check if it has # changed. If it has, we have to rerun. if self.used_cites: if new != self.used_cites: msg.log(_("the list of citations changed"), pkg="bibtex") self.used_cites = new self.undef_cites = self.list_undefs() return 1 self.used_cites = new # If there was a list of undefined citations, we check if it has # changed. If it has and it is not empty, we have to rerun. if self.undef_cites: new = self.list_undefs() if new == []: msg.log(_("no more undefined citations"), pkg="bibtex") self.undef_cites = new else: for cite in new: if cite in self.undef_cites: continue msg.log(_("there are new undefined citations"), pkg="bibtex") self.undef_cites = new return 1 msg.log(_("there is no new undefined citation"), pkg="bibtex") self.undef_cites = new return 0 else: self.undef_cites = self.list_undefs() # At this point we don't know if undefined citations changed. If # BibTeX has not been run before (i.e. there is no log file) we know # that it has to be run now. blg = self.base + ".blg" if not exists(blg): msg.log(_("no BibTeX log file"), pkg="bibtex") return 1 # Here, BibTeX has been run before but we don't know if undefined # citations changed. if self.undef_cites == []: msg.log(_("no undefined citations"), pkg="bibtex") return 0 log = self.doc.target + ".log" if getmtime(blg) < getmtime(log): msg.log(_("BibTeX's log is older than the main log"), pkg="bibtex") return 1 return 0
def clean (self): self.doc.remove_suffixes([".pytxcode"]) pythontex_files = 'pythontex-files-' + os.path.basename(self.doc.target) if os.path.exists(pythontex_files): msg.log(_("removing tree %s") % pythontex_files) shutil.rmtree(pythontex_files)
def hook_newindex (loc, index, idx, ind): register(index, idx, ind, 'ilg') msg.log(_("index %s registered") % index, pkg='index')
def main(self, cmdline): """ Run Rubber for the specified command line. This processes each specified source in order (for making or cleaning). If an error happens while making one of the documents, the whole process stops. The method returns the program's exit code. """ self.jobname = None self.prologue = [] self.epilogue = [] self.clean = 0 self.force = 0 self.shell_escape = 0 self.warn = 0 self.warn_boxes = 0 self.warn_misc = 0 self.warn_refs = 0 self.place = "." args = self.parse_opts(cmdline) initial_dir = os.getcwd() msg.cwd = os.path.join(initial_dir, "") if self.place != "." and self.place is not None: msg.path = self.place self.place = os.path.abspath(self.place) msg.log(_("This is Rubber version %s.") % version) for srcname in args: src = os.path.abspath(os.path.join(initial_dir, srcname)) # Go to the appropriate directory if self.place != ".": if self.place is None: msg.path = os.path.dirname(src) os.chdir(os.path.dirname(src)) src = os.path.basename(src) else: os.chdir(self.place) # Check the source and prepare it for processing env = Environment() env.vars.new_key('shell_escape', self.shell_escape) if env.set_source(src, jobname=self.jobname): return 1 self.jobname = None if self.include_only is not None: env.main.includeonly(self.include_only) if self.clean: if env.main.products == []: msg.warn(_("there is no LaTeX source for %s") % srcname) continue else: env.make_source() saved_vars = env.main.vars env.main.vars = Variables(saved_vars, {"cwd": initial_dir}) for dir in self.path: env.main.do_path(dir) for cmd in self.prologue: cmd = parse_line(cmd, env.main.vars) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) env.main.vars = saved_vars env.main.parse() saved_vars = env.main.vars env.main.vars = Variables(saved_vars, {"cwd": initial_dir}) for cmd in self.epilogue: cmd = parse_line(cmd, env.main.vars) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) env.main.vars = saved_vars if self.compress is not None: last_node = env.final filename = last_node.products[0] if self.compress == 'gzip': from rubber.converters.gz import GzipDep env.final = GzipDep(env.depends, filename + '.gz', filename) elif self.compress == 'bzip2': from rubber.converters.bzip2 import Bzip2Dep env.final = Bzip2Dep(env.depends, filename + '.bz2', filename) # Compile the document if self.clean: env.final.clean() continue if self.force: ret = env.main.make(True) if ret != ERROR and env.final is not env.main: ret = env.final.make() else: # This is a hack for the call to get_errors() below # to work when compiling failed when using -f. env.final.failed_dep = env.main.failed_dep else: ret = env.final.make(self.force) if ret == ERROR: msg.info(_("There were errors compiling %s.") % srcname) number = self.max_errors for err in env.final.failed().get_errors(): if number == 0: msg.info(_("More errors.")) break msg.display(**err) number -= 1 return 1 if ret == UNCHANGED: msg(1, _("nothing to be done for %s") % srcname) if self.warn: log = env.main.log if log.read(env.main.target + ".log"): msg.error(_("cannot read the log file")) return 1 msg.display_all( log.parse(boxes=self.warn_boxes, refs=self.warn_refs, warnings=self.warn_misc)) return 0
def main (self, cmdline): """ Run Rubber for the specified command line. This processes each specified source in order (for making or cleaning). If an error happens while making one of the documents, the whole process stops. The method returns the program's exit code. """ self.jobname = None self.prologue = [] self.epilogue = [] self.clean = 0 self.force = 0 self.warn = 0 self.warn_boxes = 0 self.warn_misc = 0 self.warn_refs = 0 self.place = "." args = self.parse_opts(cmdline) initial_dir = os.getcwd() msg.cwd = os.path.join(initial_dir, "") if self.place != "." and self.place is not None: msg.path = self.place self.place = os.path.abspath(self.place) msg.log(_("This is Rubber version %s.") % version) for srcname in args: src = os.path.abspath(os.path.join(initial_dir, srcname)) # Go to the appropriate directory if self.place != ".": if self.place is None: msg.path = os.path.dirname(src) os.chdir(os.path.dirname(src)) src = os.path.basename(src) else: os.chdir(self.place) # Check the source and prepare it for processing env = Environment() if env.set_source(src, jobname=self.jobname): return 1 self.jobname = None if self.include_only is not None: env.main.includeonly(self.include_only) if self.clean: if env.main.products == []: msg.warn(_("there is no LaTeX source for %s") % srcname) continue else: env.make_source() saved_vars = env.main.vars env.main.vars = Variables(saved_vars, { "cwd": initial_dir }) for dir in self.path: env.main.do_path(dir) for cmd in self.prologue: cmd = parse_line(cmd, env.main.vars) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) env.main.vars = saved_vars env.main.parse() saved_vars = env.main.vars env.main.vars = Variables(saved_vars, { "cwd": initial_dir }) for cmd in self.epilogue: cmd = parse_line(cmd, env.main.vars) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) env.main.vars = saved_vars if self.compress is not None: last_node = env.final filename = last_node.products[0] if self.compress == 'gzip': from rubber.converters.gz import GzipDep env.final = GzipDep(env.depends, filename + '.gz', filename) elif self.compress == 'bzip2': from rubber.converters.bzip2 import Bzip2Dep env.final = Bzip2Dep(env.depends, filename + '.bz2', filename) # Compile the document if self.clean: env.final.clean() continue if self.force: ret = env.main.make(True) if ret != ERROR and env.final is not env.main: ret = env.final.make() else: # This is a hack for the call to get_errors() below # to work when compiling failed when using -f. env.final.failed_dep = env.main.failed_dep else: ret = env.final.make(self.force) if ret == ERROR: msg.info(_("There were errors compiling %s.") % srcname) number = self.max_errors for err in env.final.failed().get_errors(): if number == 0: msg.info(_("More errors.")) break msg.display(**err) number -= 1 return 1 if ret == UNCHANGED: msg(1, _("nothing to be done for %s") % srcname) if self.warn: log = env.main.log if log.read(env.main.target + ".log"): msg.error(_("cannot read the log file")) return 1 msg.display_all(log.parse(boxes=self.warn_boxes, refs=self.warn_refs, warnings=self.warn_misc)) return 0