[pywin32-checkins] pywin32 pywin32_postinstall.py,1.10,1.11
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2004-07-02 04:22:06
|
Update of /cvsroot/pywin32/pywin32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31504 Modified Files: pywin32_postinstall.py Log Message: Install a shortcut to the docs, handle 'non-admin' installs, and pull more tricks to work around our system dll issues. Index: pywin32_postinstall.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/pywin32_postinstall.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** pywin32_postinstall.py 7 Feb 2004 10:03:54 -0000 1.10 --- pywin32_postinstall.py 2 Jul 2004 04:21:57 -0000 1.11 *************** *** 19,22 **** --- 19,25 ---- verbose = 1 + ver_string = "%d.%d" % (sys.version_info[0], sys.version_info[1]) + root_key_name = "Software\\Python\\PythonCore\\" + ver_string + try: # When this script is run from inside the bdist_wininst installer, *************** *** 31,50 **** def directory_created(directory): 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, --- 34,65 ---- def directory_created(directory): pass + def get_root_hkey(): + try: + _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, + root_key_name, _winreg.KEY_CREATE_SUB_KEY) + return _winreg.HKEY_LOCAL_MACHINE + except OSError, details: + # Either not exist, or no permissions to create subkey means + # must be HKCU + return _winreg.HKEY_CURRENT_USER ! def CopyTo(desc, src, dest): import win32api, win32con while 1: try: ! win32api.CopyFile(src, dest, 0) ! return ! except win32api.error, details: ! if details[0]==5: # access denied - user not admin. ! raise if silent: # Running silent mode - just re-raise the error. raise ! err_msg = details[2] 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, err_msg) rc = win32api.MessageBox(0, full_desc, *************** *** 54,68 **** 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) --- 69,100 ---- raise elif rc == win32con.IDIGNORE: ! return # else retry - around we go again. + # We need to import win32api to determine the Windows system directory, + # so we can copy our system files there - but importing win32api will + # load the pywintypes.dll already in the system directory preventing us + # from updating them! + # So, we pull the same trick pywintypes.py does, but it loads from + # our pywintypes_system32 directory. + def LoadSystemModule(lib_dir, modname): + # See if this is a debug build. + import imp + for suffix_item in imp.get_suffixes(): + if suffix_item[0]=='_d.pyd': + suffix = '_d' + break + else: + suffix = "" + filename = "%s%d%d%s.dll" % \ + (modname, sys.version_info[0], sys.version_info[1], suffix) + filename = os.path.join(lib_dir, "pywin32_system32", filename) + mod = imp.load_module(modname, None, filename, + ('.dll', 'rb', imp.C_EXTENSION)) + + def SetPyKeyVal(key_name, value_name, value): ! root_hkey = get_root_hkey() ! root_key = _winreg.OpenKey(root_hkey, root_key_name) try: my_key = _winreg.CreateKey(root_key, key_name) *************** *** 93,96 **** --- 125,129 ---- def install(): import distutils.sysconfig + import traceback lib_dir = distutils.sysconfig.get_python_lib(plat_specific=1) fname = os.path.join(sys.prefix, "pywin32.pth") *************** *** 120,148 **** except WindowsError: pass ! # 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) # Pythonwin 'compiles' config files - record them for uninstall. pywin_dir = os.path.join(lib_dir, "Pythonwin", "pywin") --- 153,189 ---- except WindowsError: pass ! LoadSystemModule(lib_dir, "pywintypes") ! LoadSystemModule(lib_dir, "pythoncom") import win32api # and now we can get the system directory: files = glob.glob(os.path.join(lib_dir, "pywin32_system32\\*.*")) if not files: raise RuntimeError, "No system files to copy!!" ! # Try the system32 directory first - if that fails due to "access denied", ! # it implies a non-admin user, and we use sys.prefix ! for dest_dir in [win32api.GetSystemDirectory(), sys.prefix]: ! # and copy some files over there ! worked = 0 ! try: ! for fname in files: ! base = os.path.basename(fname) ! dst = os.path.join(dest_dir, base) ! CopyTo("installing %s" % base, fname, dst) ! if verbose: ! print "Copied %s to %s" % (base, dst) ! # Register the files with the uninstaller ! file_created(dst) ! worked = 1 ! if worked: ! break ! except win32api.error, details: ! if details[0]==5: ! # access denied - user not admin - try sys.prefix dir. ! continue ! raise ! else: ! raise RuntimeError, \ ! "You don't have enough permissions to install the system files" ! # Pythonwin 'compiles' config files - record them for uninstall. pywin_dir = os.path.join(lib_dir, "Pythonwin", "pywin") *************** *** 151,155 **** # Register our demo COM objects. ! RegisterCOMObjects() # Register the .chm help file. chm_file = os.path.join(lib_dir, "PyWin32.chm") --- 192,207 ---- # Register our demo COM objects. ! try: ! try: ! RegisterCOMObjects() ! except win32api.error, details: ! if details[0]!=5: # ERROR_ACCESS_DENIED ! raise ! print "You do not have the permissions to install COM objects." ! print "The sample COM objects were not registered." ! except: ! print "FAILED to register the Python COM objects" ! traceback.print_exc() ! # Register the .chm help file. chm_file = os.path.join(lib_dir, "PyWin32.chm") *************** *** 177,198 **** try: # use bdist_wininst builtins to create a shortcut. ! try: ! # CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP: ! fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS") ! except OSError: ! # CSIDL_PROGRAMS should work on Win 98 fldr = get_special_folder_path("CSIDL_PROGRAMS") ! dst = os.path.join(fldr, "Python %d.%d\\PythonWin.lnk" % \ ! (sys.version_info[0], sys.version_info[1])) create_shortcut(os.path.join(lib_dir, "Pythonwin\\Pythonwin.exe"), ! "The Pythonwin IDE", ! dst) file_created(dst) except Exception, details: if verbose: print details - else: - if verbose: - print "Shortcut for Pythonwin created" print "The pywin32 extensions were successfully installed." --- 229,265 ---- try: # use bdist_wininst builtins to create a shortcut. ! # CSIDL_COMMON_PROGRAMS only available works on NT/2000/XP, and ! # will fail there if the user has no admin rights. ! if get_root_hkey()==_winreg.HKEY_LOCAL_MACHINE: ! try: ! fldr = get_special_folder_path("CSIDL_COMMON_PROGRAMS") ! except OSError: ! # No CSIDL_COMMON_PROGRAMS on this platform ! fldr = get_special_folder_path("CSIDL_PROGRAMS") ! else: ! # non-admin install - always goes in this user's start menu. fldr = get_special_folder_path("CSIDL_PROGRAMS") ! ! vi = sys.version_info ! fldr = os.path.join(fldr, "Python %d.%d" % (vi[0], vi[1])) ! if not os.path.isdir(fldr): ! os.mkdir(fldr) ! ! dst = os.path.join(fldr, "PythonWin.lnk") create_shortcut(os.path.join(lib_dir, "Pythonwin\\Pythonwin.exe"), ! "The Pythonwin IDE", dst, "", sys.prefix) ! file_created(dst) ! if verbose: ! print "Shortcut for Pythonwin created" ! # And the docs. ! dst = os.path.join(fldr, "Python for Windows Documentation.lnk") ! doc = "Documentation for the PyWin32 extensions" ! create_shortcut(chm_file, doc, dst) file_created(dst) + if verbose: + print "Shortcut to documentation created" except Exception, details: if verbose: print details print "The pywin32 extensions were successfully installed." *************** *** 250,254 **** verbose = 0 elif arg == "-remove": ! break # we do nothing for now else: print "Unknown option:", arg --- 317,323 ---- verbose = 0 elif arg == "-remove": ! # Nothing to do here - we can't unregister much, as we have ! # already been uninstalled. ! pass else: print "Unknown option:", arg |