コード例 #1
0
ファイル: biblatex.py プロジェクト: patttakid/rubber
    def get_errors(self):
        """
		Read the log file, identify error messages and report them.
		"""
        if self.tool != "biber":
            # we re-use the BibTeX support in superclass
            for error in super(BibLaTeXDep, self).get_errors():
                yield error
            return

        current_bib = None

        try:
            log = open(self.blg, "r")
        except:
            msg.warn(_("cannot open Biber logfile: %s") % self.blg,
                     pkg="biblatex")
            return

        with log:
            for line in log:
                m = re_updatefile.match(line)
                if m:
                    current_bib = m.group("filename")
                m = re_error.match(line)
                if m:
                    d = {"pkg": "biber"}
                    d["kind"] = biber_to_rubber[m.group("kind")]
                    if current_bib:
                        d["file"] = current_bib
                    d["line"] = int(m.group("line"))
                    d["text"] = m.group("text")
                    yield d
コード例 #2
0
ファイル: biblatex.py プロジェクト: skapfer/rubber
    def get_errors(self):
        """
		Read the log file, identify error messages and report them.
		"""
        if self.tool != "biber":
            # we re-use the BibTeX support in superclass
            for error in super(BibLaTeXDep, self).get_errors():
                yield error
            return

        current_bib = None

        try:
            log = open(self.blg, "r")
        except:
            msg.warn(_("cannot open Biber logfile: %s") % self.blg, pkg="biblatex")
            return

        with log:
            for line in log:
                m = re_updatefile.match(line)
                if m:
                    current_bib = m.group("filename")
                m = re_error.match(line)
                if m:
                    d = {"pkg": "biber"}
                    d["kind"] = biber_to_rubber[m.group("kind")]
                    if current_bib:
                        d["file"] = current_bib
                    d["line"] = int(m.group("line"))
                    d["text"] = m.group("text")
                    yield d
コード例 #3
0
	def do_order (self, *args):
		for opt in args:
			if opt == "standard": self.opts = []
			elif opt == "german": self.opts.append("-g")
			elif opt == "letter": self.opts.append("-l")
			else: msg.warn(
				_("unknown option '%s' for 'makeidx.order'") % opt)
コード例 #4
0
	def __init__ (self, set):
		super (BibToolDep, self).__init__ (set)
		self.tool = "bibtex"
		self.environ = os.environ.copy ()
		self.bib_paths = rubber.util.explode_path ("BIBINPUTS")
		# self.bst_paths = rubber.util.explode_path ("BSTINPUTS")
		self.devnull = rubber.util.devnull ()
		if any(os.access(os.path.join(path, "kpsepath"), os.X_OK) for path in os.environ["PATH"].split(os.pathsep)):
			self.bst_paths = subprocess.check_output (["kpsepath", "bst"]).decode("utf-8").encode('ascii', 'ignore').split (":")
		else:
			self.bst_paths = rubber.util.explode_path ("BSTINPUTS")
			msg.warn (_("cannot find cmd \"kpsepath\": you may set \"BSTINPUTS\" in your .bashrc"), pkg="biblio")
コード例 #5
0
	def set_style (self, name):
		if self.bst_file is not None:
			self.remove_source (self.bst_file)
			self.bst_file = None

		filename = rubber.util.find_resource (name, suffix = ".bst", paths = self.bst_paths)
		if filename is not None:
			self.bst_file = filename
			self.add_source (filename, track_contents=True)
		elif name not in [ "plain", "alpha" ]:
			# do not complain about default styles coming with bibtex
			msg.warn (_ ("cannot find bibliography style %s") % name, pkg="biblio")
コード例 #6
0
	def get_errors (self):
		"""
		Read the log file, identify error messages and report them.
		"""
		try:
			log = open (self.blg, "r")
		except:
			msg.warn (_("cannot open BibTeX logfile: %s") % self.blg, pkg="biblio")
			return

		with log:
			last_line = ""
			for line in log:
				m = re_error.search (line)
				if m:
					# TODO: it would be possible to report the offending code.
					if m.start () == 0:
						text = last_line.strip ()
					else:
						text = line[:m.start ()].strip ()

					# when including a bibtex DB with \bibliography{a.bib}
					# bibtex will report it in the log as a.bib.bib.
					# work around this
					filename = m.group ("file")
					if filename.endswith (".bib.bib"):
						filename = filename[:-4]

					filename = self.find_bib (filename) or filename

                    # oracleyue: fix bug when no citation entry
                    if m.group("line") is not None:
				        line = int (m.group ("line"))
                    else:
                        line = int (0)

					d =	{
						"pkg": "bibtex",
						"kind": "error",
						"file": filename,
						"line": line,
						"text": text
					}

					yield d

				last_line = line
コード例 #7
0
	def run (self):
		if not os.path.exists (self.cmd [1]):
			msg.info (_ ("%s not yet generated" % self.cmd [1]))
			return True

		# No more settings are expected, we compute the
		# command once and for all.
		if self.command_env == None:
			if self.cmd [0] == "makeindex":
				self.cmd.extend (self.opts)
				if self.style:
					self.cmd.extend (["-s", self.style])
				path_var = "INDEXSTYLE"
			else:   # self.cmd [0] == "texindy"
				for opt in self.opts:
					if opt == "-g":
						if self.lang != "":
							msg.warn(_("'language' overrides 'order german'"),
								 pkg="index")
						else:
							self.lang = "german-din"
					else: # opt == "-l"
						self.modules.append("letter-ordering")
						msg.warn(_("use 'module letter-ordering' instead of 'order letter'"),
							 pkg="index")
				for mod in self.modules:
					self.cmd.extend(["--module", mod])
				if self.lang:
					self.cmd.extend(["--language", self.lang])
				path_var = "XINDY_SEARCHPATH"

			if self.path != []:
				self.command_env = { path_var: ':'.join(self.path + [os.getenv(path_var, '')]) }
			else:
				self.command_env = {}

		# The actual run.
		return self.doc.env.execute(self.cmd, self.command_env) == 0
コード例 #8
0
ファイル: convert.py プロジェクト: ypersyntelykos/rubber3k
 def read_ini(self, filename):
     """
     Read a set of rules from a file. The file has the form of an INI file,
     each section describes a rule.
     """
     cp = ConfigParser()
     try:
         cp.read(filename)
     except ParsingError:
         msg.error(_("parse error, ignoring this file"), file=filename)
         return
     for name in cp.sections():
         dict = {'name': name}
         for key in cp.options(name):
             dict[key] = cp.get(name, key)
         try:
             dict['cost'] = cp.getint(name, 'cost')
         except NoOptionError:
             msg.warn(_("ignoring rule `%s' (no cost found)") % name,
                      file=filename)
             continue
         except ValueError:
             msg.warn(_("ignoring rule `%s' (invalid cost)") % name,
                      file=filename)
             continue
         if 'target' not in dict:
             msg.warn(_("ignoring rule `%s' (no target found)") % name,
                      file=filename)
             continue
         if 'rule' not in dict:
             msg.warn(_("ignoring rule `%s' (no module found)") % name,
                      file=filename)
         if not self.load_module(dict['rule']):
             msg.warn(_("ignoring rule `%s' (module `%s' not found)") %
                      (name, dict['rule']),
                      file=filename)
         self.rules[name] = Rule(None, dict)
コード例 #9
0
ファイル: convert.py プロジェクト: skapfer/rubber
	def read_ini (self, filename):
		"""
		Read a set of rules from a file. The file has the form of an INI file,
		each section describes a rule.
		"""
		cp = ConfigParser()
		try:
			cp.read(filename)
		except ParsingError:
			msg.error(_("parse error, ignoring this file"), file=filename)
			return
		for name in cp.sections():
			dict = { 'name': name }
			for key in cp.options(name):
				dict[key] = cp.get(name, key)
			try:
				dict['cost'] = cp.getint(name, 'cost')
			except NoOptionError:
				msg.warn(_("ignoring rule `%s' (no cost found)") % name,
						file=filename)
				continue
			except ValueError:
				msg.warn(_("ignoring rule `%s' (invalid cost)") % name,
						file=filename)
				continue
			if 'target' not in dict:
				msg.warn(_("ignoring rule `%s' (no target found)") % name,
						file=filename)
				continue
			if 'rule' not in dict:
				msg.warn(_("ignoring rule `%s' (no module found)") % name,
						file=filename)
			if not self.load_module(dict['rule']):
				msg.warn(_("ignoring rule `%s' (module `%s' not found)") %
						(name, dict['rule']), file=filename)
			self.rules[name] = Rule(None, dict)
コード例 #10
0
ファイル: biblatex.py プロジェクト: skapfer/rubber
 def bibliographystyle(self, loc, bibs):
     msg.warn(_("\\usepackage{biblatex} incompatible with \\bibliographystyle"), pkg="biblatex")
