diff --git a/README b/README index a707e28fe123c45ea1c85c9cb79f8c1643b6a983..08ef6a863cd124f83091d66e7b9431f9c2c3a8ca 100644 --- a/README +++ b/README @@ -141,6 +141,17 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Change history -------------- +Version 2.10b (06/10/2013) +- Changed flag for generating getters and setters. Removed flag + --use-old-getter-setter. Replaced it with new flag + --use-getter-setter, which can have the following values: + "old" - Name getters/setters getVar()/setVar(). + "new" - Name getters/setters get_var()/set_var(). + "none" - Do not generate getter/setter methods. + The default is "new". See the help (use --help option) or see the + doc (generateDS.txt/generateDS.html) for more on this. Thanks to + Mike Vella for suggesting this. + Version 2.10a (05/29/2013) - Added ability to produce mapping (a dict) during call to to_etree() that maps gDS instances to their associated etree diff --git a/generateDS.html b/generateDS.html index 520a2c11823d838835390b44e3adecf9ca33057f..221ecb29b4ded24edf81cda1330d30c02d2dd314 100644 --- a/generateDS.html +++ b/generateDS.html @@ -225,7 +225,7 @@ They are used by updateversion.py. --> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> -<tr class="field"><th class="field-name">date:</th><td class="field-body">May 30, 2013</td> +<tr class="field"><th class="field-name">date:</th><td class="field-body">June 10, 2013</td> </tr> </tbody> </table> @@ -517,11 +517,17 @@ Options: Default="Sub". --root-element="XXX" Assume XXX is root element of instance docs. Default is first element defined in schema. - --super="XXX" Super module name in subclass module. Default="???" + Also see section "Recognizing the top level + element" in the documentation. + --super="XXX" Super module name in generated in subclass + module. Default="???" --validator-bodies=path Path to a directory containing files that provide bodies (implementations) of validator methods. - --use-old-getter-setter Name getters and setters getVar() and setVar(), - instead of get_var() and set_var(). + --use-getter-setter Generate getter and setter methods. Values: + "old" - Name getters/setters getVar()/setVar(). + "new" - Name getters/setters get_var()/set_var(). + "none" - Do not generate getter/setter methods. + Default is "new". --user-methods= <module>, -u <module> Optional module containing user methods. See section "User Methods" in the documentation. @@ -529,10 +535,10 @@ Options: files. This is useful if you want to minimize the amount of (no-operation) changes to the generated python code. - --no-versions Do not include the current version in the generated - files. This is useful if you want to minimize - the amount of (no-operation) changes to the - generated python code. + --no-versions Do not include the current version in the + generated files. This is useful if you want + to minimize the amount of (no-operation) + changes to the generated python code. --no-process-includes Do not process included XML Schema files. By default, generateDS.py will insert content from files referenced by <include ... /> @@ -556,7 +562,7 @@ Options: class: a dictionary of instances of class MemberSpec_ containing member name, type, and array or not. Allowed values are - "list" or "dict". Default: None. + "list" or "dict". Default: do not generate. --export=<export-list> Specifies export functions to be generated. Value is a whitespace separated list of any of the following: @@ -564,15 +570,28 @@ Options: literal -- write out python code etree -- build element tree (can serialize to XML) - Examples: --export="write etree" - --export="write" - Default: --export="write literal" + Example: "write etree" + Default: "write" -q, --no-questions Do not ask questions, for example, force overwrite. --session=mysession.session Load and use options from session file. You can - create session file in generateds_gui.py. + create session file in generateds_gui.py. Or, + copy and edit sample.session from the + distribution. --version Print version and exit. + +Usage example: + + $ python generateDS.py -f -o sample_lib.py sample_api.xsd + +creates (with force over-write) sample_lib.py from sample_api.xsd. + + $ python generateDS.py -o sample_lib.py -s sample_app1.py \ + --member-specs=dict sample_api.xsd + +creates sample_lib.py superclass and sample_app1.py subclass modules; +also generates member specifications in each class (in a dictionary). </pre> <p>The following command line flags are recognized by <tt class="docutils literal">generateDS.py</tt>:</p> <dl class="docutils"> @@ -655,13 +674,22 @@ an optional ".py" extension. If a file is not provided for a given type, an empty body (<tt class="docutils literal">pass</tt>) is generated. In these files, lines with "##" in the first two columns are ignored and are not inserted.</dd> -<dt>use-old-getter-setter</dt> -<dd><tt class="docutils literal">generateDS.py</tt> now generates getter and setter methods (for +<dt>use-getter-setter</dt> +<dd><p class="first"><tt class="docutils literal">generateDS.py</tt> now generates getter and setter methods (for variable "abc", for example) with the names get_abc() and -set_abc(), which I believe is a more Pythonic style, instead -of getAbc() and setAbc(), which was the old behavior. Use -this flag to generate getters and setters in the old style -(getAbc() and setAbc()).</dd> +set_abc(), which I believe is a more Pythonic style, instead of +getAbc() and setAbc(), which was the old behavior. Use this +flag to generate getters and setters in the old style (getAbc() +and setAbc()) or the newer style(get_abc() and set_abc()) which +is the default or to omit generation of getter and setter +methods. Possible values are:</p> +<ul class="simple"> +<li>"old" - Name getters/setters getVar()/setVar().</li> +<li>"new" - Name getters/setters get_var()/set_var().</li> +<li>"none" - Do not generate getter/setter methods.</li> +</ul> +<p class="last">The default is "new".</p> +</dd> <dt>u, user-methods=<module></dt> <dd>If specified, <tt class="docutils literal">generateDS.py</tt> will add methods to generated classes as specified in the indicated module. For more diff --git a/generateDS.py b/generateDS.py index efebfc75ab7b021945384602982297ccec3475d4..86240f07a86269e3a722537f93b870d7b31dcd4f 100755 --- a/generateDS.py +++ b/generateDS.py @@ -27,8 +27,11 @@ Options: module. Default="???" --validator-bodies=path Path to a directory containing files that provide bodies (implementations) of validator methods. - --use-old-getter-setter Name getters and setters getVar() and setVar(), - instead of get_var() and set_var(). + --use-getter-setter Generate getter and setter methods. Values: + "old" - Name getters/setters getVar()/setVar(). + "new" - Name getters/setters get_var()/set_var(). + "none" - Do not generate getter/setter methods. + Default is "new". --user-methods= <module>, -u <module> Optional module containing user methods. See section "User Methods" in the documentation. @@ -164,11 +167,11 @@ logging.disable(logging.INFO) # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## -VERSION = '2.10a' +VERSION = '2.10b' ##VERSION## GenerateProperties = 0 -UseOldGetterSetter = 0 +UseGetterSetter = 'new' MemberSpecs = None DelayedElements = [] DelayedElements_subclass = [] @@ -2382,8 +2385,8 @@ def generateExportChildren(wrt, element, hasChildren, namespace): any_type_child = child else: if abstract_child and child.getMaxOccurs() > 1: - wrt("%sfor %s_ in self.get%s():\n" % (fill, - name, make_gs_name(name),)) + wrt("%sfor %s_ in self.%s:\n" % ( + fill, name, name,)) wrt("%s %s_.export(outfile, level, namespace_, " "name_='%s', pretty_print=pretty_print)\n" % ( fill, name, name, )) @@ -3397,7 +3400,7 @@ def generateBuildStandard_1( name = substitutionGroup else: name = headName - s1 = " self.set%s(obj_)\n" % (make_gs_name(name), ) + s1 = " self.%s = obj_\n" % (name, ) wrt(s1) # # If this child is defined in a simpleType, then generate @@ -4136,7 +4139,8 @@ def generateClasses(wrt, prefix, element, delayed): wrt(' else:\n') wrt(' return %s%s(*args_, **kwargs_)\n' % (prefix, name)) wrt(' factory = staticmethod(factory)\n') - generateGettersAndSetters(wrt, element) + if UseGetterSetter != 'none': + generateGettersAndSetters(wrt, element) if Targetnamespace in NamespacesDict: namespace = NamespacesDict[Targetnamespace] else: @@ -5548,10 +5552,12 @@ def cleanupName(oldName): def make_gs_name(oldName): - if UseOldGetterSetter: + if UseGetterSetter == 'old': newName = oldName.capitalize() - else: + elif UseGetterSetter == 'new': newName = '_%s' % oldName + else: + newName = '' return newName ## def mapName(oldName): @@ -5777,7 +5783,7 @@ def usage(): def main(): global Force, GenerateProperties, SubclassSuffix, RootElement, \ - ValidatorBodiesBasePath, UseOldGetterSetter, \ + ValidatorBodiesBasePath, UseGetterSetter, \ UserMethodsPath, XsdNameSpace, \ Namespacedef, NoDates, NoVersion, \ TEMPLATE_MAIN, TEMPLATE_SUBCLASS_FOOTER, Dirpath, \ @@ -5791,7 +5797,7 @@ def main(): [ 'help', 'subclass-suffix=', 'root-element=', 'super=', - 'validator-bodies=', 'use-old-getter-setter', + 'validator-bodies=', 'use-getter-setter=', 'user-methods=', 'no-process-includes', 'silence', 'namespacedef=', 'external-encoding=', 'member-specs=', 'no-dates', 'no-versions', @@ -5848,7 +5854,7 @@ def main(): if sessionObj.get_superclass_module(): superModule = sessionObj.get_superclass_module() if sessionObj.get_old_getters_setters(): - UseOldGetterSetter = 1 + UseGetterSetter = option[1] if sessionObj.get_validator_bodies(): ValidatorBodiesBasePath = sessionObj.get_validator_bodies() if not os.path.isdir(ValidatorBodiesBasePath): @@ -5905,8 +5911,13 @@ def main(): err_msg('*** Option validator-bodies must specify an ' 'existing path.\n') sys.exit(1) - elif option[0] == '--use-old-getter-setter': - UseOldGetterSetter = 1 + elif option[0] == '--use-getter-setter': + if option[1] in ('old', 'new', 'none'): + UseGetterSetter = option[1] + else: + err_msg('*** Option use-getter-setter must ' + '"old" or "new" or "none".\n') + sys.exit(1) elif option[0] in ('-u', '--user-methods'): UserMethodsPath = option[1] elif option[0] == '--no-process-includes': diff --git a/generateDS.txt b/generateDS.txt index ea0ab905779955e8289497d7505a6cbf517c03ee..e1134f24035fb9117784f0f1b6f801e519875faa 100644 --- a/generateDS.txt +++ b/generateDS.txt @@ -11,7 +11,7 @@ generateDS -- Generate Data Structures from XML Schema .. version -:revision: 2.10a +:revision: 2.10b .. version @@ -221,11 +221,17 @@ Here is the usage message displayed by ``generateDS.py``:: Default="Sub". --root-element="XXX" Assume XXX is root element of instance docs. Default is first element defined in schema. - --super="XXX" Super module name in subclass module. Default="???" + Also see section "Recognizing the top level + element" in the documentation. + --super="XXX" Super module name in generated in subclass + module. Default="???" --validator-bodies=path Path to a directory containing files that provide bodies (implementations) of validator methods. - --use-old-getter-setter Name getters and setters getVar() and setVar(), - instead of get_var() and set_var(). + --use-getter-setter Generate getter and setter methods. Values: + "old" - Name getters/setters getVar()/setVar(). + "new" - Name getters/setters get_var()/set_var(). + "none" - Do not generate getter/setter methods. + Default is "new". --user-methods= <module>, -u <module> Optional module containing user methods. See section "User Methods" in the documentation. @@ -233,10 +239,10 @@ Here is the usage message displayed by ``generateDS.py``:: files. This is useful if you want to minimize the amount of (no-operation) changes to the generated python code. - --no-versions Do not include the current version in the generated - files. This is useful if you want to minimize - the amount of (no-operation) changes to the - generated python code. + --no-versions Do not include the current version in the + generated files. This is useful if you want + to minimize the amount of (no-operation) + changes to the generated python code. --no-process-includes Do not process included XML Schema files. By default, generateDS.py will insert content from files referenced by <include ... /> @@ -247,7 +253,7 @@ Here is the usage message displayed by ``generateDS.py``:: --namespacedef='xmlns:abc="http://www.abc.com"' Namespace definition to be passed in as the value for the namespacedef_ parameter of - the export() method by the generated + the export() method by the generated parse() and parseString() functions. Default=''. --external-encoding=<encoding> @@ -260,7 +266,7 @@ Here is the usage message displayed by ``generateDS.py``:: class: a dictionary of instances of class MemberSpec_ containing member name, type, and array or not. Allowed values are - "list" or "dict". Default: None. + "list" or "dict". Default: do not generate. --export=<export-list> Specifies export functions to be generated. Value is a whitespace separated list of any of the following: @@ -268,15 +274,28 @@ Here is the usage message displayed by ``generateDS.py``:: literal -- write out python code etree -- build element tree (can serialize to XML) - Examples: --export="write etree" - --export="write" - Default: --export="write literal" + Example: "write etree" + Default: "write" -q, --no-questions Do not ask questions, for example, force overwrite. --session=mysession.session Load and use options from session file. You can - create session file in generateds_gui.py. - --version Print version and exit. + create session file in generateds_gui.py. Or, + copy and edit sample.session from the + distribution. + --version Print version and exit. + + Usage example: + + $ python generateDS.py -f -o sample_lib.py sample_api.xsd + + creates (with force over-write) sample_lib.py from sample_api.xsd. + + $ python generateDS.py -o sample_lib.py -s sample_app1.py \ + --member-specs=dict sample_api.xsd + + creates sample_lib.py superclass and sample_app1.py subclass modules; + also generates member specifications in each class (in a dictionary). The following command line flags are recognized by ``generateDS.py``: @@ -367,13 +386,21 @@ validator-bodies=<path> files, lines with "##" in the first two columns are ignored and are not inserted. -use-old-getter-setter +use-getter-setter ``generateDS.py`` now generates getter and setter methods (for variable "abc", for example) with the names get_abc() and - set_abc(), which I believe is a more Pythonic style, instead - of getAbc() and setAbc(), which was the old behavior. Use - this flag to generate getters and setters in the old style - (getAbc() and setAbc()). + set_abc(), which I believe is a more Pythonic style, instead of + getAbc() and setAbc(), which was the old behavior. Use this + flag to generate getters and setters in the old style (getAbc() + and setAbc()) or the newer style(get_abc() and set_abc()) which + is the default or to omit generation of getter and setter + methods. Possible values are: + + - "old" - Name getters/setters getVar()/setVar(). + - "new" - Name getters/setters get_var()/set_var(). + - "none" - Do not generate getter/setter methods. + + The default is "new". u, user-methods=<module> If specified, ``generateDS.py`` will add methods to generated diff --git a/librarytemplate_howto.txt b/librarytemplate_howto.txt index 6e8d71ca8ff827e47816a4cf13e57074f2acaba2..4e3c1aa4d7d0151117fdaae75929a86b869a06ce 100644 --- a/librarytemplate_howto.txt +++ b/librarytemplate_howto.txt @@ -8,7 +8,7 @@ How to package a generateDS.py generated library .. version -:revision: 2.10a +:revision: 2.10b .. version diff --git a/process_includes.py b/process_includes.py index ac7644a8a7b998dd5518a8401b792efa94889249..3f9389d04b38a3261dcae77c28a1160a0ecbab94 100755 --- a/process_includes.py +++ b/process_includes.py @@ -30,7 +30,7 @@ from lxml import etree # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## -VERSION = '2.10a' +VERSION = '2.10b' ##VERSION## Namespaces = {'xs': 'http://www.w3.org/2001/XMLSchema'} diff --git a/setup.py b/setup.py index a310e3ebe1e711deb65fae0af4cd279cc754a54a..2a4bbe9fae54a774dc7b85db791bdc2a39907b43 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup(name="generateDS", # Do not modify the following VERSION comments. # Used by updateversion.py. ##VERSION## - version="2.10a", + version="2.10b", ##VERSION## author="Dave Kuhlman", author_email="dkuhlman@rexx.com",