Beispiel #1
0
 def run(self):
     cmd = [self.cmdexec]
     msg.progress(_("running %s on %s") % (cmd[0], self.source))
     for opt in self.doc.paper.split():
         cmd.extend(["-t", opt])
     cmd.extend(self.options + ["-o", self.target, self.source])
     msg.debug(" ".join(cmd))
     rc = subprocess.call(cmd, stdout=msg.stdout)
     if rc != 0:
         msg.error(_("%s failed on %s") % (cmd[0], self.source))
         return 1
     return 0
Beispiel #2
0
 def run (self):
     cmd = [self.cmdexec]
     msg.progress(_("running %s on %s") % (cmd[0], self.source))
     for opt in self.doc.paper.split():
         cmd.extend(["-t", opt])
     cmd.extend(self.options + ["-o", self.target, self.source])
     msg.debug(" ".join(cmd))
     rc = subprocess.call(cmd, stdout=msg.stdout)
     if rc != 0:
         msg.error(_("%s failed on %s") % (cmd[0], self.source))
         return 1
     return 0
Beispiel #3
0
 def update(self):
     """
     Update the MD5 sums of all files watched, and return the name of one
     of the files that changed, or None of they didn't change.
     """
     changed = []
     for file in self.files.keys():
         if os.path.exists(file):
             new = md5_file(file)
             if self.files[file] != new:
                 msg.debug(_("%s MD5 checksum changed") % \
                           os.path.basename(file))
                 changed.append(file)
             self.files[file] = new
     return changed
Beispiel #4
0
    def register (self, name, dict={}):
        """
        Attempt to register a package with the specified name. If a module is
        found, create an object from the module's class called `Module',
        passing it the environment and `dict' as arguments, and execute all
        delayed commands for this module. The dictionary describes the
        command that caused the registration.
        """
        if self.has_key(name):
            msg.debug(_("module %s already registered") % name)
            return 2

        # First look for a script

        moddir = ""
        mod = None
        for path in "", join(moddir, "modules"):
            file = join(path, name + ".rub")
            if exists(file):
                mod = ScriptModule(self.env, file)
                msg.log(_("script module %s registered") % name)
                break

        # Then look for a Python module

        if not mod:
            if Plugins.register(self, name) == 0:
                msg.debug(_("no support found for %s") % name)
                return 0
            mod = self.modules[name].Module(self.env, dict)
            msg.log(_("built-in module %s registered") % name)

        # Run any delayed commands.

        if self.commands.has_key(name):
            for (cmd, args, vars) in self.commands[name]:
                msg.push_pos(vars)
                try:
                    mod.command(cmd, args)
                except AttributeError:
                    msg.warn(_("unknown directive '%s.%s'") % (name, cmd))
                except TypeError:
                    msg.warn(_("wrong syntax for '%s.%s'") % (name, cmd))
                msg.pop_pos()
            del self.commands[name]

        self.objects[name] = mod
        return 1
Beispiel #5
0
    def register(self, name, dict={}):
        """
        Attempt to register a package with the specified name. If a module is
        found, create an object from the module's class called `Module',
        passing it the environment and `dict' as arguments, and execute all
        delayed commands for this module. The dictionary describes the
        command that caused the registration.
        """
        if self.has_key(name):
            msg.debug(_("module %s already registered") % name)
            return 2

        # First look for a script

        moddir = ""
        mod = None
        for path in "", join(moddir, "modules"):
            file = join(path, name + ".rub")
            if exists(file):
                mod = ScriptModule(self.env, file)
                msg.log(_("script module %s registered") % name)
                break

        # Then look for a Python module

        if not mod:
            if Plugins.register(self, name) == 0:
                msg.debug(_("no support found for %s") % name)
                return 0
            mod = self.modules[name].Module(self.env, dict)
            msg.log(_("built-in module %s registered") % name)

        # Run any delayed commands.

        if self.commands.has_key(name):
            for (cmd, args, vars) in self.commands[name]:
                msg.push_pos(vars)
                try:
                    mod.command(cmd, args)
                except AttributeError:
                    msg.warn(_("unknown directive '%s.%s'") % (name, cmd))
                except TypeError:
                    msg.warn(_("wrong syntax for '%s.%s'") % (name, cmd))
                msg.pop_pos()
            del self.commands[name]

        self.objects[name] = mod
        return 1
