~ubuntu-branches/ubuntu/intrepid/dblatex/intrepid

« back to all changes in this revision

Viewing changes to lib/dbtexmf/core/dbtex.py

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Hoenen
  • Date: 2008-04-14 20:00:57 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080414200057-eug1i8gwbcc8n27q
Tags: 0.2.8-7
* In db2latex style for multiple authors avoid exceeding the right border
  of the title page.  Thanks to W. Martin Borgert for reporting.
  Closes: #465221
* Localize REFERENCE label in native style and omit printing it when empty.
  Thanks to Roland Stigge for reporting.  Closes: #466162
* Adapt the section entry in dblatex.doc-base: Applications/Text -> Text
* Actualize the copyright dates in debian/copyright.
* Actualize my mail address in all debian files except changelog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
            self.set_base(base)
42
42
        self.xslopts = []
43
43
        self.xslparams = []
44
 
        self.xsluser = ""
 
44
        self.xslusers = []
45
45
        self.flags = self.USE_MKLISTINGS
 
46
        self.stdindir = ""
 
47
        self.inputdir = ""
46
48
        self.input = ""
47
49
        self.input_format = "xml"
48
50
        self.output = ""
120
122
            return "unknown"
121
123
 
122
124
    def build_stylesheet(self, wrapper="custom.xsl"):
123
 
        if not(self.xslparams or self.xsluser):
 
125
        if not(self.xslparams or self.xslusers):
124
126
            self.xslbuild = self.xslmain
125
127
            return
126
128
 
131
133
                version="1.0">
132
134
                \n""")
133
135
        f.write('<xsl:import href="%s"/>\n' % path_to_uri(self.xslmain))
134
 
        if self.xsluser:
135
 
            f.write('<xsl:import href="%s"/>\n' % path_to_uri(self.xsluser))
 
136
        for xsluser in self.xslusers:
 
137
            f.write('<xsl:import href="%s"/>\n' % path_to_uri(xsluser))
136
138
 
137
139
        for param in self.xslparams:
138
140
            v = param.split("=", 1)
216
218
        self.set_xslt()
217
219
        self.cwdir = os.getcwd()
218
220
        self.tmpdir = self.tmpdir_user or tempfile.mkdtemp()
219
 
        self.inputdir = os.path.dirname(self.input)
 
221
        if self.input:
 
222
            self.inputdir = os.path.dirname(self.input)
 
223
        else:
 
224
            self._stdin_write()
220
225
        os.chdir(self.tmpdir)
221
226
        try:
222
227
            donefile = self._compile()
229
234
            else:
230
235
                print "%s not removed" % self.tmpdir
231
236
 
 
237
    def _stdin_write(self):
 
238
        # Find out the stdin working directory
 
239
        self.inputdir = self.stdindir or self.cwdir
 
240
 
 
241
        # Need to dump the stdin input, because of the two passes
 
242
        self.input = os.path.join(self.tmpdir, "stdin.xml")
 
243
        f = open(self.input, "w")
 
244
        for line in sys.stdin:
 
245
            f.write(line)
 
246
        f.close()
 
247
 
232
248
    def _compile(self):
233
249
        # The temporary output file
234
250
        tmpout = os.path.basename(self.input)
290
306
                          help="All the tex output is printed")
291
307
        parser.add_option("-c", "-S", "--config",
292
308
                          help="Configuration file")
 
309
        parser.add_option("-C", "--changedir",
 
310
                          help="Standard input working directory")
293
311
        parser.add_option("-d", "--debug", action="store_true",
294
312
                          help="Debug mode. Keep the temporary directory in "
295
313
                               "which %s actually works" % prog)
316
334
        parser.add_option("-o", "--output", dest="output",
317
335
                          help="Output filename. When not used, the input filename "
318
336
                               "is used, with the suffix of the output format")
319
 
        parser.add_option("-p", "--xsl-user",
 
337
        parser.add_option("-p", "--xsl-user", action="append",
320
338
                          help="XSL user configuration file to use")
321
339
        parser.add_option("-P", "--param", dest="xslparams",
322
340
                          action="append", metavar="PARAM=VALUE",
426
444
            run.backend = options.backend
427
445
 
428
446
        if options.xsl_user:
429
 
            xsluser = os.path.realpath(options.xsl_user)
430
 
            if not(os.path.isfile(xsluser)):
431
 
                failed_exit("Error: '%s' does not exist" % options.xsl_user)
432
 
            run.xsluser = xsluser
 
447
            for xfile in options.xsl_user:
 
448
                xsluser = os.path.realpath(xfile)
 
449
                if not(os.path.isfile(xsluser)):
 
450
                    failed_exit("Error: '%s' does not exist" % options.xsl_user)
 
451
                run.xslusers.append(xsluser)
433
452
 
434
453
        if options.texpost:
435
454
            path = os.path.realpath(options.texpost)
516
535
        # Verbose mode
517
536
        run.log = logger(self.prog, run.verbose)
518
537
 
519
 
        input = os.path.realpath(args[0])
 
538
        # Data from standard input?
 
539
        if args[0] == "-":
 
540
            if not(options.output):
 
541
                failed_exit("Error: -o expected when input from stdin")
 
542
            input = ""
 
543
            if options.changedir:
 
544
                run.stdindir = os.path.realpath(options.changedir)
 
545
        else:
 
546
            input = os.path.realpath(args[0])
520
547
 
521
548
        # The output name can be deduced from the input one:
522
549
        # /path/to/input.xml -> /path/to/input.{tex|pdf|dvi|ps}