Update of /cvsroot/pywin32/pywin32
In directory sc8-pr-cvs1:/tmp/cvs-serv22652
Modified Files:
setup_win32all_core.py pywin32_postinstall.py
Log Message:
Get most data files and .py files installed correctly. Post install file
is called even for a standard 'install', and registers the help file, etc
Only thing I know of that is left is the .exe installation (and I have no
real idea how to approach this)
Index: setup_win32all_core.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/setup_win32all_core.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** setup_win32all_core.py 12 Nov 2003 12:02:56 -0000 1.19
--- setup_win32all_core.py 25 Nov 2003 13:24:36 -0000 1.20
***************
*** 4,13 ****
#
# Things known to be missing:
- # * Commented "data files"
# * Install of .exe/.dlls - most .exe files go next to python.exe
# * "dbi" was built as .dll, as odbc depends on it. does it work?
- # * create win32com\gen_py directory post install.
- # * Installing the 2 system DLLs to the system directory (just notice post-
- # setup script does this - maybe do this on std "install" too?
from distutils.core import setup, Extension, Command
--- 4,9 ----
***************
*** 19,22 ****
--- 15,19 ----
from distutils.filelist import FileList
import os, string, sys
+ import re
# Python 2.2 has no True/False
***************
*** 135,151 ****
class WinExt_system32(WinExt):
def get_pywin32_dir(self):
! return "system32"
################################################################
-
- class my_install_lib (install_lib):
- # A special install_lib command, which will install into the windows
- # system directory instead of Lib/site-packages
-
- # XXX Currently broken. Should only install pywintypes and pythoncom into sysdir
- def finalize_options(self):
- install_lib.finalize_options(self)
- self.install_dir = os.getenv("windir") + '\\system32'
-
class my_build_ext(build_ext):
--- 132,138 ----
class WinExt_system32(WinExt):
def get_pywin32_dir(self):
! return "pywin32_system32"
################################################################
class my_build_ext(build_ext):
***************
*** 358,367 ****
def get_ext_filename(self, name):
# The pywintypes and pythoncom extensions have special names
! if name == "system32.pywintypes":
extra = self.debug and "_d.dll" or ".dll"
! return r"system32\pywintypes%d%d%s" % (sys.version_info[0], sys.version_info[1], extra)
! elif name == "system32.pythoncom":
extra = self.debug and "_d.dll" or ".dll"
! return r"system32\pythoncom%d%d%s" % (sys.version_info[0], sys.version_info[1], extra)
elif name.endswith("win32.perfmondata"):
extra = self.debug and "_d.dll" or ".dll"
--- 345,354 ----
def get_ext_filename(self, name):
# The pywintypes and pythoncom extensions have special names
! if name == "pywin32_system32.pywintypes":
extra = self.debug and "_d.dll" or ".dll"
! return r"pywin32_system32\pywintypes%d%d%s" % (sys.version_info[0], sys.version_info[1], extra)
! elif name == "pywin32_system32.pythoncom":
extra = self.debug and "_d.dll" or ".dll"
! return r"pywin32_system32\pythoncom%d%d%s" % (sys.version_info[0], sys.version_info[1], extra)
elif name.endswith("win32.perfmondata"):
extra = self.debug and "_d.dll" or ".dll"
***************
*** 541,570 ****
]
! # XXX - incomplete, but checking in to avoid conflicts with Thomas ;)
# NOTE: somewhat counter-intuitively, a result list a-la:
# [('Lib/site-packages\\Pythonwin', ('Pythonwin/license.txt',)),]
# will 'do the right thing' in terms of installing licence.txt into
! # 'Lib/site-packages/Pythonwin/licence.txt'. I intent exploiting this to
! # get 'com/wincom/whatever' installed to 'win32com/whatever'
def convert_data_files(files):
ret = []
for file in files:
if file.find("*") >= 0:
! continue
! flist = FileList(os.path.dirname(file))
! if not flist.include_pattern(os.path.basename(file)):
raise RuntimeError, "No files match '%s'" % file
! found = flist.files
else:
if not os.path.isfile(file):
raise RuntimeError, "No file '%s'" % file
! path = os.path.join("Lib/site-packages", os.path.dirname(file))
! ret.append( (path, (file,)) )
! continue
! # xxx - incomplete, but semi-working, and going to bed :)
! # found = [file]
! ret.append( ("Lib/site-packages", found) )
!
! print ret
return ret
--- 528,568 ----
]
! def expand_modules(module_dir):
! flist = FileList()
! flist.findall(module_dir)
! flist.include_pattern("*.py")
! return [os.path.splitext(name)[0] for name in flist.files]
!
# NOTE: somewhat counter-intuitively, a result list a-la:
# [('Lib/site-packages\\Pythonwin', ('Pythonwin/license.txt',)),]
# will 'do the right thing' in terms of installing licence.txt into
! # 'Lib/site-packages/Pythonwin/licence.txt'. We exploit this to
! # get 'com/win32com/whatever' installed to 'win32com/whatever'
def convert_data_files(files):
+ base_dir = "Lib/site-packages"
ret = []
for file in files:
+ file = os.path.normpath(file)
if file.find("*") >= 0:
! flist = FileList()
! flist.findall(os.path.dirname(file))
! flist.include_pattern(os.path.basename(file))
! # We never want CVS
! flist.exclude_pattern(re.compile(".*\\\\CVS\\\\"), is_regex=1)
! if not flist.files:
raise RuntimeError, "No files match '%s'" % file
! files_use = flist.files
else:
if not os.path.isfile(file):
raise RuntimeError, "No file '%s'" % file
! files_use = (file,)
! path_use = os.path.dirname(file)
! if path_use.startswith("com/") or path_use.startswith("com\\"):
! path_use = path_use[4:]
! path_use = os.path.join(base_dir, path_use)
! ret.append( (path_use, files_use))
! #print "DataFiles:"
! #for f in ret:
! # print f
return ret
***************
*** 589,614 ****
ext_modules = win32_extensions + com_extensions + pythonwin_extensions,
! package_dir = {"win32": "win32",
! "win32com": "com/win32com",
"win32comext": "com/win32comext",
"Pythonwin": "Pythonwin"},
!
! data_files=convert_data_files([
! 'Pythonwin/pywin/*.cfg',
! 'pywin32.chm',
! 'Pythonwin/license.txt',
! 'win32/license.txt',
! # win32com readme (doesn't work for cvt_data_files)
! # win32com/license
! # win32com test - *.txt, *.py, *.vbs, *.js, *.sct, *.xsl
! # win32com HTML\*
! # win32com HTML\image\*
! # win32comext\axscript\test - *.py, *.vbs, *.pys
! # win32comext\axscript\demos\ie\*.*
! # win32comext\axscript\demos\wsh\*.*
! # win32comext\axscript\demos\asp\*.*
! ]),
! packages=['win32',
! 'win32com',
'win32com.client',
'win32com.demos',
--- 587,594 ----
ext_modules = win32_extensions + com_extensions + pythonwin_extensions,
! package_dir = {"win32com": "com/win32com",
"win32comext": "com/win32comext",
"Pythonwin": "Pythonwin"},
! packages=['win32com',
'win32com.client',
'win32com.demos',
***************
*** 622,635 ****
'win32comext.axscript.server',
- 'win32comext.axscript.demos', # XXX not a package
- 'win32comext.axscript.demos.client',
- 'win32comext.axscript.demos.client.asp',
- 'win32comext.axscript.demos.client.ie',
- 'win32comext.axscript.demos.client.wsh',
- 'win32comext.axscript.test', # XXX not a package
'win32comext.axdebug',
- 'win32comext.axscript',
- 'win32comext.axscript.client',
- 'win32comext.axscript.server',
'win32comext.shell',
--- 602,606 ----
***************
*** 638,642 ****
'win32comext.axcontrol',
- 'Pythonwin',
'Pythonwin.pywin',
'Pythonwin.pywin.debugger',
--- 609,612 ----
***************
*** 651,656 ****
'Pythonwin.pywin.tools',
],
)
! # If we did any extension building...
if dist.command_obj.has_key('build_ext'):
what_string = "built"
--- 621,659 ----
'Pythonwin.pywin.tools',
],
+
+ py_modules = expand_modules("win32\\lib"),
+
+ data_files=convert_data_files([
+ 'pywin32.chm',
+ 'pythonwin/pywin/*.cfg',
+ 'pythonwin/license.txt',
+ 'win32/license.txt',
+ 'com/win32com/readme.htm',
+ # win32com test utility files.
+ 'com/win32com/test/*.txt',
+ 'com/win32com/test/*.vbs',
+ 'com/win32com/test/*.js',
+ 'com/win32com/test/*.sct',
+ 'com/win32com/test/*.xsl',
+ # win32com docs
+ 'com/win32com/HTML/*',
+ 'com/win32com/HTML/image/*',
+ # Active Scripting test and demos.
+ 'com/win32comext/axscript/test/*.vbs',
+ 'com/win32comext/axscript/test/*.pys',
+ 'com/win32comext/axscript/demos/client/ie/*',
+ 'com/win32comext/axscript/demos/client/wsh/*',
+ 'com/win32comext/axscript/demos/client/asp/*',
+ ]) + \
+ # And data files convert_data_files can't handle.
+ [
+ ('Lib/site-packages\\win32com', ('com/License.txt',)),
+ # pythoncom.py doesn't quite fit anywhere else.
+ # Note we don't get an auto .pyc - but who cares?
+ ('Lib/site-packages', ('com/pythoncom.py',)),
+ ],
)
!
! # If we did any extension building, and report if we skipped any.
if dist.command_obj.has_key('build_ext'):
what_string = "built"
***************
*** 665,666 ****
--- 668,688 ----
else:
print "All extension modules %s OK" % (what_string,)
+
+ # Custom script we run at the end of installing - this is the same script
+ # run by bdist_wininst, but the standard 'install' command doesn't seem
+ # to have such a concept.
+ # This child process won't be able to install the system DLLs until our
+ # process has terminated (as distutils imports win32api!), so we must use
+ # some 'no wait' executor - spawn seems fine! We pass the PID of this
+ # process so the child will wait for us.
+ if dist.command_obj.has_key('install'):
+ # What executable to use? This one I guess. Maybe I could just import
+ # as a module and execute?
+ filename = os.path.join(
+ os.path.dirname(sys.argv[0]), "pywin32_postinstall.py")
+ if not os.path.isfile(filename):
+ raise RuntimeError, "Can't find pywin32_postinstall.py"
+ print "Executing post install script..."
+ os.spawnl(os.P_NOWAIT, sys.executable,
+ sys.executable, filename,
+ "-quiet", "-wait", str(os.getpid()), "-install")
Index: pywin32_postinstall.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/pywin32_postinstall.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pywin32_postinstall.py 10 Nov 2003 20:47:18 -0000 1.1
--- pywin32_postinstall.py 25 Nov 2003 13:24:37 -0000 1.2
***************
*** 4,17 ****
# and creates a pth file
import os, sys, glob, shutil
! if sys.argv[1] == "-install":
import distutils.sysconfig
lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
fname = os.path.join(sys.prefix, "pywin32.pth")
! print "Creating PTH FILE %s" % fname
pthfile = open(fname, "w")
# Register the file with the uninstaller
file_created(fname)
! for name in "win32 win32com Pythonwin".split():
# Create entries for the PTH file, and at the same time
# add the directory to sys.path so we can load win32api below.
--- 4,94 ----
# and creates a pth file
import os, sys, glob, shutil
+ import _winreg
! com_modules = [
! # module_name, class_names
! ("win32com.servers.interp", "Interpreter"),
! ("win32com.servers.dictionary", "DictionaryPolicy"),
! ]
!
! # Is this a 'silent' install - ie, avoid all dialogs.
! # Different than 'verbose'
! silent = 0
!
! # Verbosity of output messages.
! verbose = 1
!
! def file_created(file):
! pass
!
! def AbortRetryIgnore(desc, func, *args):
! import win32api, win32con
! while 1:
! try:
! return func(*args)
! except:
! if silent:
! # Running silent mode - just re-raise the error.
! raise
! exc_type, exc_val, tb = sys.exc_info()
! tb = None
! full_desc = "Error %s\n\n" \
! "If you have any Python applications running, " \
! "please close them now\nand select 'Retry'\n\n%s" \
! % (desc, exc_val)
! rc = win32api.MessageBox(0,
! full_desc,
! "Installation Error",
! win32con.MB_ABORTRETRYIGNORE)
! if rc == win32con.IDABORT:
! raise
! elif rc == win32con.IDIGNORE:
! return None
! # else retry - around we go again.
!
! def SetPyKeyVal(key_name, value_name, value):
! ver_string = "%d.%d" % (sys.version_info[0], sys.version_info[1])
! root_key_name = "Software\\Python\\PythonCore\\" + ver_string
! try:
! root_key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, root_key_name)
! except OSError:
! root_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER_MACHINE,
! root_key_name)
! try:
! my_key = _winreg.CreateKey(root_key, key_name)
! try:
! _winreg.SetValueEx(my_key, value_name, 0, _winreg.REG_SZ, value)
! finally:
! my_key.Close()
! finally:
! root_key.Close()
! if verbose:
! print "-> %s\\%s[%s]=%r" % (root_key_name, key_name, value_name, value)
!
! def RegisterCOMObjects(register = 1):
! import win32com.server.register
! if register:
! func = win32com.server.register.RegisterClasses
! else:
! func = win32com.server.register.UnregisterClasses
! flags = {}
! if not verbose:
! flags['quiet']=1
! for module, klass_name in com_modules:
! __import__(module)
! mod = sys.modules[module]
! klass = getattr(mod, klass_name)
! func(klass, **flags)
!
! def install():
import distutils.sysconfig
lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1)
fname = os.path.join(sys.prefix, "pywin32.pth")
! if verbose:
! print "Creating .PTH file %s" % fname
pthfile = open(fname, "w")
# Register the file with the uninstaller
file_created(fname)
! for name in "win32 win32\\lib Pythonwin".split():
# Create entries for the PTH file, and at the same time
# add the directory to sys.path so we can load win32api below.
***************
*** 20,37 ****
sys.path.append(path)
# To be able to import win32api, PyWinTypesxx.dll must be on the PATH
! # We must be carefull to use the one we just installed, not one already
# in the system directory, otherwise we will not be able to copy the one
# just installed into the system dir.
! os.environ["PATH"] = "%s;%s" % (os.path.join(lib_dir, "system32"), os.environ["PATH"])
import win32api
# and now we can get the system directory:
sysdir = win32api.GetSystemDirectory()
# and copy some files over there
! for fname in glob.glob(os.path.join(lib_dir, "system32\\*.*")):
base = os.path.basename(fname)
dst = os.path.join(sysdir, base)
! print "Copy %s to %s" % (base, sysdir)
! shutil.copyfile(fname, dst)
# Register the files with the uninstaller
file_created(dst)
!
--- 97,181 ----
sys.path.append(path)
# To be able to import win32api, PyWinTypesxx.dll must be on the PATH
! # We must be careful to use the one we just installed, not one already
# in the system directory, otherwise we will not be able to copy the one
# just installed into the system dir.
! os.environ["PATH"] = "%s;%s" % (os.path.join(lib_dir, "pywin32_system32"), os.environ["PATH"])
! # importing pywintypes explicitly before win32api means our one in sys.path
! # is found, rather than whatever Windows implicitly finds as a side-effect
! # of importing win32api.
! import pywintypes
import win32api
# and now we can get the system directory:
sysdir = win32api.GetSystemDirectory()
# and copy some files over there
! files = glob.glob(os.path.join(lib_dir, "pywin32_system32\\*.*"))
! if not files:
! raise RuntimeError, "No system files to copy!!"
! for fname in files:
base = os.path.basename(fname)
dst = os.path.join(sysdir, base)
! if verbose:
! print "Copy %s to %s" % (base, sysdir)
! AbortRetryIgnore("installing %s" % base,
! shutil.copyfile, fname, dst)
# Register the files with the uninstaller
file_created(dst)
! # Register our demo COM objects.
! RegisterCOMObjects()
! # Register the .chm help file.
! SetPyKeyVal("Help\\Pythonwin Reference",
! None,
! os.path.join(lib_dir, "PyWin32.chm"))
! # Create the win32com\gen_py directory.
! make_dir = os.path.join(lib_dir, "win32com", "gen_py")
! if not os.path.isdir(make_dir):
! if verbose:
! print "Creating directory", make_dir
! os.mkdir(make_dir)
!
! print "The pywin32 extensions were successfully installed."
!
! def usage():
! msg = \
! """%s: A post-install script for the pywin32 extensions.
!
! This should be run automatically after installation, but if it fails you
! can run it again with a '-install' parameter, to ensure the environment
! is setup correctly.
!
! Additional Options:
! -wait pid : Wait for the specified process to terminate before starting.
! -silent : Don't display the "Abort/Retry/Ignore" dialog for files in use.
! -quiet : Don't display progress messages.
! """
! print msg.strip() % os.path.basename(sys.argv[0])
!
! if __name__=='__main__':
! if len(sys.argv)==1:
! usage()
! sys.exit(1)
!
! arg_index = 1
! while arg_index < len(sys.argv):
! arg = sys.argv[arg_index]
! # Hack for installing while we are in use. Just a simple wait so the
! # parent process can terminate.
! if arg == "-wait":
! arg_index += 1
! pid = int(sys.argv[arg_index])
! try:
! os.waitpid(pid, 0)
! except os.error:
! # child already dead
! pass
! elif arg == "-install":
! install()
! elif arg == "-silent":
! silent = 1
! elif arg == "-quiet":
! verbose = 0
! else:
! print "Unknown option:", arg
! usage()
! sys.exit(0)
! arg_index += 1
|