Blame lib/dbtexmf/dblatex/grubber/dvips.py

Packit 0f19cf
# This file is part of Rubber and thus covered by the GPL
Packit 0f19cf
# (c) Emmanuel Beffara, 2002--2006
Packit 0f19cf
"""
Packit 0f19cf
PostScript generation through dvips with Rubber.
Packit 0f19cf
Packit 0f19cf
This module has specific support for Omega: when the name of the main compiler
Packit 0f19cf
is "Omega" (instead of "TeX" for instance), then "odvips" is used instead of
Packit 0f19cf
"dvips".
Packit 0f19cf
"""
Packit 0f19cf
Packit 0f19cf
import sys
Packit 0f19cf
import os
Packit 0f19cf
from os.path import *
Packit 0f19cf
import subprocess
Packit 0f19cf
Packit Service f3de8e
from dbtexmf.dblatex.grubber.msg import _ , msg
Packit Service f3de8e
from dbtexmf.dblatex.grubber.plugins import TexModule
Packit Service f3de8e
from dbtexmf.dblatex.grubber.maker import Depend
Packit 0f19cf
Packit 0f19cf
class Dep (Depend):
Packit 0f19cf
    def __init__ (self, doc, target, source, node):
Packit 0f19cf
        self.doc = doc
Packit 0f19cf
        self.env = doc.env
Packit 0f19cf
        self.source = source
Packit 0f19cf
        self.target = target
Packit 0f19cf
        Depend.__init__(self, doc.env, prods=[target], sources={source: node})
Packit 0f19cf
        self.options = []
Packit 0f19cf
        if self.doc.engine == "Omega":
Packit 0f19cf
            self.cmdexec = "odvips"
Packit 0f19cf
        else:
Packit 0f19cf
            self.cmdexec = "dvips"
Packit 0f19cf
            self.options.append("-R0")
Packit 0f19cf
Packit 0f19cf
    def run (self):
Packit 0f19cf
        cmd = [self.cmdexec]
Packit 0f19cf
        msg.progress(_("running %s on %s") % (cmd[0], self.source))
Packit 0f19cf
        for opt in self.doc.paper.split():
Packit 0f19cf
            cmd.extend(["-t", opt])
Packit 0f19cf
        cmd.extend(self.options + ["-o", self.target, self.source])
Packit 0f19cf
        msg.debug(" ".join(cmd))
Packit 0f19cf
        rc = subprocess.call(cmd, stdout=msg.stdout)
Packit 0f19cf
        if rc != 0:
Packit 0f19cf
            msg.error(_("%s failed on %s") % (cmd[0], self.source))
Packit 0f19cf
            return 1
Packit 0f19cf
        return 0
Packit 0f19cf
Packit 0f19cf
class Module (TexModule):
Packit 0f19cf
    def __init__ (self, doc, dict):
Packit 0f19cf
        self.doc = doc
Packit 0f19cf
        lastdep = doc.env.dep_last()
Packit 0f19cf
        dvi = lastdep.prods[0]
Packit 0f19cf
        root, ext = os.path.splitext(dvi)
Packit 0f19cf
        if ext != ".dvi":
Packit 0f19cf
            msg.error(_("I can't use dvips when not producing a DVI"))
Packit 0f19cf
            sys.exit(2)
Packit 0f19cf
        ps = root + ".ps"
Packit 0f19cf
        self.dep = Dep(doc, ps, dvi, lastdep)
Packit 0f19cf
        doc.env.dep_append(self.dep)
Packit 0f19cf
Packit 0f19cf
    def do_options (self, *args):
Packit 0f19cf
        self.dep.options.extend(args)
Packit 0f19cf