[pywin32-checkins] pywin32/com/win32com __init__.py,1.4,1.5
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: <mha...@us...> - 2003-09-16 04:57:36
|
Update of /cvsroot/pywin32/pywin32/com/win32com
In directory sc8-pr-cvs1:/tmp/cvs-serv27897
Modified Files:
__init__.py
Log Message:
Cleanup some of the environment hacks we do. If a real module
"win32com\gen_py" exists, just use that. This avoids most freeze utilities
from doing anything special other than ensuring this module can be imported
Ensure __gen_path__ is setup, even in a frozen distribution, and even if
this points to a .zip file.
Index: __init__.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/__init__.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** __init__.py 1 Sep 2003 08:16:33 -0000 1.4
--- __init__.py 16 Sep 2003 04:57:33 -0000 1.5
***************
*** 6,9 ****
--- 6,14 ----
import pythoncom
+ # flag if we are in a "frozen" build.
+ _frozen = getattr(sys, "frozen", 1==0)
+ if _frozen and not hasattr(pythoncom, "frozen"):
+ pythoncom.frozen = sys.frozen
+
# Add support for an external "COM Extensions" path.
# Concept is that you can register a seperate path to be used for
***************
*** 13,17 ****
# eg "win32com.mapi" or "win32com.axscript" both work, even though they do not
# live under the main win32com directory.
!
### TODO - Load _all_ \\Extensions subkeys - for now, we only read the default
### Modules will work if loaded into "win32comext" path.
--- 18,22 ----
# eg "win32com.mapi" or "win32com.axscript" both work, even though they do not
# live under the main win32com directory.
! __gen_path__ = ''
### TODO - Load _all_ \\Extensions subkeys - for now, we only read the default
### Modules will work if loaded into "win32comext" path.
***************
*** 54,83 ****
# __build_path__ neednt be defined.
pass
-
- found = 0
global __gen_path__
if key is not None:
try:
__gen_path__ = win32api.RegQueryValue(key, "GenPath")
- found = 1
except win32api.error:
pass
- if not found:
- # no key.
- # We used to use a directory under win32com - but this sucks.
- # If that directory exists, we still use it, but now we prefer
- # a version specific directory under the user temp directory.
- if os.path.isdir(win32api.GetFullPathName( __path__[0] + "\\gen_py")):
- __gen_path__ = win32api.GetFullPathName( __path__[0] + "\\gen_py")
- else:
- __gen_path__ = os.path.join(
- win32api.GetTempPath(), "gen_py",
- "%d.%d" % (sys.version_info[0], sys.version_info[1]))
- # Create a "win32com.gen_py", but with a custom __path__
- import new
- global gen_py # Exists in the win32com namespace.
- gen_py = new.module("win32com.gen_py")
- gen_py.__path__ = [ __gen_path__ ]
- sys.modules[gen_py.__name__]=gen_py
finally:
if key is not None:
--- 59,68 ----
***************
*** 89,105 ****
def __PackageSupportBuildPath__(package_path):
# See if we have a special directory for the binaries (for developers)
! try:
package_path.append(__build_path__)
- except (NameError, AttributeError):
- # AttributeError may be raised in a frozen EXE.
- pass
! # pythoncom.frozen may already be set if
! # a special build.
! if hasattr(sys, "frozen"):
! pythoncom.frozen = sys.frozen
!
! if not pythoncom.frozen:
SetupEnvironment()
# get rid of these for module users
--- 74,108 ----
def __PackageSupportBuildPath__(package_path):
# See if we have a special directory for the binaries (for developers)
! if not _frozen:
package_path.append(__build_path__)
! if not _frozen:
SetupEnvironment()
+
+ # If we don't have a special __gen_path__, see if we have a gen_py as a
+ # normal module and use that (ie, "win32com\gen_py" may already exist as
+ # a package.
+ if not __gen_path__:
+ try:
+ import win32com.gen_py
+ __gen_path__ = sys.modules["win32com.gen_py"].__path__[0]
+ except ImportError:
+ # We used to dynamically create a directory under win32com -
+ # but this sucks. Now we create a version specific directory
+ # under the user temp directory.
+ __gen_path__ = os.path.join(
+ win32api.GetTempPath(), "gen_py",
+ "%d.%d" % (sys.version_info[0], sys.version_info[1]))
+
+ # we must have a __gen_path__, but may not have a gen_py module -
+ # set that up.
+ if not sys.modules.has_key("win32com.gen_py"):
+ # Create a "win32com.gen_py", but with a custom __path__
+ import new
+ gen_py = new.module("win32com.gen_py")
+ gen_py.__path__ = [ __gen_path__ ]
+ sys.modules[gen_py.__name__]=gen_py
+ del new
+ gen_py = sys.modules["win32com.gen_py"]
# get rid of these for module users
|