VirtualBox

Changeset 19883 in vbox for trunk/src


Ignore:
Timestamp:
May 21, 2009 3:03:06 PM (16 years ago)
Author:
vboxsync
Message:

Python: generate constants, instead of relying on (*)COM mechanisms (WIP)

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r19853 r19883  
    174174# so for users it look 'just being here'
    175175VBox-python-glue_SOURCES = glue/vboxapi.py=>glue/python/vboxapi.py
     176
     177VBOX_PYTHON_CONSTANTS = $(VBOX_PATH_SDK)/bindings/glue/python/VirtualBox_constants.py
     178OTHERS += $(VBOX_PYTHON_CONSTANTS)
    176179
    177180ifndef VBOX_ONLY_SDK # Note this goes on for *very* long
     
    721724        $(QUIET)$(VBOX_XSLTPROC) -o $@ $< $(VBOX_XIDL_FILE)
    722725
     726$(VBOX_PYTHON_CONSTANTS):  $(VBOX_PATH_MAIN_SRC)/glue/constants-python.xsl $(VBOX_XIDL_FILE) | $$(dir $$@)
     727        $(call MSG_TOOL,xsltproc,Python constants,$<,$@)
     728        $(VBOX_XSLTPROC) -o $@ $< $(VBOX_XIDL_FILE)
    723729
    724730# Aliases for testing purposes.
  • trunk/src/VBox/Main/glue/vboxapi.py

    r19859 r19883  
    4545                    raise AttributeError
    4646
    47             def __getattr__(self, attr):
    48                 if attr.startswith("__"):
    49                     raise AttributeError
    50 
    51                 consts = self.__dict__['_consts']
    52                 fake = consts.get(attr, None)
    53                 if fake != None:
    54                     return fake 
    55                 try:
    56                     name = makeFullName(self, attr)
    57                     return win32com.client.constants.__getattr__(name)
    58                 except AttributeError,e:
    59                     fake = ConstantFake(self, attr)
    60                     consts[attr] = fake
    61                     return fake     
     47        def __getattr__(self, attr):
     48            import win32com
     49            from win32com.client import constants
     50               
     51            if attr.startswith("__"):
     52                raise AttributeError
     53
     54            consts = self.__dict__['_consts']
     55           
     56            fake = consts.get(attr, None)
     57            if fake != None:
     58               return fake 
     59            try:
     60               name = self.__dict__['_name']
     61               parent = self.__dict__['_parent']
     62               while parent != None:                 
     63                  if parent._name is not None:
     64                    name = parent._name+'_'+name
     65                  parent = parent._parent
     66               
     67               if name is not None:
     68                  name += "_" + attr
     69               else:
     70                  name = attr
     71               print "ask",name
     72               return win32com.client.constants.__getattr__(name)
     73            except AttributeError,e:
     74               fake = PlatformMSCOM.ConstantFake(self, attr)
     75               consts[attr] = fake
     76               return fake
     77
    6278
    6379    class InterfacesWrapper:
     
    6682
    6783            def __getattr__(self, a):
     84                import win32com
     85                from win32com.client import constants
    6886                if a.startswith("__"):
    6987                    raise AttributeError
     
    7290                except AttributeError,e:
    7391                    return self.__dict__['_rootFake'].__getattr__(a)
    74 
    75     def makeFullName(fake, attr):
    76             name = fake._name
    77             parent = fake._parent
    78             while parent != None:
    79                 if parent._name is not None:
    80                     name = parent._name+'_'+name
    81                 parent = parent._parent
    82                
    83             if name is not None:
    84                 name += "_" + attr
    85             else:
    86                 name = attr
    87             return name
    8892
    8993    def __init__(self, params):
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette