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 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] # BibTeX comes with a straightjacket in some TeX distros and can't write # to absolute paths. strip the directory, and change into that dir. workdir = os.path.dirname(self.base) basename = os.path.basename(self.base) if self.doc.env.execute(['bibtex', basename], doc, pwd=workdir): msg.info(_("There were errors making the bibliography.")) return False self.run_needed = 0 self.doc.must_compile = 1 return True
def pre_compile(self): if not os.path.exists(self.doc.target + '.pytxcode'): msg.info(_("Need compilation!"), pkg="pythontex") self.force_compilation() msg.info(_("running pythontex..."), pkg="pythontex") self.run_pythontex() self.doc.watch_file(self.doc.target + ".pytxcode") return True
def pre_compile (self): if not os.path.exists(self.doc.target + '.pytxcode'): msg.info(_("Need compilation!"), pkg="pythontex") self.force_compilation() msg.info(_("running pythontex..."), pkg="pythontex") self.run_pythontex() self.doc.watch_file(self.doc.target + ".pytxcode") return True
def run (self): # check if the input file exists. if not, refuse to run. if not os.path.exists (self.sources[0]): msg.info (_('input file for %s does not yet exist, deferring') % self.tool, pkg='pythontex') return True if not self.doc.env.is_in_unsafe_mode_: msg.error (_('The document tries to run embedded Python code which could be dangerous. Use rubber --unsafe if the document is trusted.')) return False return super (PythonTeXDep, self).run ()
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", "")], os.pathsep) if len(self.bst_path) != 1: doc["BSTINPUTS"] = string.join(self.bst_path + [os.getenv("BSTINPUTS", "")], os.pathsep) if self.crossrefs is None: cmd = ["bibtex"] else: cmd = ["bibtex", "-min-crossrefs=" + self.crossrefs] if self.doc.env.execute(['bibtex', self.base], doc): msg.info(_("There were errors making the bibliography.")) return False self.run_needed = 0 self.doc.must_compile = 1 return True
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", "")], os.pathsep) if len(self.bst_path) != 1: doc["BSTINPUTS"] = string.join( self.bst_path + [os.getenv("BSTINPUTS", "")], os.pathsep) if self.crossrefs is None: cmd = ["bibtex"] else: cmd = ["bibtex", "-min-crossrefs=" + self.crossrefs] if self.doc.env.execute(['bibtex', self.base], doc): msg.info(_("There were errors making the bibliography.")) return False self.run_needed = 0 self.doc.must_compile = 1 return True
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 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
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 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