[pypy-svn] r49685 - pypy/branch/clr-module-improvements/pypy/module/clr
regmee at codespeak.net
regmee at codespeak.net
Wed Dec 12 22:27:47 CET 2007
Author: regmee
Date: Wed Dec 12 22:27:45 2007
New Revision: 49685
Modified:
pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py
pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py
Log:
assembly file loading with clr.load_assembly() and namespaces scaning from currently loaded assemblies
Modified: pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py (original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/__init__.py Wed Dec 12 22:27:45 2007
@@ -17,6 +17,7 @@
'load_valid_namespaces': 'interp_clr.load_valid_namespaces',
'isDotNetType': 'interp_clr.isDotNetType',
'load_assembly': 'interp_clr.load_assembly',
+ 'list_of_loadedAssemblies': 'interp_clr.list_of_loadedAssemblies',
}
def setup_after_space_initialization(self):
Modified: pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py (original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/interp_clr.py Wed Dec 12 22:27:45 2007
@@ -194,17 +194,8 @@
Return: List of Valid .NET namespaces
"""
listOfNamespaces = []
- assembliesToScan = [ "/usr/lib/mono/1.0/mscorlib.dll",
- "/usr/lib/mono/1.0/System.dll",
- "/usr/lib/mono/1.0/System.Web.dll",
- "/usr/lib/mono/1.0/System.Data.dll",
- "/usr/lib/mono/1.0/System.Xml.dll",
- "/usr/lib/mono/1.0/System.Drawing.dll"
- ]
- assems = []
- for assemblyName in assembliesToScan:
- assems.append(System.Reflection.Assembly.LoadFile(assemblyName))
-
+ currentDomain = System.AppDomain.get_CurrentDomain()
+ assems = currentDomain.GetAssemblies()
for loadedAssembly in assems:
typesInAssembly = loadedAssembly.GetTypes()
for type in typesInAssembly:
@@ -227,19 +218,56 @@
isDotNetType.unwrap_spec = [ObjSpace, str]
-def load_assembly(space, assemblyName):
+def list_of_loadedAssemblies(space):
+ """
+ return a List of currently loaded .NET assembliesy
+
+ return:
+ list eg: ['System.Xml','System.Data','mscorlib']
+ """
+ loadedAssemblies = []
+ currentDomain = System.AppDomain.get_CurrentDomain()
+ currentLoadedAssemblies = currentDomain.GetAssemblies()
+
+ for lAssembly in currentLoadedAssemblies:
+ strName = lAssembly.get_FullName()
+ rindexComma = strName.find(',')
+ if rindexComma != -1:
+ loadedAssemblies.append(strName[:rindexComma])
+ return space.wrap(loadedAssemblies)
+list_of_loadedAssemblies.unwrap_spec = [ObjSpace]
+
+def load_assembly(space, assemblyPath):
"""
Load the given .NET assembly into the PyPy interpreter
Parameters:
- - assemblyName: the full name of the assembly
- (e.g., ``System.Xml.dll``).
+ - assemblyPath: the full path of the assembly
+ (e.g., /usr/lib/mono/2.0/System.Data.dll).
"""
- # listOfNamespaces = []
- # currentDomain = System.AppDomain.get_CurrentDomain()
- # asEvidence = currentDomain.get_Evidence()
- pass
+ assemblyToLoad = ""
+ loadedAssemblies = space.unwrap(list_of_loadedAssemblies(space))
+
+ # split the name to pull out "System.Data.dll"
+ # then check if it has already been loaded.
+ rindexSlash = assemblyPath.rfind('/')
+ if rindexSlash != -1:
+ strAfterSlash = assemblyPath[rindexSlash +1 : ]
+ rindexDot = strAfterSlash.rfind('.')
+ if rindexDot != -1:
+ assemblyToLoad = strAfterSlash[: rindexDot]
+
+ if assemblyToLoad in loadedAssemblies:
+ print " won't reload loaded assembly "
+ pass
+ else:
+ try:
+ System.Reflection.Assembly.LoadFile(assemblyPath)
+ print "Loaded %s"%assemblyPath
+ except:
+ print " can not load the assembly "
+load_assembly.unwrap_spec = [ObjSpace, str]
def load_cli_class(space, namespace, classname):
"""
More information about the Pypy-commit
mailing list