Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes
xpcom.server.loader.PythonComponentLoader Class Reference

List of all members.

Public Member Functions

def __init__
def getFactory
def init
def onRegister
def autoRegisterComponents
def autoRegisterComponent
def autoUnregisterComponent
def registerDeferredComponents
def unloadAll

Public Attributes

 com_modules
 moduleFactory
 num_modules_this_register
 comp_mgr

Private Member Functions

def _getCOMModuleForLocation

Static Private Attributes

 _com_interfaces_ = components.interfaces.nsIComponentLoader
string _reg_clsid_ = "{63B68B1E-3E62-45f0-98E3-5E0B5797970C}"
string _reg_contractid_ = "moz.pyloader.1"
string _reg_desc_ = "Python component loader"
tuple _reg_registrar_ = (register_self,None)
string _reg_component_type_ = "script/python"

Detailed Description

Definition at line 74 of file loader.py.


Constructor & Destructor Documentation

Definition at line 85 of file loader.py.

00085 
00086     def __init__(self):
00087         self.com_modules = {} # Keyed by module's FQN as obtained from nsIFile.path
00088         self.moduleFactory = module.Module
00089         self.num_modules_this_register = 0


Member Function Documentation

def xpcom.server.loader.PythonComponentLoader._getCOMModuleForLocation (   self,
  componentFile 
) [private]

Definition at line 90 of file loader.py.

00090 
00091     def _getCOMModuleForLocation(self, componentFile):
00092         fqn = componentFile.path
00093         mod = self.com_modules.get(fqn)
00094         if mod is not None:
00095             return mod
00096         import ihooks, sys
00097         base_name = os.path.splitext(os.path.basename(fqn))[0]
00098         loader = ihooks.ModuleLoader()
00099 
00100         module_name_in_sys = "component:%s" % (base_name,)
00101         stuff = loader.find_module(base_name, [componentFile.parent.path])
00102         assert stuff is not None, "Couldnt find the module '%s'" % (base_name,)
00103         py_mod = loader.load_module( module_name_in_sys, stuff )
00104 
00105         # Make and remember the COM module.
00106         comps = FindCOMComponents(py_mod)
00107         mod = self.moduleFactory(comps)
00108         
00109         self.com_modules[fqn] = mod
00110         return mod
        

Here is the call graph for this function:

Here is the caller graph for this function:

def xpcom.server.loader.PythonComponentLoader.autoRegisterComponent (   self,
  when,
  componentFile 
)

Definition at line 167 of file loader.py.

00167 
00168     def autoRegisterComponent (self, when, componentFile):
00169         # bool return
00170         
00171         # Check if we actually need to do anything
00172         modtime = componentFile.lastModifiedTime
00173         loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
00174         if not loader_mgr.hasFileChanged(componentFile, None, modtime):
00175             return 1
00176 
00177         if self.num_modules_this_register == 0:
00178             # New components may have just installed new Python
00179             # modules into the main python directory (including new .pth files)
00180             # So we ask Python to re-process our site directory.
00181             # Note that the pyloader does the equivalent when loading.
00182             try:
00183                 from xpcom import _xpcom
00184                 import site
00185                 NS_XPCOM_CURRENT_PROCESS_DIR="XCurProcD"
00186                 dirname = _xpcom.GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR)
00187                 dirname.append("python")
00188                 site.addsitedir(dirname.path)
00189             except:
00190                 print "PyXPCOM loader failed to process site directory before component registration"
00191                 traceback.print_exc()
00192 
00193         self.num_modules_this_register += 1
00194 
00195         # auto-register via the module.
00196         m = self._getCOMModuleForLocation(componentFile)
00197         m.registerSelf(components.manager, componentFile, None, self._reg_component_type_)
00198         loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
00199         loader_mgr.saveFileInfo(componentFile, None, modtime)
00200         return 1

Here is the call graph for this function:

Here is the caller graph for this function:

def xpcom.server.loader.PythonComponentLoader.autoRegisterComponents (   self,
  when,
  directory 
)

Definition at line 134 of file loader.py.

