зеркало из https://github.com/mozilla/gecko-dev.git
Get pyxpcom building and working again, at least on Windows. file test
fails, but we can live with that for now. Not part of the build.
This commit is contained in:
Родитель
12b87e861c
Коммит
8b6dfce2a9
|
@ -18,8 +18,14 @@
|
|||
# The XPCOM (Cross Platform COM) package.
|
||||
import exceptions
|
||||
|
||||
#import sys
|
||||
|
||||
import sys
|
||||
#sys.stdout = open("pystdout.log", "w")
|
||||
if sys.version_info >= (2, 3):
|
||||
# sick off the new hex() warnings, and no time to digest what the
|
||||
# impact will be!
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore", category=FutureWarning, append=1)
|
||||
|
||||
# A global "verbose" flag - currently used by the
|
||||
# server package to print trace messages
|
||||
|
|
|
@ -324,7 +324,7 @@ class Component(_XPCOMBase):
|
|||
interface = self.__dict__['_interface_names_'][interface_name]
|
||||
setattr(interface, attr, val)
|
||||
return
|
||||
raise AttributeError, "XPCOM component '%s' can not set attribute '%s'" % (self._object_name_, attr)
|
||||
raise AttributeError, "XPCOM component '%s' has no attribute '%s'" % (self._object_name_, attr)
|
||||
def __repr__(self):
|
||||
# We can advantage from nsIClassInfo - use it.
|
||||
if not self._tried_classinfo_:
|
||||
|
|
|
@ -62,9 +62,13 @@ def LocalFileToURL(localFileName):
|
|||
.createInstance(components.interfaces.nsILocalFile)
|
||||
localFile.initWithPath(localFileName)
|
||||
|
||||
# Create a standard URL, but we QI for the FileURL interface!
|
||||
url = components.classes["@mozilla.org/network/standard-url;1"] \
|
||||
.createInstance(components.interfaces.nsIFileURL)
|
||||
# Use the IO Service to create the interface
|
||||
# Or not - I don't know - I give up.
|
||||
io_service = components.classes["@mozilla.org/network/io-service;1"] \
|
||||
.getService(components.interfaces.nsIIOService)
|
||||
url = io_service.newFileURI(localFile).queryInterface(components.interfaces.nsIFileURL)
|
||||
# url = components.classes["@mozilla.org/network/standard-url;1"] \
|
||||
# .createInstance(components.interfaces.nsIFileURL)
|
||||
# Setting the "file" attribute causes initialization...
|
||||
url.file = localFile
|
||||
return url
|
||||
|
|
|
@ -22,13 +22,10 @@ import factory
|
|||
import module
|
||||
|
||||
import glob, os, types
|
||||
import traceback
|
||||
|
||||
from xpcom.client import Component
|
||||
|
||||
fileSizeValueName = "FileSize"
|
||||
lastModValueName = "LastModTimeStamp"
|
||||
xpcomKeyName = "software/mozilla/XPCOM/components"
|
||||
|
||||
# Until we get interface constants.
|
||||
When_Startup = 0
|
||||
When_Component = 1
|
||||
|
@ -100,17 +97,6 @@ class PythonComponentLoader:
|
|||
|
||||
def init(self, comp_mgr, registry):
|
||||
# void
|
||||
registry = registry.QueryInterface(components.interfaces.nsIRegistry)
|
||||
try:
|
||||
self.xpcom_registry_key = registry.getSubtree(
|
||||
components.interfaces.nsIRegistry.Common,
|
||||
xpcomKeyName)
|
||||
# If we worked, we can use the registry!
|
||||
self.registry = registry
|
||||
except xpcom.Exception, details:
|
||||
print "Registry failed", details
|
||||
self.registry = None # no registry ops allowed
|
||||
|
||||
self.comp_mgr = comp_mgr
|
||||
if xpcom.verbose:
|
||||
print "Python component loader init() called"
|
||||
|
@ -124,8 +110,8 @@ class PythonComponentLoader:
|
|||
|
||||
def autoRegisterComponents (self, when, directory):
|
||||
directory_path = directory.path
|
||||
print "Auto-registering all Python components in", directory_path
|
||||
import traceback
|
||||
if xpcom.verbose:
|
||||
print "Auto-registering all Python components in", directory_path
|
||||
|
||||
# ToDo - work out the right thing here
|
||||
# eg - do we recurse?
|
||||
|
@ -157,29 +143,28 @@ class PythonComponentLoader:
|
|||
def autoRegisterComponent (self, when, componentFile):
|
||||
# bool return
|
||||
|
||||
reg_loc = components.manager.registryLocationForSpec(componentFile)
|
||||
# Use the registry to see if we actually need to do anything
|
||||
if not self._hasChanged(reg_loc, componentFile):
|
||||
# Check if we actually need to do anything
|
||||
modtime = componentFile.lastModifiedTime
|
||||
loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
|
||||
if not loader_mgr.hasFileChanged(componentFile, None, modtime):
|
||||
return 1
|
||||
|
||||
# Sheesh - it appears we should also use the observer service
|
||||
# to let the system know of our auto-register progress.
|
||||
|
||||
# auto-register via the module.
|
||||
m = self._getCOMModuleForLocation(componentFile)
|
||||
m.registerSelf(components.manager, componentFile, reg_loc, self._reg_component_type_)
|
||||
self._setRegistryInfo(reg_loc, componentFile)
|
||||
m.registerSelf(components.manager, componentFile, None, self._reg_component_type_)
|
||||
loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
|
||||
loader_mgr.saveFileInfo(componentFile, None, modtime)
|
||||
return 1
|
||||
|
||||
def autoUnregisterComponent (self, when, componentFile):
|
||||
# bool return
|
||||
# auto-unregister via the module.
|
||||
m = self._getCOMModuleForLocation(componentFile)
|
||||
reg_loc = components.manager.registryLocationForSpec(componentFile)
|
||||
loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
|
||||
try:
|
||||
m.unregisterSelf(components.manager, componentFile, reg_loc)
|
||||
m.unregisterSelf(components.manager, componentFile)
|
||||
finally:
|
||||
self._removeRegistryInfo( reg_loc, componentFile)
|
||||
loader_mgr.removeFileInfo(componentFile, None)
|
||||
return 1
|
||||
|
||||
def registerDeferredComponents (self, when):
|
||||
|
@ -190,46 +175,8 @@ class PythonComponentLoader:
|
|||
def unloadAll (self, when):
|
||||
if xpcom.verbose:
|
||||
print "Python component loader being asked to unload all components!"
|
||||
self.registry = None
|
||||
self.comp_mgr = None
|
||||
self.com_modules = {}
|
||||
# Internal Helpers
|
||||
def _setRegistryInfo(self, registry_location, nsIFile):
|
||||
if self.registry is None:
|
||||
return # No registry work allowed.
|
||||
e_location = self.registry.escapeKey(registry_location, 1)
|
||||
if e_location is None: # No escaped key needed.
|
||||
e_location = registry_location
|
||||
key = self.registry.addSubtreeRaw(self.xpcom_registry_key, e_location)
|
||||
self.registry.setLongLong(key, lastModValueName, nsIFile.lastModifiedTime)
|
||||
self.registry.setLongLong(key, fileSizeValueName, nsIFile.fileSize)
|
||||
def _hasChanged(self, registry_location, nsIFile):
|
||||
if self.registry is None:
|
||||
# Can't cache in registry - assume it has changed.
|
||||
return 1
|
||||
e_location = self.registry.escapeKey(registry_location, 1)
|
||||
if e_location is None: # No escaped key needed.
|
||||
e_location = registry_location
|
||||
try:
|
||||
key = self.registry.getSubtreeRaw(self.xpcom_registry_key, e_location)
|
||||
if nsIFile.lastModifiedTime != self.registry.getLongLong(key, lastModValueName):
|
||||
return 1
|
||||
if nsIFile.fileSize != self.registry.getLongLong(key, fileSizeValueName):
|
||||
return 1
|
||||
return 0
|
||||
except xpcom.Exception, details:
|
||||
return 1
|
||||
|
||||
def _removeRegistryInfo(self, registry_location, nsIFile):
|
||||
if self.registry is None:
|
||||
return # No registry work allowed.
|
||||
e_location = self.registry.escapeKey(registry_location, 1)
|
||||
if e_location is None: # No escaped key needed.
|
||||
e_location = registry_location
|
||||
try:
|
||||
key = self.registry.removeSubtreeRaw(self.xpcom_registry_key, e_location)
|
||||
except xpcom.Exception, details:
|
||||
pass
|
||||
|
||||
def MakePythonComponentLoaderModule(serviceManager, nsIFile):
|
||||
import module
|
||||
|
|
|
@ -42,28 +42,27 @@ class Module:
|
|||
# We can ignore the IID - the auto-wrapp process will automatically QI us.
|
||||
return factory.Factory(klass)
|
||||
|
||||
def registerSelf(self, compMgr, location, registryLocation, componentType):
|
||||
def registerSelf(self, compMgr, location, loaderStr, componentType):
|
||||
# void function.
|
||||
fname = os.path.basename(location.path)
|
||||
for klass in self.components.values():
|
||||
print "Registering: %s" % (klass.__name__,)
|
||||
reg_contractid = klass._reg_contractid_
|
||||
print "Registering '%s' (%s)" % (reg_contractid, fname)
|
||||
reg_desc = getattr(klass, "_reg_desc_", reg_contractid)
|
||||
compMgr.registerComponentWithType(klass._reg_clsid_,
|
||||
compMgr = compMgr.queryInterface(components.interfaces.nsIComponentRegistrar)
|
||||
compMgr.registerFactoryLocation(klass._reg_clsid_,
|
||||
reg_desc,
|
||||
reg_contractid,
|
||||
location,
|
||||
registryLocation,
|
||||
1,
|
||||
1,
|
||||
loaderStr,
|
||||
componentType)
|
||||
|
||||
# See if this class nominates custom register_self
|
||||
extra_func = getattr(klass, "_reg_registrar_", (None,None))[0]
|
||||
if extra_func is not None:
|
||||
extra_func(klass, compMgr, location, registryLocation, componentType)
|
||||
print "Registered %d Python components in %s" % (len(self.components),os.path.basename(location.path))
|
||||
extra_func(klass, compMgr, location, loaderStr, componentType)
|
||||
|
||||
def unregisterSelf(self, compMgr, location, registryLocation):
|
||||
def unregisterSelf(self, compMgr, location, loaderStr):
|
||||
# void function.
|
||||
for klass in self.components.values():
|
||||
ok = 1
|
||||
|
@ -75,7 +74,7 @@ class Module:
|
|||
extra_func = getattr(klass, "_reg_registrar_", (None,None))[1]
|
||||
if extra_func is not None:
|
||||
try:
|
||||
extra_func(klass, compMgr, location, registryLocation)
|
||||
extra_func(klass, compMgr, location, loaderStr)
|
||||
except Exception:
|
||||
ok = 0
|
||||
if ok:
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
// (c) 2000, ActiveState corp.
|
||||
|
||||
#include "PyXPCOM_std.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include <nsFileStream.h>
|
||||
|
||||
static char *PyTraceback_AsString(PyObject *exc_tb);
|
||||
|
@ -37,10 +38,17 @@ static char *PyTraceback_AsString(PyObject *exc_tb);
|
|||
|
||||
void LogMessage(const char *prefix, const char *pszMessageText)
|
||||
{
|
||||
nsOutputConsoleStream console;
|
||||
nsOutputStream console;
|
||||
console << prefix << pszMessageText;
|
||||
}
|
||||
|
||||
void LogMessage(const char *prefix, nsACString &text)
|
||||
{
|
||||
char *c = ToNewCString(text);
|
||||
LogMessage(prefix, c);
|
||||
nsCRT::free(c);
|
||||
}
|
||||
|
||||
// A helper for the various logging routines.
|
||||
static void VLogF(const char *prefix, const char *fmt, va_list argptr)
|
||||
{
|
||||
|
@ -61,36 +69,35 @@ void PyXPCOM_LogError(const char *fmt, ...)
|
|||
PyErr_Fetch( &exc_typ, &exc_val, &exc_tb);
|
||||
if (exc_typ) {
|
||||
PyErr_NormalizeException( &exc_typ, &exc_val, &exc_tb);
|
||||
char *string1 = nsnull;
|
||||
nsOutputStringStream streamout(string1);
|
||||
nsCAutoString streamout;
|
||||
|
||||
if (exc_tb) {
|
||||
const char *szTraceback = PyTraceback_AsString(exc_tb);
|
||||
if (szTraceback == NULL)
|
||||
streamout << "Can't get the traceback info!";
|
||||
streamout += "Can't get the traceback info!";
|
||||
else {
|
||||
streamout << "Traceback (most recent call last):\n";
|
||||
streamout << szTraceback;
|
||||
streamout += "Traceback (most recent call last):\n";
|
||||
streamout += szTraceback;
|
||||
PyMem_Free((void *)szTraceback);
|
||||
}
|
||||
}
|
||||
PyObject *temp = PyObject_Str(exc_typ);
|
||||
if (temp) {
|
||||
streamout << PyString_AsString(temp);
|
||||
streamout += PyString_AsString(temp);
|
||||
Py_DECREF(temp);
|
||||
} else
|
||||
streamout << "Can't convert exception to a string!";
|
||||
streamout << ": ";
|
||||
streamout += "Can't convert exception to a string!";
|
||||
streamout += ": ";
|
||||
if (exc_val != NULL) {
|
||||
temp = PyObject_Str(exc_val);
|
||||
if (temp) {
|
||||
streamout << PyString_AsString(temp);
|
||||
streamout += PyString_AsString(temp);
|
||||
Py_DECREF(temp);
|
||||
} else
|
||||
streamout << "Can't convert exception value to a string!";
|
||||
streamout += "Can't convert exception value to a string!";
|
||||
}
|
||||
streamout << "\n";
|
||||
LogMessage("PyXPCOM Exception:", string1);
|
||||
streamout += "\n";
|
||||
LogMessage("PyXPCOM Exception:", streamout);
|
||||
}
|
||||
PyErr_Restore(exc_typ, exc_val, exc_tb);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
// pyloader
|
||||
//
|
||||
// Not part of the main Python _xpcom package, but a seperate, thin DLL.
|
||||
// Not part of the main Python _xpcom package, but a separate, thin DLL.
|
||||
//
|
||||
// The main loader and registrar for Python. A thin DLL that is designed to live in
|
||||
// the xpcom "components" directory. Simply locates and loads the standard
|
||||
|
@ -37,6 +37,8 @@
|
|||
#include "stdlib.h"
|
||||
#include "stdarg.h"
|
||||
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include <nsFileStream.h> // For console logging.
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
|
@ -48,7 +50,6 @@
|
|||
static char *PyTraceback_AsString(PyObject *exc_tb);
|
||||
|
||||
#ifdef XP_WIN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
|
@ -172,8 +173,14 @@ extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
|||
|
||||
void LogMessage(const char *prefix, const char *pszMessageText)
|
||||
{
|
||||
nsOutputConsoleStream console;
|
||||
console << prefix << pszMessageText;
|
||||
fprintf(stderr, "%s", pszMessageText);
|
||||
}
|
||||
|
||||
void LogMessage(const char *prefix, nsACString &text)
|
||||
{
|
||||
char *c = ToNewCString(text);
|
||||
LogMessage(prefix, c);
|
||||
nsCRT::free(c);
|
||||
}
|
||||
|
||||
// A helper for the various logging routines.
|
||||
|
@ -195,36 +202,35 @@ static void LogError(const char *fmt, ...)
|
|||
PyObject *exc_typ = NULL, *exc_val = NULL, *exc_tb = NULL;
|
||||
PyErr_Fetch( &exc_typ, &exc_val, &exc_tb);
|
||||
if (exc_typ) {
|
||||
char *string1 = nsnull;
|
||||
nsOutputStringStream streamout(string1);
|
||||
nsCAutoString streamout;
|
||||
|
||||
if (exc_tb) {
|
||||
const char *szTraceback = PyTraceback_AsString(exc_tb);
|
||||
if (szTraceback == NULL)
|
||||
streamout << "Can't get the traceback info!";
|
||||
streamout += "Can't get the traceback info!";
|
||||
else {
|
||||
streamout << "Traceback (most recent call last):\n";
|
||||
streamout << szTraceback;
|
||||
streamout += "Traceback (most recent call last):\n";
|
||||
streamout += szTraceback;
|
||||
PyMem_Free((void *)szTraceback);
|
||||
}
|
||||
}
|
||||
PyObject *temp = PyObject_Str(exc_typ);
|
||||
if (temp) {
|
||||
streamout << PyString_AsString(temp);
|
||||
streamout += PyString_AsString(temp);
|
||||
Py_DECREF(temp);
|
||||
} else
|
||||
streamout << "Can convert exception to a string!";
|
||||
streamout << ": ";
|
||||
streamout += "Can convert exception to a string!";
|
||||
streamout += ": ";
|
||||
if (exc_val != NULL) {
|
||||
temp = PyObject_Str(exc_val);
|
||||
if (temp) {
|
||||
streamout << PyString_AsString(temp);
|
||||
streamout += PyString_AsString(temp);
|
||||
Py_DECREF(temp);
|
||||
} else
|
||||
streamout << "Can convert exception value to a string!";
|
||||
streamout += "Can convert exception value to a string!";
|
||||
}
|
||||
streamout << "\n";
|
||||
LogMessage("PyXPCOM Exception:", string1);
|
||||
streamout += "\n";
|
||||
LogMessage("PyXPCOM Exception:", streamout);
|
||||
}
|
||||
PyErr_Restore(exc_typ, exc_val, exc_tb);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,10 @@ import sys
|
|||
import test.regrtest # The standard Python test suite.
|
||||
|
||||
path = os.path.abspath(os.path.split(sys.argv[0])[0])
|
||||
# This sucks - python now uses "test." - so to worm around this,
|
||||
# we append our test path to the test packages!
|
||||
test.__path__.append(path)
|
||||
|
||||
tests = []
|
||||
for arg in sys.argv[1:]:
|
||||
if arg[0] not in "-/":
|
||||
|
|
Загрузка…
Ссылка в новой задаче