Exemple #1
0
 def load_plugin(self, pathname):
     moddir, modname = os.path.split(pathname)
     try:
         filemod, path, descr = imp.find_module(modname, [moddir])
     except ImportError:
         try:
             filemod, path, descr = imp.find_module(modname)
         except ImportError:
             failed_exit("Error: '%s' module not found" % modname)
     mod = imp.load_module(modname, filemod, path, descr)
     filemod.close()
     return mod
Exemple #2
0
    def run_setup(self, options):
        run = self.run

        if not(options.format):
            if options.format_pdf:
                options.format = "pdf"
            elif options.format_ps:
                options.format = "ps"
            elif options.format_dvi:
                options.format = "dvi"

        if options.format:
            try:
                run.set_format(options.format)
            except Exception, e:
                failed_exit("Error: %s" % e)
Exemple #3
0
    def main(self):
        (options, args) = self.parser.parse_args()

        run = self.run
        parser = self.parser

        if options.version:
            version = run.get_version()
            print "%s version %s" % (self.prog, version)
            if not(args):
                sys.exit(0)

        # At least the input file is expected
        if not(args):
            parser.parse_args(args=["-h"])

        # Load the specified configurations
        conf = DbtexConfig()
        if options.style:
            try:
                conf.paths = self.get_config_paths()
                conf.fromstyle(options.style)
            except Exception, e:
                failed_exit("Error: %s" % e)
Exemple #4
0
    def main(self):
        (options, args) = self.parser.parse_args()

        run = self.run
        parser = self.parser

        if options.version:
            version = run.get_version()
            print("%s version %s" % (self.prog, version))
            if not (args):
                sys.exit(0)

        # At least the input file is expected
        if not (args):
            parser.parse_args(args=["-h"])

        # Load the specified configurations
        conf = DbtexConfig()
        if options.dump:
            dump_stack()

        if options.style:
            try:
                conf.paths = self.get_config_paths()
                conf.fromstyle(options.style)
            except Exception as e:
                failed_exit("Error: %s" % e)

        if options.config:
            try:
                for config in options.config:
                    conf.fromfile(config)
            except Exception as e:
                failed_exit("Error: %s" % e)

        if conf.options:
            options2, args2 = parser.parse_args(conf.options)
            self.run_setup(options2)

        # Now apply the command line setup
        self.run_setup(options)

        # Verbose mode
        run.log = logger.logger(self.prog, run.verbose)

        # Data from standard input?
        if args[0] == "-":
            if not (options.output):
                failed_exit("Error: -o expected when input from stdin")
            input = ""
            if options.changedir:
                run.stdindir = os.path.realpath(options.changedir)
        else:
            input = os.path.realpath(args[0])

        # Output file in case of single document (main case)
        if not (options.output):
            output = None
        else:
            output = os.path.realpath(options.output)

        # Output directory in case of chunked books (from a set)
        if not (options.output_dir):
            outputdir = None
        else:
            # Check the output dir is OK
            outputdir = os.path.realpath(options.output_dir)
            if not (os.path.isdir(outputdir)):
                failed_exit("Error: '%s' is not a directory" %\
                            options.output_dir)

        run.input = input
        run.output = output
        run.outputdir = outputdir

        # Try to buid the file
        try:
            run.compile()
        except Exception as e:
            signal_error(self, e)
            failed_exit("Error: %s" % e)
Exemple #5
0
    def run_setup(self, options):
        run = self.run

        if not (options.format):
            if options.format_pdf:
                options.format = "pdf"
            elif options.format_ps:
                options.format = "ps"
            elif options.format_dvi:
                options.format = "dvi"

        if options.format:
            try:
                run.set_format(options.format)
            except Exception as e:
                failed_exit("Error: %s" % e)

        # Always set the XSLT (default or not)
        try:
            run.set_xslt(options.xslt)
        except Exception as e:
            failed_exit("Error: %s" % e)

        if options.xslopts:
            for o in options.xslopts:
                run.xslopts += shlex.split(o)

        if options.xslparams:
            run.xslparams += options.xslparams

        if options.debug:
            run.debug = options.debug

        if options.fig_paths:
            run.fig_paths += [os.path.realpath(p) for p in options.fig_paths]

        if options.bib_paths:
            run.bib_paths += [os.path.realpath(p) for p in options.bib_paths]

        if options.bst_paths:
            run.bst_paths += [os.path.realpath(p) for p in options.bst_paths]

        if options.texstyle:
            try:
                xslparam, texpath = texstyle_parse(options.texstyle)
            except Exception as e:
                failed_exit("Error: %s" % e)
            run.xslparams.append(xslparam)
            if texpath: run.texinputs.append(texpath)

        if options.indexstyle:
            run.runtex.index_style = os.path.abspath(options.indexstyle)

        if options.texinputs:
            for texinputs in options.texinputs:
                run.texinputs += texinputs_parse(texinputs)

        if options.fig_format:
            run.fig_format = options.fig_format

        if options.input_format:
            run.input_format = options.input_format

        if options.no_batch:
            run.texbatch = 0

        if options.backend:
            run.backend = options.backend

        if options.xsl_user:
            for xfile in options.xsl_user:
                xsluser = os.path.realpath(xfile)
                if not (os.path.isfile(xsluser)):
                    failed_exit("Error: '%s' does not exist" %
                                options.xsl_user)
                run.xslusers.append(xsluser)

        if options.texpost:
            is_plugin = options.texpost.startswith("plugin:")
            if is_plugin:
                path = self.load_plugin(options.texpost[len("plugin:"):])
            else:
                path = os.path.realpath(options.texpost)
                if not (os.path.isfile(path)):
                    failed_exit("Error: '%s' does not exist" % options.texpost)
            run.texpost = path

        if options.no_external:
            run.unset_flags(run.USE_MKLISTINGS)

        if options.verbose:
            run.verbose = options.verbose

        if options.quiet:
            run.verbose = logger.QUIET
            run.xslparams.append("output.quietly=1")

        if options.tmpdir:
            if not (os.path.exists(options.tmpdir)):
                try:
                    os.mkdir(options.tmpdir)
                except Exception as e:
                    failed_exit("Error: %s" % e)
            run.tmpdir_user = os.path.abspath(options.tmpdir)

        if options.dump:
            dump_stack()
Exemple #6
0
            run.debug = options.debug

        if options.fig_paths:
            run.fig_paths += [os.path.realpath(p) for p in options.fig_paths]

        if options.bib_paths:
            run.bib_paths += [os.path.realpath(p) for p in options.bib_paths]

        if options.bst_paths:
            run.bst_paths += [os.path.realpath(p) for p in options.bst_paths]

        if options.texstyle:
            try:
                xslparam, texpath = texstyle_parse(options.texstyle)
            except Exception, e:
                failed_exit("Error: %s" % e)
            run.xslparams.append(xslparam)
            if texpath: run.texinputs.append(texpath)

        if options.indexstyle:
            run.runtex.index_style = os.path.abspath(options.indexstyle)

        if options.texinputs:
            for texinputs in options.texinputs:
                run.texinputs += texinputs_parse(texinputs)

        if options.fig_format:
            run.fig_format = options.fig_format

        if options.input_format:
            run.input_format = options.input_format