def main(self, cmdline): self.env = Environment() self.prologue = [] self.epilogue = [] self.act = None args = self.parse_opts(cmdline) if not self.act: self.act = "check" msg.log( _("This is Rubber's information extractor version %s.") % version) if len(args) != 1: sys.stderr.write(_("You must specify one source file.\n")) sys.exit(1) src = args[0] if self.env.set_source(src): sys.stderr.write(_("I cannot find %s.\n") % src) sys.exit(1) if self.act == "deps": self.prepare(src) deps = {} for dep in self.env.main.source_nodes(): for file in dep.leaves(): deps[file] = None print(' '.join(deps.keys())) elif self.act == "rules": self.prepare(src) seen = {} next_ = [self.env.final] while len(next_) > 0: node = next_[0] next_ = next_[1:] if seen.has_key(node): continue seen[node] = None if len(node.sources) == 0: continue print("\n%s:" % ' '.join(node.products), end=',') print(' '.join(node.sources)) next_.extend(node.source_nodes()) else: self.prepare(src, parse=0) return self.info_log(self.act) return 0
def main (self, cmdline): self.env = Environment() self.prologue = [] self.epilogue = [] self.act = None args = self.parse_opts(cmdline) if not self.act: self.act = "check" msg.log(_( "This is Rubber's information extractor version %s.") % version) if len(args) != 1: sys.stderr.write(_("You must specify one source file.\n")) sys.exit(1) src = args[0] if self.env.set_source(src): sys.stderr.write(_("I cannot find %s.\n") % src) sys.exit(1) if self.act == "deps": self.prepare(src) deps = {} for dep in self.env.main.source_nodes(): for file in dep.leaves(): deps[file] = None print(' '.join(deps.keys())) elif self.act == "rules": self.prepare(src) seen = {} next_ = [self.env.final] while len(next_) > 0: node = next_[0] next_ = next_[1:] if seen.has_key(node): continue seen[node] = None if len(node.sources) == 0: continue print("\n%s:" % ' '.join(node.products), end=',') print(' '.join(node.sources)) next_.extend(node.source_nodes()) else: self.prepare(src, parse=0) return self.info_log(self.act) 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.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.unsafe = False 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 try: 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) except OSError as e: msg.error(_("Error changing to working directory: %s") % e.strerror) return 1 # Check the source and prepare it for processing env = Environment() if env.set_source(src, jobname=self.jobname): return 1 self.jobname = None env.is_in_unsafe_mode_ = self.unsafe 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. """ args = self.parse_opts(cmdline) initial_dir = os.getcwd() msg.cwd = os.path.join(initial_dir, "") if self.place == ".": self.place = initial_dir if self.place is not None: msg.path = self.place self.place = os.path.abspath(self.place) global rubber msg.log(_("This is Rubber version %s.") % rubber_version) for srcname in args: src = os.path.join(initial_dir, srcname) # Go to the appropriate directory try: if self.place != ".": if self.place is None: msg.path = os.path.dirname(src) os.chdir(os.path.dirname(src)) else: os.chdir(self.place) except OSError as e: msg.error( _("Error changing to working directory: %s") % e.strerror) rubber.util.abort_generic_error() # prepare the source file. this may require a pre-processing # step, or dumping stdin. thus, the input filename may change. # in case of build mode, preprocessors will be run as part of # prepare_source. env = self.env = Environment() self.env.is_in_unsafe_mode_ = self.unsafe src = self.prepare_source(src) if self.include_only is not None: env.main.includeonly(self.include_only) # at this point, the LaTeX source file must exist; if it is # the result of pre-processing, this has happened already. # the main LaTeX file is not found via find_file (unlike # most other resources) by design: paths etc may be set up # from within via rubber directives, so that wouldn't make a # whole lot of sense. if not os.path.exists(src): msg.error(_("LaTeX source file not found: '%s'") % src) rubber.util.abort_generic_error() saved_vars = env.main.vars env.main.vars = rubber.util.Variables(saved_vars, {"cwd": initial_dir}) for dir in self.path: env.main.do_path(dir) for cmd in self.prologue: cmd = rubber.util.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 = rubber.util.Variables(saved_vars, {"cwd": initial_dir}) for cmd in self.epilogue: cmd = rubber.util.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': import gzip env.final = rubber.converters.compressor.Node( env.depends, gzip.GzipFile, '.gz', filename) else: # self.compress == 'bzip2' import bz2 env.final = rubber.converters.compressor.Node( env.depends, bz2.BZ2File, '.bz2', filename) self.process_source(env) exit(0)
class Main (rubber.cmdline.Main): def __init__ (self): rubber.cmdline.Main.__init__(self) msg.write = self.stdout_write def stdout_write (self, text, level=0): sys.stdout.write(text + "\n") def short_help (self): sys.stderr.write(_("""\ usage: rubber-info [options] source For more information, try `rubber-info --help'. """)) def help (self): print(("""\ This is Rubber's information extractor version %s. usage: rubber-info [options] source available options: all options accepted by rubber(1) actions: --boxes report overfull and underfull boxes --check report errors or warnings (default action) --deps show the target file's dependencies --errors show all errors that occured during compilation --help display this help --refs show the list of undefined references --rules print the dependency rules including intermediate results --version print the program's version and exit --warnings show all LaTeX warnings\ """) % version) def parse_opts (self, cmdline): try: long = [ "module=", "readopts=", "short", "verbose", "boxes", "check", "deps", "errors", "help", "refs", "rules", "version", "warnings" ] args = rubber.cmdline.Main.parse_opts(self, cmdline, long=long) opts, args = getopt(args, "", long) self.max_errors = -1 except GetoptError as e: msg.error(e) sys.exit(1) for (opt,arg) in opts: if opt in ("-h", "--help"): self.help() sys.exit(0) elif opt in ("-m", "--module"): self.modules.append(arg) elif opt in ("-o" ,"--readopts"): file = open(arg) opts2 = file.read().split() file.close() args = self.parse_opts(opts2) + args elif opt in ("-s", "--short"): msg.short = 1 elif opt in ("-v", "--verbose"): msg.level = msg.level + 1 elif opt == "--version": msg(0, version) sys.exit(0) else: if self.act: sys.stderr.write(_("You must specify only one action.\n")) sys.exit(1) self.act = opt[2:] return args def main (self, cmdline): self.env = Environment() self.prologue = [] self.epilogue = [] self.act = None args = self.parse_opts(cmdline) if not self.act: self.act = "check" msg.log(_( "This is Rubber's information extractor version %s.") % version) if len(args) != 1: sys.stderr.write(_("You must specify one source file.\n")) sys.exit(1) src = args[0] if self.env.set_source(src): sys.stderr.write(_("I cannot find %s.\n") % src) sys.exit(1) if self.act == "deps": self.prepare(src) deps = {} for dep in self.env.main.source_nodes(): for file in dep.leaves(): deps[file] = None print(' '.join(deps.keys())) elif self.act == "rules": self.prepare(src) seen = {} next_ = [self.env.final] while len(next_) > 0: node = next_[0] next_ = next_[1:] if seen.has_key(node): continue seen[node] = None if len(node.sources) == 0: continue print("\n%s:" % ' '.join(node.products), end=',') print(' '.join(node.sources)) next_.extend(node.source_nodes()) else: self.prepare(src, parse=0) return self.info_log(self.act) return 0 def prepare (self, src, parse=1): """ Check for the source file and prepare it for processing. """ env = self.env if env.make_source(): sys.exit(1) if not parse: return 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'}) self.env.main.parse() for cmd in self.epilogue: cmd = parse_line(cmd, {}) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) def info_log (self, act): """ Check for a log file and extract information from it if it exists, accroding to the argument's value. """ log = self.env.main.log ret = log.read(self.env.main.target + ".log") if ret == 1: msg.error(_("The log file is invalid.")) return 1 elif ret == 2: msg.error(_("There is no log file")) return 1 if act == "boxes": if not msg.display_all(log.get_boxes()): msg.info(_("There is no bad box.")) elif act == "check": if msg.display_all(log.get_errors()): return 0 msg.info(_("There was no error.")) if msg.display_all(log.get_references()): return 0 msg.info(_("There is no undefined reference.")) if not msg.display_all(log.get_warnings()): msg.info(_("There is no warning.")) if not msg.display_all(log.get_boxes()): msg.info(_("There is no bad box.")) elif act == "errors": if not msg.display_all(log.get_errors()): msg.info(_("There was no error.")) elif act == "refs": if not msg.display_all(log.get_references()): msg.info(_("There is no undefined reference.")) elif act == "warnings": if not msg.display_all(log.get_warnings()): msg.info(_("There is no warning.")) else: sys.stderr.write(_("\ I don't know the action `%s'. This should not happen.\n") % act) return 1 return 0 def __call__ (self, cmdline): if cmdline == []: self.short_help() return 1 try: self.main(cmdline) except KeyboardInterrupt: msg(0, _("*** interrupted")) return 2
class Main(rubber.cmdline.Main): def __init__(self): rubber.cmdline.Main.__init__(self) msg.write = self.stdout_write def stdout_write(self, text, level=0): sys.stdout.write(text + "\n") def short_help(self): sys.stderr.write( _("""\ usage: rubber-info [options] source For more information, try `rubber-info --help'. """)) def help(self): print(("""\ This is Rubber's information extractor version %s. usage: rubber-info [options] source available options: all options accepted by rubber(1) actions: --boxes report overfull and underfull boxes --check report errors or warnings (default action) --deps show the target file's dependencies --errors show all errors that occured during compilation --help display this help --refs show the list of undefined references --rules print the dependency rules including intermediate results --version print the program's version and exit --warnings show all LaTeX warnings\ """) % version) def parse_opts(self, cmdline): try: long = [ "module=", "readopts=", "short", "verbose", "boxes", "check", "deps", "errors", "help", "refs", "rules", "version", "warnings" ] args = rubber.cmdline.Main.parse_opts(self, cmdline, long=long) opts, args = getopt(args, "", long) self.max_errors = -1 except GetoptError as e: msg.error(e) sys.exit(1) for (opt, arg) in opts: if opt in ("-h", "--help"): self.help() sys.exit(0) elif opt in ("-m", "--module"): self.modules.append(arg) elif opt in ("-o", "--readopts"): file = open(arg) opts2 = file.read().split() file.close() args = self.parse_opts(opts2) + args elif opt in ("-s", "--short"): msg.short = 1 elif opt in ("-v", "--verbose"): msg.level = msg.level + 1 elif opt == "--version": msg(0, version) sys.exit(0) else: if self.act: sys.stderr.write(_("You must specify only one action.\n")) sys.exit(1) self.act = opt[2:] return args def main(self, cmdline): self.env = Environment() self.prologue = [] self.epilogue = [] self.act = None args = self.parse_opts(cmdline) if not self.act: self.act = "check" msg.log( _("This is Rubber's information extractor version %s.") % version) if len(args) != 1: sys.stderr.write(_("You must specify one source file.\n")) sys.exit(1) src = args[0] if self.env.set_source(src): sys.stderr.write(_("I cannot find %s.\n") % src) sys.exit(1) if self.act == "deps": self.prepare(src) deps = {} for dep in self.env.main.source_nodes(): for file in dep.leaves(): deps[file] = None print(' '.join(deps.keys())) elif self.act == "rules": self.prepare(src) seen = {} next_ = [self.env.final] while len(next_) > 0: node = next_[0] next_ = next_[1:] if seen.has_key(node): continue seen[node] = None if len(node.sources) == 0: continue print("\n%s:" % ' '.join(node.products), end=',') print(' '.join(node.sources)) next_.extend(node.source_nodes()) else: self.prepare(src, parse=0) return self.info_log(self.act) return 0 def prepare(self, src, parse=1): """ Check for the source file and prepare it for processing. """ env = self.env if env.make_source(): sys.exit(1) if not parse: return 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'}) self.env.main.parse() for cmd in self.epilogue: cmd = parse_line(cmd, {}) env.main.command(cmd[0], cmd[1:], {'file': 'command line'}) def info_log(self, act): """ Check for a log file and extract information from it if it exists, accroding to the argument's value. """ log = self.env.main.log ret = log.read(self.env.main.target + ".log") if ret == 1: msg.error(_("The log file is invalid.")) return 1 elif ret == 2: msg.error(_("There is no log file")) return 1 if act == "boxes": if not msg.display_all(log.get_boxes()): msg.info(_("There is no bad box.")) elif act == "check": if msg.display_all(log.get_errors()): return 0 msg.info(_("There was no error.")) if msg.display_all(log.get_references()): return 0 msg.info(_("There is no undefined reference.")) if not msg.display_all(log.get_warnings()): msg.info(_("There is no warning.")) if not msg.display_all(log.get_boxes()): msg.info(_("There is no bad box.")) elif act == "errors": if not msg.display_all(log.get_errors()): msg.info(_("There was no error.")) elif act == "refs": if not msg.display_all(log.get_references()): msg.info(_("There is no undefined reference.")) elif act == "warnings": if not msg.display_all(log.get_warnings()): msg.info(_("There is no warning.")) else: sys.stderr.write( _("\ I don't know the action `%s'. This should not happen.\n") % act) return 1 return 0 def __call__(self, cmdline): if cmdline == []: self.short_help() return 1 try: self.main(cmdline) except KeyboardInterrupt: msg(0, _("*** interrupted")) return 2