Beispiel #1
0
 def _run(self, xslfile, xmlfile, outfile):
     rc = self.command.run(kw={
         "stylesheet": xslfile,
         "xmlfile": xmlfile,
         "output": outfile
     })
     if rc != 0: signal_error(self, "")
Beispiel #2
0
 def convert(self, input, output, format, doexec=1):
     rc = self.command.run(kw={
         "input": input,
         "output": output,
         "dst": format
     })
     if rc != 0: signal_error(self, "")
Beispiel #3
0
 def system(self, cmd, doexec=1):
     if not(cmd):
         return ""
     if self.log:
         self.log.info(cmd)
     if doexec:
         if not(self.fake):
             if (os.system(cmd)):
                 signal_error(self, cmd)
     else:
         return cmd
Beispiel #4
0
 def system(self, cmd, doexec=1):
     if not (cmd):
         return ""
     if self.log:
         self.log.info(cmd)
     if doexec:
         if not (self.fake):
             if (os.system(cmd)):
                 signal_error(self, cmd)
     else:
         return cmd
Beispiel #5
0
 def compile(self):
     self.set_xslt()
     self.cwdir = os.getcwd()
     self.tmpdir = self.tmpdir_user or tempfile.mkdtemp()
     if self.input:
         self.inputdir = os.path.dirname(self.input)
     else:
         self._stdin_write()
     os.chdir(self.tmpdir)
     try:
         donefiles = self._compile()
         if len(donefiles) == 1:
             shutil.move(donefiles[0], self.output)
             self.log.info("'%s' successfully built" % \
                           os.path.basename(self.output))
         else:
             for d in donefiles:
                 shutil.move(d, self.outputdir)
             donefiles.sort()
             self.log.info("Files successfully built in '%s':\n%s" % \
                           (self.outputdir, "\n".join(donefiles)))
     except Exception, e:
         signal_error(self, e)
Beispiel #6
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)
Beispiel #7
0
        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, e:
            signal_error(self, e)
            failed_exit("Error: %s" % e)