root/livinglogic.python.xist/src/ll/xist/scripts/tld2xsc.py @ 4436:b3c3ebbdfa3c

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

Remove defaults argument from tld2xsc. Add proper docstring to tld2xsc.

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