зеркало из https://github.com/mozilla/gecko-dev.git
When new components are registered, re-scan the Python directory for
new .pth files (which may have just been installed). Add _xpcom.GetSpecialDirectory() to make this work. Not part of the build.
This commit is contained in:
Родитель
337ac5a75d
Коммит
ca8e433988
|
@ -110,6 +110,7 @@ class PythonComponentLoader:
|
|||
|
||||
def autoRegisterComponents (self, when, directory):
|
||||
directory_path = directory.path
|
||||
self.num_modules_this_register = 0
|
||||
if xpcom.verbose:
|
||||
print "Auto-registering all Python components in", directory_path
|
||||
|
||||
|
@ -149,6 +150,24 @@ class PythonComponentLoader:
|
|||
if not loader_mgr.hasFileChanged(componentFile, None, modtime):
|
||||
return 1
|
||||
|
||||
if self.num_modules_this_register == 0:
|
||||
# New conponents may have just installed new Python
|
||||
# modules into the main python directory (including new .pth files)
|
||||
# So we ask Python to re-process our site directory.
|
||||
# Note that the pyloader does the equivalent when loading.
|
||||
try:
|
||||
from xpcom import _xpcom
|
||||
import site
|
||||
NS_XPCOM_CURRENT_PROCESS_DIR="XCurProcD"
|
||||
dirname = _xpcom.GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR)
|
||||
dirname.append("python")
|
||||
site.addsitedir(dirname.path)
|
||||
except:
|
||||
print "PyXPCOM loader failed to process site directory before component registration"
|
||||
traceback.print_exc()
|
||||
|
||||
self.num_modules_this_register += 1
|
||||
|
||||
# auto-register via the module.
|
||||
m = self._getCOMModuleForLocation(componentFile)
|
||||
m.registerSelf(components.manager, componentFile, None, self._reg_component_type_)
|
||||
|
|
|
@ -374,6 +374,19 @@ PyXPCOMMethod_GetProxyForObject(PyObject *self, PyObject *args)
|
|||
return result;
|
||||
}
|
||||
|
||||
PyObject *PyGetSpecialDirectory(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *dirname;
|
||||
if (!PyArg_ParseTuple(args, "s:GetSpecialDirectory", &dirname))
|
||||
return NULL;
|
||||
nsIFile *file = NULL;
|
||||
nsresult r = NS_GetSpecialDirectory(dirname, &file);
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
// returned object swallows our reference.
|
||||
return Py_nsISupports::PyObjectFromInterface(file, NS_GET_IID(nsIFile), PR_FALSE);
|
||||
}
|
||||
|
||||
PyObject *AllocateBuffer(PyObject *self, PyObject *args)
|
||||
{
|
||||
int bufSize;
|
||||
|
@ -419,6 +432,7 @@ static struct PyMethodDef xpcom_methods[]=
|
|||
{"_GetGatewayCount", PyXPCOMMethod_GetGatewayCount, 1},
|
||||
{"getProxyForObject", PyXPCOMMethod_GetProxyForObject, 1},
|
||||
{"GetProxyForObject", PyXPCOMMethod_GetProxyForObject, 1},
|
||||
{"GetSpecialDirectory", PyGetSpecialDirectory, 1},
|
||||
{"AllocateBuffer", AllocateBuffer, 1},
|
||||
{"LogWarning", LogWarning, 1},
|
||||
{"LogError", LogError, 1},
|
||||
|
|
Загрузка…
Ссылка в новой задаче