00134 
00135     def autoRegisterComponents (self, when, directory):
00136         directory_path = directory.path
00137         self.num_modules_this_register = 0
00138         if xpcom.verbose:
00139             print "Auto-registering all Python components in", directory_path
00140 
00141         # ToDo - work out the right thing here
00142         # eg - do we recurse?
00143         # - do we support packages?
00144         entries = directory.directoryEntries
00145         while entries.HasMoreElements():
00146             entry = entries.GetNext(components.interfaces.nsIFile)
00147             if os.path.splitext(entry.path)[1]==".py":
00148                 try:
00149                     self.autoRegisterComponent(when, entry)
00150                 # Handle some common user errors
00151                 except xpcom.COMException, details:
00152                     from xpcom import nsError
00153                     # If the interface name does not exist, suppress the traceback
00154                     if details.errno==nsError.NS_ERROR_NO_INTERFACE:
00155                         print "** Registration of '%s' failed\n %s" % (entry.leafName,details.message,)
00156                     else:
00157                         print "** Registration of '%s' failed!" % (entry.leafName,)
00158                         traceback.print_exc()
00159                 except SyntaxError, details:
00160                     # Syntax error in source file - no useful traceback here either.
00161                     print "** Registration of '%s' failed!" % (entry.leafName,)
00162                     traceback.print_exception(SyntaxError, details, None)
00163                 except:
00164                     # All other exceptions get the full traceback.
00165                     print "** Registration of '%s' failed!" % (entry.leafName,)
00166                     traceback.print_exc()

Here is the call graph for this function:

def xpcom.server.loader.PythonComponentLoader.autoUnregisterComponent (   self,
  when,
  componentFile 
)

Definition at line 201 of file loader.py.

00201 
00202     def autoUnregisterComponent (self, when, componentFile):
00203         # bool return
00204         # auto-unregister via the module.
00205         m = self._getCOMModuleForLocation(componentFile)
00206         loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
00207         try:
00208             m.unregisterSelf(components.manager, componentFile)
00209         finally:
00210             loader_mgr.removeFileInfo(componentFile, None)
00211         return 1

Here is the call graph for this function:

def xpcom.server.loader.PythonComponentLoader.getFactory (   self,
  clsid,
  location,
  type 
)

Definition at line 111 of file loader.py.

00111 
00112     def getFactory(self, clsid, location, type):
00113         # return the factory
00114         assert type == self._reg_component_type_, "Being asked to create an object not of my type:%s" % (type,)
00115         # FIXME: how to do this without obsolete component manager?
00116         cmo = components.manager.queryInterface(components.interfaces.nsIComponentManagerObsolete)       
00117         file_interface = cmo.specForRegistryLocation(location)
00118         # delegate to the module.
00119         m = self._getCOMModuleForLocation(file_interface)
00120         return m.getClassObject(components.manager, clsid, components.interfaces.nsIFactory)

Here is the call graph for this function:

def xpcom.server.loader.PythonComponentLoader.init (   self,
  comp_mgr,
  registry 
)

Definition at line 121 of file loader.py.

00121 
00122     def init(self, comp_mgr, registry):
00123         # void
00124         self.comp_mgr = comp_mgr
00125         if xpcom.verbose:
00126             print "Python component loader init() called"
00127 
00128      # Called when a component of the appropriate type is registered,
00129      # to give the component loader an opportunity to do things like
     # annotate the registry and such.
def xpcom.server.loader.PythonComponentLoader.onRegister (   self,
  clsid,
  type,
  className,
  proId,
  location,
  replace,
  persist 
)

Definition at line 130 of file loader.py.

00130 
00131     def onRegister (self, clsid, type, className, proId, location, replace, persist):
00132         if xpcom.verbose:
00133             print "Python component loader - onRegister() called"

Definition at line 212 of file loader.py.

00212 
00213     def registerDeferredComponents (self, when):
00214         # bool return
00215         if xpcom.verbose:
00216             print "Python component loader - registerDeferred() called"
        return 0 # no more to register

Definition at line 217 of file loader.py.

00217 
00218     def unloadAll (self, when):
00219         if xpcom.verbose:
00220             print "Python component loader being asked to unload all components!"
00221         self.comp_mgr = None
00222         self.com_modules = {}


Member Data Documentation

xpcom.server.loader.PythonComponentLoader._com_interfaces_ = components.interfaces.nsIComponentLoader [static, private]

Definition at line 75 of file loader.py.

string xpcom.server.loader.PythonComponentLoader._reg_clsid_ = "{63B68B1E-3E62-45f0-98E3-5E0B5797970C}" [static, private]

Definition at line 76 of file loader.py.

Definition at line 83 of file loader.py.

Definition at line 77 of file loader.py.

string xpcom.server.loader.PythonComponentLoader._reg_desc_ = "Python component loader" [static, private]

Definition at line 78 of file loader.py.

Definition at line 81 of file loader.py.

Definition at line 86 of file loader.py.

Definition at line 123 of file loader.py.

Definition at line 87 of file loader.py.

Definition at line 88 of file loader.py.


The documentation for this class was generated from the following file: