def CheckPythonPaths(verbose): if verbose: print("Python Paths:") # Check the core path if verbose: print("\tCore Path:", end=' ') try: appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath") except win32api.error as exc: print("** does not exist - ", exc.strerror) problem = CheckPathString(appPath) if problem: print(problem) else: if verbose: print(appPath) key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath", 0, win32con.KEY_READ) try: keyNo = 0 while 1: try: appName = win32api.RegEnumKey(key, keyNo) appPath = win32api.RegQueryValue(key, appName) if verbose: print("\t"+appName+":", end=' ') if appPath: problem = CheckPathString(appPath) if problem: print(problem) else: if verbose: print(appPath) else: if verbose: print("(empty)") keyNo = keyNo + 1 except win32api.error: break finally: win32api.RegCloseKey(key)
def __init__(self): self.runtimepath = None self.datapath = None try: self.runtimepath = win32api.RegQueryValue( regutil.GetRootKey(), REGKEY_BASE + "RuntimePath") except Exception: # FIXME - should probably catch just the specific exception meaning that the key is missing self.runtimepath = DEFAULT_INSTALL_DIR try: self.datapath = win32api.RegQueryValue(regutil.GetRootKey(), REGKEY_BASE + "DataPath") except Exception: # FIXME - should probably catch just the specific exception meaning that the key is missing self.datapath = DEFAULT_INSTALL_DIR
def FindPythonExe(exeAlias, possibleRealNames, searchPaths): """Find an exe. Returns the full path to the .exe, and a boolean indicating if the current registered entry is OK. We don't trust the already registered version even if it exists - it may be wrong (ie, for a different Python version) """ import win32api, regutil, string, os, sys if possibleRealNames is None: possibleRealNames = exeAlias # Look first in Python's home. found = os.path.join(sys.prefix, possibleRealNames) if not FileExists(found): # for developers found = os.path.join(sys.prefix, "PCBuild", possibleRealNames) if not FileExists(found): found = LocateFileName(possibleRealNames, searchPaths) registered_ok = 0 try: registered = win32api.RegQueryValue( regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exeAlias) registered_ok = found == registered except win32api.error: pass return found, registered_ok
def CheckHelpFiles(verbose): if verbose: print("Help Files:") try: key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ) except win32api.error as exc: import winerror if exc.winerror != winerror.ERROR_FILE_NOT_FOUND: raise return try: keyNo = 0 while 1: try: helpDesc = win32api.RegEnumKey(key, keyNo) helpFile = win32api.RegQueryValue(key, helpDesc) if verbose: print("\t" + helpDesc + ":", end=' ') # query the os section. try: os.stat(helpFile) if verbose: print(helpFile) except os.error: print("** Help file %s does not exist" % helpFile) keyNo = keyNo + 1 except win32api.error as exc: import winerror if exc.winerror != winerror.ERROR_NO_MORE_ITEMS: raise break finally: win32api.RegCloseKey(key)
def CheckRegisteredExe(exename): try: os.stat( win32api.RegQueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exename)) # except SystemError: except (os.error, win32api.error): print("Registration of %s - Not registered correctly" % exename)
def CheckPythonPaths(verbose): if verbose: print "Python Paths:" # Check the core path if verbose: print "\tCore Path:", try: appPath = win32api.RegQueryValue( regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath") except win32api.error, exc: print "** does not exist - ", exc.strerror
def CheckHelpFiles(verbose): if verbose: print "Help Files:" try: key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ) except win32api.error, exc: import winerror if exc.winerror != winerror.ERROR_FILE_NOT_FOUND: raise return
def CheckRegisteredModules(verbose): # Check out all registered modules. k = regutil.BuildDefaultPythonKey() + "\\Modules" try: keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k) print "WARNING: 'Modules' registry entry is deprectated and evil!" except win32api.error, exc: import winerror if exc.winerror != winerror.ERROR_FILE_NOT_FOUND: raise return
def ListAllHelpFiles(): """Returns a list of (helpDesc, helpFname) for all registered help files """ import regutil retList = [] try: key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ) except win32api.error, (code, fn, details): import winerror if code != winerror.ERROR_FILE_NOT_FOUND: raise win32api.error, (code, fn, desc) return retList
def OpenRegistryKey(self, root=None, subkey=None): # Use this instead of OpenDocumentFile. # Look for existing open document if root is None: root = regutil.GetRootKey() if subkey is None: subkey = regutil.BuildDefaultPythonKey() for doc in self.GetDocumentList(): if doc.root == root and doc.subkey == subkey: doc.GetFirstView().ActivateFrame() return doc # not found - new one. doc = RegDocument(self, root, subkey) frame = self.CreateNewFrame(doc) doc.OnNewDocument() self.InitialUpdateFrame(frame, doc, 1) return doc
def GetSubList(self): keyStr = regutil.BuildDefaultPythonKey() + "\\PythonPath" hKey = win32api.RegOpenKey(regutil.GetRootKey(), keyStr) try: ret = [] ret.append(HLIProjectRoot("", "Standard Python Library")) # The core path. index = 0 while 1: try: ret.append(HLIProjectRoot(win32api.RegEnumKey(hKey, index))) index = index + 1 except win32api.error: break return ret finally: win32api.RegCloseKey(hKey)
def SetupCore(searchPaths): """Setup the core Python information in the registry. This function makes no assumptions about the current state of sys.path. After this function has completed, you should have access to the standard Python library, and the standard Win32 extensions """ import sys for path in searchPaths: sys.path.append(path) import os import regutil, win32api, win32con installPath, corePaths = LocatePythonCore(searchPaths) # Register the core Pythonpath. print(corePaths) regutil.RegisterNamedPath(None, ";".join(corePaths)) # Register the install path. hKey = win32api.RegCreateKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey()) try: # Core Paths. win32api.RegSetValue(hKey, "InstallPath", win32con.REG_SZ, installPath) finally: win32api.RegCloseKey(hKey) # Register the win32 core paths. win32paths = ( os.path.abspath(os.path.split(win32api.__file__)[0]) + ";" + os.path.abspath( os.path.split(LocateFileName("win32con.py;win32con.pyc", sys.path))[0])) # Python has builtin support for finding a "DLLs" directory, but # not a PCBuild. Having it in the core paths means it is ignored when # an EXE not in the Python dir is hosting us - so we add it as a named # value check = os.path.join(sys.prefix, "PCBuild") if "64 bit" in sys.version: check = os.path.join(check, "amd64") if os.path.isdir(check): regutil.RegisterNamedPath("PCBuild", check)
def SetupCore(searchPaths): """Setup the core Python information in the registry. This function makes no assumptions about the current state of sys.path. After this function has completed, you should have access to the standard Python library, and the standard Win32 extensions """ import sys for path in searchPaths: sys.path.append(path) import string, os import regutil, _winreg, win32api installPath, corePaths = LocatePythonCore(searchPaths) # Register the core Pythonpath. print corePaths regutil.RegisterNamedPath(None, string.join(corePaths, ";")) # Register the install path. hKey = _winreg.CreateKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey()) try: # Core Paths. _winreg.SetValue(hKey, "InstallPath", _winreg.REG_SZ, installPath) finally: _winreg.CloseKey(hKey) # The core DLL. # regutil.RegisterCoreDLL() # Register the win32 extensions, as some of them are pretty much core! # Why doesnt win32con.__file__ give me a path? (ahh - because only the .pyc exists?) # Register the win32 core paths. win32paths = os.path.abspath( os.path.split(win32api.__file__)[0]) + ";" + \ os.path.abspath( os.path.split(LocateFileName("win32con.py;win32con.pyc", sys.path ) )[0] ) suffix = IsDebug() ver_str = hex(sys.hexversion)[2] + hex(sys.hexversion)[4] FindRegisterModule("pywintypes", "pywintypes%s%s.dll" % (ver_str, suffix), [".", win32api.GetSystemDirectory()]) regutil.RegisterNamedPath("win32", win32paths)
def FindRegisteredModule(moduleName, possibleRealNames, searchPaths): """Find a registered module. First place looked is the registry for an existing entry. Then the searchPaths are searched. Returns the full path to the .exe or None if the current registered entry is OK. """ import _winreg, regutil, string try: fname = _winreg.QueryValue(regutil.GetRootKey(), \ regutil.BuildDefaultPythonKey() + "\\Modules\\%s" % moduleName) if FileExists(fname): return None # Nothing extra needed except EnvironmentError: pass return LocateFileName(possibleRealNames, searchPaths)
def FindPythonExe(exeAlias, possibleRealNames, searchPaths): """Find an exe. First place looked is the registry for an existing entry. Then the searchPaths are searched. Returns the full path to the .exe, and a boolean indicating if the current registered entry is OK. """ import _winreg, regutil, string if possibleRealNames is None: possibleRealNames = exeAlias try: fname = _winreg.QueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exeAlias) if FileExists(fname): return fname, 1 # Registered entry OK except EnvironmentError: pass return LocateFileName(possibleRealNames, searchPaths), 0
if verbose: print "Python Paths:" # Check the core path if verbose: print "\tCore Path:", try: appPath = win32api.RegQueryValue( regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath") except win32api.error, exc: print "** does not exist - ", exc.strerror problem = CheckPathString(appPath) if problem: print problem else: if verbose: print appPath key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath", 0, win32con.KEY_READ) try: keyNo = 0 while 1: try: appName = win32api.RegEnumKey(key, keyNo) appPath = win32api.RegQueryValue(key, appName) if verbose: print "\t" + appName + ":", if appPath: problem = CheckPathString(appPath) if problem: print problem else: if verbose: print appPath