root/livinglogic.python.xist/src/ll/xist/scripts/dtd2xsc.py @ 2590:7b6bba35f3a0

Revision 2590:7b6bba35f3a0, 2.4 KB (checked in by Walter Doerwald <walter@…>, 13 years ago)

htmlspecials.pixel() now no longer uses colored pixels, instead color is
done via CSS. The URL for the one remaining transparent pixel can now be
specified via src (either as an XML attribute or via the converter context).

Rename attrs methods with() and without() to withnames() and withoutnames()
(for Python 2.5 compatibility).

Use elinks instead of w3m for asText() and move/rename this method to a
function ll.xist.ns.html.astext().

Try to make XIST independent from PyXML (however PyXML is still required
for parsing via expat and for dtd2xsc.py (because this requires xmlproc)).

Remove the long dperecated method withSep().

Use Py_ssize_t in the C source where appropriate.

Line 
1#! /usr/bin/env python
2# -*- coding: iso-8859-1 -*-
3
4## Copyright 1999-2006 by LivingLogic AG, Bayreuth/Germany.
5## Copyright 1999-2006 by Walter Dörwald
6##
7## All Rights Reserved
8##
9## See xist/__init__.py for the license
10
11"""
12<par>Module that helps to create &xist; namespace modules from &dtd;s.
13Needs <app>xmlproc</app> from the <app>PyXML</app> package.
14For usage information type:</par>
15<prog>
16dtd2xsc --help
17</prog>
18"""
19
20
21__version__ = "$Revision$"[11:-2]
22# $Source$
23
24
25import sys, os.path, optparse
26
27from xml.parsers.xmlproc import dtdparser
28
29from ll import url
30from ll.xist import xsc, parsers, xnd
31
32
33def dtd2xsc(dtdurl, outurl, verbose, xmlname, xmlurl, shareattrs, asmod, defaults):
34    if verbose:
35        print "Parsing DTD %s ..." % dtdurl
36    d = dtdparser.load_dtd(dtdurl.url)
37
38    if verbose:
39        print "Converting ..."
40    data = xnd.fromdtd(d, xmlname, xmlurl)
41
42    if shareattrs=="dupes":
43        data.shareattrs(False)
44    elif shareattrs=="all":
45        data.shareattrs(True)
46
47    if verbose:
48        print "Writing to %s ..." % outurl
49    file = outurl.openwrite()
50    file.write(data.aspy(asmod=asmod, defaults=defaults))
51    file.close()
52
53
54def main():
55    p = optparse.OptionParser(usage="usage: %prog [options] inputurl.dtd")
56    p.add_option("-o", "--output", dest="output", metavar="FILE", help="write output to FILE")
57    p.add_option("-v", "--verbose", action="store_true", dest="verbose")
58    p.add_option("-p", "--prefix", dest="xmlname", help="the XML prefix for this namespace", default="prefix", metavar="PREFIX")
59    p.add_option("-u", "--url", dest="xmlurl", help="the XML namespace name", metavar="URL")
60    p.add_option("-a", "--shareattrs", dest="shareattrs", help="Should identical attributes be shared among elements?", choices=("none", "dupes", "all"), default="dupes")
61    p.add_option("-m", "--model", dest="model", default="once", help="Add sims information to the namespace", choices=("no", "all", "once"))
62    p.add_option("-d", "--defaults", action="store_true", dest="defaults", help="Output default values for attributes")
63
64    (options, args) = p.parse_args()
65    if len(args) != 1:
66        p.error("incorrect number of arguments")
67        return 1
68    input = url.URL(args[0])
69    if options.output is None:
70        output = url.File(input.withExt("py").file)
71    else:
72        output = url.URL(options.output)
73    dtd2xsc(input, output, options.verbose, options.xmlname, options.xmlurl, options.shareattrs, options.model, options.defaults)
74
75
76if __name__ == "__main__":
77    sys.exit(main())
Note: See TracBrowser for help on using the browser.