コード例 #11
0
	def parse_opts (self, cmdline, short="", long=[]):
		try:
			opts, args = getopt(
				cmdline, "I:bc:de:fhklm:n:o:pqr:SsvW:z" + short,
				["bzip2", "cache", "clean", "command=", "epilogue=", "force", "gzip",
				 "help", "inplace", "into=", "jobname=", "keep", "landcape", "maxerr=",
				 "module=", "only=", "post=", "pdf", "ps", "quiet", "read=",
				 "src-specials", "shell-escape", "unsafe", "short", "texpath=", "verbose", "version",
				 "warn="] + long)
		except GetoptError as e:
			print(e)
			sys.exit(1)

		extra = []
		using_dvips = 0

		for (opt,arg) in opts:
			if opt in ("-b", "--bzip2"):
				if self.compress is not None and self.compress != "bzip2":
					msg.warn(_("warning: ignoring option %s") % opt)
				else:
					self.compress = "bzip2"
			elif opt == "--cache":
				print('warning: cache is currently disabled')
			elif opt == "--clean":
				self.clean = 1
			elif opt in ("-c", "--command"):
				self.prologue.append(arg)
			elif opt in ("-e", "--epilogue"):
				self.epilogue.append(arg)
			elif opt in ("-f", "--force"):
				self.force = 1
			elif opt in ("-z", "--gzip"):
				if self.compress is not None and self.compress != "gz":
					msg.warn(_("warning: ignoring option %s") % opt)
				else:
					self.compress = "gzip"
			elif opt in ("-h", "--help"):
				self.help()
				sys.exit(0)
			elif opt == "--inplace":
				self.place = None
			elif opt == "--into":
				self.place = arg
			elif opt == "--jobname":
				self.jobname = arg
			elif opt in ("-k", "--keep"):
				self.clean = 0
			elif opt in ("-l", "--landscape"):
				self.prologue.append("paper landscape")
			elif opt in ("-n", "--maxerr"):
				self.max_errors = int(arg)
			elif opt in ("-m", "--module"):
				self.prologue.append("module " +
					string.replace(arg, ":", " ", 1))
			elif opt == "--only":
				self.include_only = arg.split(",")
			elif opt in ("-o", "--post"):
				self.epilogue.append("module " +
					string.replace(arg, ":", " ", 1))
			elif opt in ("-d", "--pdf"):
				if using_dvips:
					self.epilogue.append("module ps2pdf")
				else:
					self.prologue.append("module pdftex")
			elif opt in ("-p", "--ps"):
				self.epilogue.append("module dvips")
				using_dvips = 1
			elif opt in ("-q", "--quiet"):
				msg.level = msg.level - 1
			# we continue to accept --shell-escape for now
			elif opt in ("--unsafe", "--shell-escape"):
				self.unsafe = True
			elif opt in ("-r" ,"--read"):
				self.prologue.append("read " + arg)
			elif opt in ("-S", "--src-specials"):
				self.prologue.append("set src-specials yes")
			elif opt in ("-s", "--short"):
				msg.short = 1
			elif opt in ("-I", "--texpath"):
				self.path.append(arg)
			elif opt in ("-v", "--verbose"):
				msg.level = msg.level + 1
			elif opt == "--version":
				print("Rubber version: " + version)
				print("module path: " + moddir)
				sys.exit(0)
			elif opt in ("-W", "--warn"):
				self.warn = 1
				if arg == "all":
					self.warn_boxes = 1
					self.warn_misc = 1
					self.warn_refs = 1
				if arg == "boxes":
					self.warn_boxes = 1
				elif arg == "misc":
					self.warn_misc = 1
				elif arg == "refs":
					self.warn_refs = 1

			elif arg == "":
				extra.append(opt)
			else:
				extra.extend([arg, opt])

		return extra + args
コード例 #12
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
コード例 #13
0
 def ignored_option(self, opt):
     msg.warn(_("warning: ignoring option %s") % opt)
コード例 #14
0
ファイル: biblatex.py プロジェクト: patttakid/rubber
 def bibliographystyle(self, loc, bibs):
     msg.warn(
         _("\\usepackage{biblatex} incompatible with \\bibliographystyle"),
         pkg="biblatex")
コード例 #15
0
ファイル: cmdline.py プロジェクト: skapfer/rubber
	def ignored_option (self, opt):
		msg.warn (_("warning: ignoring option %s") % opt)