root/livinglogic.python.xist/src/ll/xist/scripts/tld2xsc.py @ 4437:6f3d4e845072

Revision 4437:6f3d4e845072, 2.6 KB (checked in by Walter Doerwald <walter@…>, 8 years ago)

Fix typos in script documentation. Add examples. Bump version number.

Line 
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3
4## Copyright 1999-2011 by LivingLogic AG, Bayreuth/Germany
5## Copyright 1999-2011 by Walter Dörwald
6##
7## All Rights Reserved
8##
9## See ll/__init__.py for the license
10
11
12"""
13Purpose
14-------
15
16``tld2xsc`` is a script that converts a JSP Tag Library Descriptor XML file
17into a skeleton XIST namespace module. The tld file is read from stdin and
18the namespace module is printed to stdout.
19
20
21Options
22-------
23
24``tld2xsc`` supports the following options:
25
26    ``-s``, ``--shareattrs`` : ``none``, ``dupes``, ``all``
27        Should attributes be shared among the elements? ``none`` means that each
28        element will have its own standalone :class:`Attrs` class directly derived
29        from :class:`ll.xist.Elements.Attrs`. For ``dupes`` each attribute that is
30        used by more than one element will be moved into its own :class:`Attrs`
31        class. For ``all`` this will be done for all attributes.
32
33    ``-m``, ``--model`` : ``no``, ``simple``, ``fullall``, ``fullonce``
34        Add model information to the namespace. ``no`` doesn't add any model
35        information. ``simple`` only adds ``model = False`` or ``model = True``
36        (i.e. only the information whether the element must be empty or not).
37        ``fullall`` adds a :mod:`ll.xist.sims` model object to each element class.
38        ``fullonce`` adds full model information to, but reuses model objects for
39        elements which have the same model.
40"""
41
42__docformat__ = "reStructuredText"
43
44
45import sys, argparse
46
47from ll import misc, url
48from ll.xist import xsc, xfind, parse
49from ll.xist.ns import tld
50
51
52__docformat__ = "reStructuredText"
53
54
55def makexnd(stream, encoding=None, shareattrs="dupes", model="simple"):
56    # :var:`stream` can be a stream, an :class:`URL` or a string
57    node = parse.tree(stream, parse.Expat(), parse.NS(tld), parse.Node())
58
59    # get and convert the taglib object
60    xnd = node.walknodes(tld.taglib)[0].asxnd(model=model)
61
62    if shareattrs=="dupes":
63        xnd.shareattrs(False)
64    elif shareattrs=="all":
65        xnd.shareattrs(True)
66    return xnd
67
68
69def main(args=None):
70    p = argparse.ArgumentParser(description="Convert JSP Tag Library Descriptor XML file (on stdin) to XIST namespace (on stdout)")
71    p.add_argument("-s", "--shareattrs", dest="shareattrs", help="Should identical attributes be shared among elements? (default %(default)s)", choices=("none", "dupes", "all"), default="dupes")
72    p.add_argument("-m", "--model", dest="model", help="Add sims information to the namespace (default %(default)s)", choices=("none", "simple", "fullall", "fullonce"), default="simple")
73
74    args = p.parse_args(args)
75    print makexnd(sys.stdin, args.shareattrs, model=args.model)
76
77
78if __name__ == "__main__":
79    sys.exit(main())
Note: See TracBrowser for help on using the browser.