Пример #1
0
	def short_help (self):
		"""
		Display a short description of the command line.
		"""
		msg(0, _("""\
usage: rubber [options] sources...
For more information, try `rubber --help'."""))
Пример #2
0
	def __call__ (self, cmdline):
		if cmdline == []:
			self.short_help()
			return 1
		try:
			self.main(cmdline)
		except KeyboardInterrupt:
			msg(0, _("*** interrupted"))
			return 2
Пример #3
0
 def __call__(self, cmdline):
     if cmdline == []:
         self.short_help()
         return 1
     try:
         self.main(cmdline)
     except KeyboardInterrupt:
         msg(0, _("*** interrupted"))
         return 2
Пример #4
0
    def __call__(self, cmdline):
        """
		This method is a wrapper around the main method,
		catching the keyboard interruption signal.
		"""
        try:
            self.main(cmdline)
            assert False
        except KeyboardInterrupt:
            msg(0, _("*** interrupted"))
            rubber.util.abort_generic_error()
Пример #5
0
	def __call__ (self, cmdline):
		"""
		This method is a wrapper around the main method,
		catching the keyboard interruption signal.
		"""
		try:
			self.main (cmdline)
			assert False
		except KeyboardInterrupt:
			msg(0, _("*** interrupted"))
			rubber.util.abort_generic_error ()
Пример #6
0
	def __call__ (self, cmdline):
		"""
		This method is a wrapper around the main method, showing a short help
		message when the command line is empty, and catching the keyboard
		interruption signal.
		"""
		if cmdline == []:
			self.short_help()
			return 1
		try:
			return self.main(cmdline)
		except KeyboardInterrupt:
			msg(0, _("*** interrupted"))
			return 2
Пример #7
0
    def build(self, env):
        """
		Build the final product.
		"""
        srcname = env.main.sources[0]
        # FIXME unindent, untangle
        if True:
            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
                rubber.util.abort_generic_error()

            if ret == UNCHANGED:
                msg(1, _("nothing to be done for %s") % srcname)

            if self.warn:
                # FIXME
                log = env.main.log
                if not env.main.parse_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))
Пример #8
0
	def build (self, env):
		"""
		Build the final product.
		"""
		srcname = env.main.sources[0]
		# FIXME unindent, untangle
		if True:
			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
				rubber.util.abort_generic_error ()

			if ret == UNCHANGED:
				msg(1, _("nothing to be done for %s") % srcname)

			if self.warn:
				# FIXME
				log = env.main.log
				if not env.main.parse_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))
Пример #9
0
    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
Пример #10
0
	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
Пример #11
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