Beispiel #6
0
 def compile_needed (self):
     """
     Returns true if a first compilation is needed. This method supposes
     that no compilation was done (by the script) yet.
     """
     if self.must_compile:
         return 1
     msg.log(_("checking if compiling is necessary..."))
     if not self.draft_support and not os.path.exists(self.outfile):
         msg.debug(_("the output file doesn't exist"))
         return 1
     if not os.path.exists(self.logfile):
         msg.debug(_("the log file does not exist"))
         return 1
     if (not self.draft_support and 
         (os.path.getmtime(self.outfile) < os.path.getmtime(self.srcfile))):
         msg.debug(_("the source is younger than the output file"))
         return 1
     if self.log.read(self.logfile):
         msg.debug(_("the log file is not produced by TeX"))
         return 1
     return self.recompile_needed()
Beispiel #7
0
 def compile_needed(self):
     """
     Returns true if a first compilation is needed. This method supposes
     that no compilation was done (by the script) yet.
     """
     if self.must_compile:
         return 1
     msg.log(_("checking if compiling is necessary..."))
     if not self.draft_support and not os.path.exists(self.outfile):
         msg.debug(_("the output file doesn't exist"))
         return 1
     if not os.path.exists(self.logfile):
         msg.debug(_("the log file does not exist"))
         return 1
     if (not self.draft_support and
         (os.path.getmtime(self.outfile) < os.path.getmtime(self.srcfile))):
         msg.debug(_("the source is younger than the output file"))
         return 1
     if self.log.read(self.logfile):
         msg.debug(_("the log file is not produced by TeX"))
         return 1
     return self.recompile_needed()
Beispiel #8
0
    def recompile_needed (self):
        """
        Returns true if another compilation is needed. This method is used
        when a compilation has already been done.
        """
        changed = self.watcher.update()
        if self.must_compile:
            return 1
        if self.log.errors():
            msg.debug(_("last compilation failed"))
            return 1
#        if self.deps_modified(os.path.getmtime(self.outfile)):
#            msg.debug(_("dependencies were modified"))
#            return 1
        if changed and (len(changed) > 1 or changed[0] != self.auxfile):
            msg.debug(_("the %s file has changed") % changed[0])
            return 1
        if self.log.run_needed():
            msg.debug(_("LaTeX asks to run again"))
            if (not(changed)):
                msg.debug(_("but the aux files are unchanged"))
                return 0
            return 1
        if changed:
            msg.debug(_("the %s file has changed but no re-run required?") \
                      % changed[0])
            if self.program == "xelatex":
                msg.debug(_("force recompilation (XeTeX engine)"))
                return 1

        msg.debug(_("no new compilation is needed"))
        return 0
Beispiel #9
0
    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 0
        if not self.run_needed():
            return 0

        msg.progress(_("processing index %s") % self.source)

        if self.tool == "makeindex":
            cmd = ["makeindex", "-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:
                string.join(self.path + [os.getenv(path_var, "")], ":") }
        else:
            env = {}

        msg.debug(" ".join(cmd))
        # Makeindex outputs everything to stderr, even progress messages
        rc = subprocess.call(cmd, stderr=msg.stdout)
        if (rc != 0):
            msg.error(_("could not make index %s") % self.target)
            return 1

        # Beware with UTF-8 encoding, makeindex with headings can be messy
        if self.doc.encoding == "utf8" and self.style:
            f = file(self.target, "r")
            error = 0
            for line in f:
                try:
                    line.decode("utf8")
                except:
                    error = 1
                    break
            f.close()
            if error:
                print "here"
                # Retry without style
                msg.log(_("%s on UTF8 failed. Retry...") % self.tool)
                self.style = ""
                self.md5 = None
                return self.post_compile()

        self.doc.must_compile = 1
        return 0
Beispiel #10
0
    def recompile_needed(self):
        """
        Returns true if another compilation is needed. This method is used
        when a compilation has already been done.
        """
        changed = self.watcher.update()
        if self.must_compile:
            return 1
        if self.log.errors():
            msg.debug(_("last compilation failed"))
            return 1
#        if self.deps_modified(os.path.getmtime(self.outfile)):
#            msg.debug(_("dependencies were modified"))
#            return 1
        if changed and (len(changed) > 1 or changed[0] != self.auxfile):
            msg.debug(_("the %s file has changed") % changed[0])
            return 1
        if self.log.run_needed():
            msg.debug(_("LaTeX asks to run again"))
            if (not (changed)):
                msg.debug(_("but the aux files are unchanged"))
                return 0
            return 1
        if changed:
            msg.debug(_("the %s file has changed but no re-run required?") \
                      % changed[0])
            if self.program == "xelatex":
                msg.debug(_("force recompilation (XeTeX engine)"))
                return 1

        msg.debug(_("no new compilation is needed"))
        return 0