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 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 _ListAllHelpFilesInRoot(root): """Returns a list of (helpDesc, helpFname) for all registered help files """ import regutil retList = [] try: key = win32api.RegOpenKey(root, regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ) except win32api.error as exc: import winerror if exc.winerror != winerror.ERROR_FILE_NOT_FOUND: raise return retList try: keyNo = 0 while 1: try: helpDesc = win32api.RegEnumKey(key, keyNo) helpFile = win32api.RegQueryValue(key, helpDesc) retList.append((helpDesc, 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) return retList
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 _ListAllHelpFilesInRoot(root): """Returns a list of (helpDesc, helpFname) for all registered help files """ import regutil retList = [] try: key = win32api.RegOpenKey(root, 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, details) return retList
def demo(): try: # seeif I can locate the demo files. import fontdemo except ImportError: # else put the demos direectory on the path (if not already) try: instPath = regutil.GetRegistryDefaultValue( regutil.BuildDefaultPythonKey() + "\\InstallPath" ) except win32api.error: print( "The InstallPath can not be located, and the Demos directory is not on the path" ) instPath = "." demosDir = win32ui.FullPath(instPath + "\\Demos") for path in sys.path: if win32ui.FullPath(path) == demosDir: break else: sys.path.append(demosDir) import fontdemo import sys if "/go" in sys.argv: for name, cmd in demos: try: exec(cmd) except: print( "Demo of %s failed - %s:%s" % (cmd, sys.exc_info()[0], sys.exc_info()[1]) ) return # Otherwise allow the user to select the demo to run import pywin.dialogs.list while 1: rc = pywin.dialogs.list.SelectFromLists("Select a Demo", demos, ["Demo Title"]) if rc is None: break title, cmd = demos[rc] try: exec(cmd) except: print( "Demo of %s failed - %s:%s" % (title, sys.exc_info()[0], sys.exc_info()[1]) )
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)
# 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 else: