I have write an example. Now it can only add the import module automatically .
see the attachment.

What about this way to add the NOT_GENERATED codes?

if OK, I will go ahead to add the left NOT_GENERATED codes.
such as  how to add an attribute of an class.



On 05/28/2012 03:54 PM, ShaoHe Feng wrote:
On 05/28/2012 03:26 PM, ShaoHe Feng wrote:
On 05/28/2012 02:56 PM, Michael Pasternak wrote:
On 05/27/2012 08:06 PM, ShaoHe Feng wrote:
On 05/26/2012 01:48 AM, Michael Pasternak wrote:
Hi,

On 05/24/2012 09:13 PM, ShaoHe Fen3g wrote:
Hi all,

Now I'm using the code generation suites of ovirt-engine-sdk, I find it is very troublesome.
I completely agree with you, automating python entities generation is on top
of my TODO stack see [1],

Along with this, there was always something more important to do, and
it was delayed time after time, so your help is most welcome.

[1] http://www.ovirt.org/wiki/SDK#codegen

IMO,  we can simplify the process. And I want to engaged in it.

there are two tools parse the api.xsd and generate the params.py code. They are generateds_gui.py and generateDS.py. but there still some code can not be generate by these tools. now we should add these codes manually.

the not NOT_GENERATED codes are as follow in the current params.py code:
1.  import python module
2.  a new attribute of GeneratedsSuper class
3.  modify the get_root_tag function.
4.  modify the parseString function to shut up the stdout.
5.  _rootClassMap
6 . _elementToClassMap
7. findRootClass

And I have two ideas about the code generation.
For we should not modify the generateDS.py tools.
But we can improve it.

I think the 1, 2, 3, 7, can be hard-code, and 4, 5 and 6 can be configured. So I want to add an configure file to tell how to add the extra code that are not generated by generateDS.py tools. And new python program, as extension of generateDS.py to read the configure file and generate these codes.
sounds good, btw 5,6 can be constructed programmatically using __all__ generated by generateDS
and finding element name in xsd by type (from __all__).
should all the element name in xsd by type be added to _rootClassMap, and no element can be exception?
basically yes, cause _rootClassMap is<name, type> holder which used for (by name) type retrieval, only exception is if certain type is not referenced by any other type (then none will look for
it during the type construction), but i would not implement this logic.

Hi Michael,
what's your account on ovirt IRC channel?
seem I can not log on the #ovirt IRC channel.

still some questions.
can I edit the generateDS.py directly in order to generate the params.py code that we expect. and then rename the generateDS.py, put it into the SDK directory?
or an new py program to call the functions of generateDS?

Or without the configure file, just make the new python program that supports an interactive commands.



_______________________________________________
Engine-devel mailing list
Engine-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-devel



_______________________________________________
Engine-devel mailing list
Engine-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-devel


#!/usr/bin/python
#
# Copyright (c) 2010 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#           http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import re
import sys
#I have find a good way to import the generateDS module,
# So I add this module path to sys path, tentatively
sys.path.append("/usr/lib/python2.7/site-packages/generateDS-2.7b-py2.7.egg/EGG-INFO/scripts/")
try:
    import generateDS
except ImportError:
    print "Error: Module generateDS not available."
    exit(1)
from generateDS import *

def findTheLastImportModule(headTemplate):
    # I suppose the code generated by generateDS should import some code. 
    p = re.compile('\nimport\s.*')
    match = p.findall(headTemplate)
    return  match.pop()

def addExtraImportModule(headTemplate, rule, modules=[]): 
    if not modules or not rule:
        return headTemplate
    replace = rule + "\n\n# Begin NOT_GENERATED\n"
    for moudle in modules:
        replace = replace + moudle + "\n" 
    replace = replace + "# End NOT_GENERATED"
    return re.sub(rule, replace, generateDS.TEMPLATE_HEADER, 1)

rule = findTheLastImportModule(generateDS.TEMPLATE_HEADER)

#this modules list can be set in a configure file
modules = ["from ovirtsdk.utils.reflectionhelper import ReflectionHelper"]
generateDS.TEMPLATE_HEADER = addExtraImportModule(
                    generateDS.TEMPLATE_HEADER, rule, modules)
#now, it is ok to add the import module.
print generateDS.TEMPLATE_HEADER

_______________________________________________
Engine-devel mailing list
Engine-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-devel

Reply via email to