Example #1
0
 def doLoad():
     for what in whats:
         result = None
         apid = ApiHelper.loadApiType(what, apids=self._comparitor.apids, root=self._projectRoot)
         try:
             api = apid.api()
             NS = apid.ns()
             alreadyLoadedInSameNamespace = True
             found = True
             try:
                 if NS in self._namespaceWrapperControllers.keys():
                     raise DuplicateApiNamespaceError([(NS, apid.apiType())])
                 if NS in self._apiInstances.keys():
                     raise DuplicateApiNamespaceError([(NS, apid.apiType())])
                 if NS in self._namespace["__builtins__"].keys():
                     raise DuplicateApiNamespaceError([(NS, apid.apiType())])
             except DuplicateApiNamespaceError, _e:
                 #    Duplicate found, however is the apid the same?
                 alreadyLoadedInSameNamespace = False
                 for apid_ in self._comparitor.apids:
                     if apid==apid_:
                         #    Yes, no error, do nothing - module already loaded!
                         alreadyLoadedInSameNamespace = True
                         break
                 if alreadyLoadedInSameNamespace==False:
                     #    Another api is using the same namespace.
                     if mode==-1:
                         #    Should auto-blat with new namespace!
                         found = True
                     elif mode==2:
                         #    Api already loaded with same namespace.
                         found = False
                     elif mode==0:
                         #    Should auto-blat!
                         self._freshenNamespace(api, apid)
                         self._debugger.debug("API: Freshened '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what})
                         continue
                     elif mode==1:
                         #    Determine new methods and inject them using the NamespaceWrapperController:
                         self._updateNamespace(api, apid)
                         self._debugger.debug("API: Updated '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what})
                         continue
                     else:
                         raise
                 else:
                     #    Same api is using the same namespace.
                     found = False
             if found==True:
                 theApi = api(self._control, self._display, self._srcPath, self._debugger)
                 self._apiInstances[NS] = theApi
                 self._namespaceWrapperControllers[NS] = NamespaceWrapperController.create(apid, theApi.namespace(), waitOnEvent=self._getWaitOnEvent, debugger=self._debugger)
                 wrapper = self._namespaceWrapperControllers[NS].getWrapper()
                 self._comparitor.apids.append(apid)
                 self._namespace["__builtins__"][NS] = wrapper
                 self._debugger.debug("API: Loaded '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what})
             else:
                 self._debugger.debug("API: Already loaded '%(NS)s' from '%(W)s'"%{"NS":NS, "W":what})
         except Exception, result:
             raise
Example #2
0
 def create(apiTypes, allowDuplicates=False):
     r"""
     @summary: Import an api type from the file-system.
     """
     for type_ in apiTypes:
         apid = ApiHelper.loadApiType(type_)
         if allowDuplicates==False:
             try:
                 ApiFactory._find(type_)
             except Exception, _e:
                 pass
             else:
                 raise DuplicateApiNamespaceError([apid.ns()])
         ApiFactory._map.append(apid)
Example #3
0
 def create(apiTypes, allowDuplicates=False):
     r"""
     @summary: Import an api type from the file-system.
     """
     for type_ in apiTypes:
         apid = ApiHelper.loadApiType(type_)
         if allowDuplicates == False:
             try:
                 ApiFactory._find(type_)
             except Exception, _e:
                 pass
             else:
                 raise DuplicateApiNamespaceError([apid.ns()])
         ApiFactory._map.append(apid)
Example #4
0
 def _find(type_):
     #    All non-None fields must match exactly!
     if len(ApiFactory._map)==0:
         raise Exception("No apis loaded!")
     #    If multiple, raise InsufficientlySpecifiedApi(type_, [matching apis]).
     apid = ApiHelper.decodeApiType(type_)
     matching = []
     for item in ApiFactory._map:
         match = True
         for matcher in ["apiType", "clazzName", "ns", "path"]:
             attr = getattr(apid, matcher)()
             if attr!=None:
                 if getattr(item, matcher)()!=attr:
                     match = False
                     break
         if match==True:
             matching.append(item)
     if len(matching)>1:
         raise InsufficientlySpecifiedApiLoad(type_, matching)
     return matching[0]
Example #5
0
 def _find(type_):
     #    All non-None fields must match exactly!
     if len(ApiFactory._map) == 0:
         raise Exception("No apis loaded!")
     #    If multiple, raise InsufficientlySpecifiedApi(type_, [matching apis]).
     apid = ApiHelper.decodeApiType(type_)
     matching = []
     for item in ApiFactory._map:
         match = True
         for matcher in ["apiType", "clazzName", "ns", "path"]:
             attr = getattr(apid, matcher)()
             if attr != None:
                 if getattr(item, matcher)() != attr:
                     match = False
                     break
         if match == True:
             matching.append(item)
     if len(matching) > 1:
         raise InsufficientlySpecifiedApiLoad(type_, matching)
     return matching[0]