<s> import win32api <EOL> import win32con <EOL> import sys <EOL> import os <EOL> error = "<STR_LIT>" <EOL> CLSIDPyFile = "<STR_LIT>" <EOL> RegistryIDPyFile = "<STR_LIT>" <EOL> RegistryIDPycFile = "<STR_LIT>" <EOL> def GetRootKey ( ) : <EOL> """<STR_LIT>""" <EOL> return win32con . HKEY_LOCAL_MACHINE <EOL> def GetRegistryDefaultValue ( subkey , rootkey = None ) : <EOL> """<STR_LIT>""" <EOL> if rootkey is None : rootkey = GetRootKey ( ) <EOL> return win32api . RegQueryValue ( rootkey , subkey ) <EOL> def SetRegistryDefaultValue ( subKey , value , rootkey = None ) : <EOL> """<STR_LIT>""" <EOL> import types <EOL> if rootkey is None : rootkey = GetRootKey ( ) <EOL> if type ( value ) == types . StringType : <EOL> typeId = win32con . REG_SZ <EOL> elif type ( value ) == types . IntType : <EOL> typeId = win32con . REG_DWORD <EOL> else : <EOL> raise TypeError , "<STR_LIT>" + str ( value ) <EOL> win32api . RegSetValue ( rootkey , subKey , typeId , value ) <EOL> def BuildDefaultPythonKey ( ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" + sys . winver <EOL> def GetAppPathsKey ( ) : <EOL> return "<STR_LIT>" <EOL> def RegisterPythonExe ( exeFullPath , exeAlias = None , exeAppPath = None ) : <EOL> """<STR_LIT>""" <EOL> if exeAppPath : <EOL> raise error , "<STR_LIT>" <EOL> if exeAlias is None : <EOL> exeAlias = os . path . basename ( exeFullPath ) <EOL> win32api . RegSetValue ( GetRootKey ( ) , GetAppPathsKey ( ) + "<STR_LIT:\\>" + exeAlias , win32con . REG_SZ , exeFullPath ) <EOL> def GetRegisteredExe ( exeAlias ) : <EOL> """<STR_LIT>""" <EOL> return win32api . RegQueryValue ( GetRootKey ( ) , GetAppPathsKey ( ) + "<STR_LIT:\\>" + exeAlias ) <EOL> def UnregisterPythonExe ( exeAlias ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> win32api . RegDeleteKey ( GetRootKey ( ) , GetAppPathsKey ( ) + "<STR_LIT:\\>" + exeAlias ) <EOL> except win32api . error , ( code , fn , details ) : <EOL> import winerror <EOL> if code != winerror . ERROR_FILE_NOT_FOUND : <EOL> raise win32api . error , ( code , fn , desc ) <EOL> return <EOL> def RegisterNamedPath ( name , path ) : <EOL> """<STR_LIT>""" <EOL> keyStr = BuildDefaultPythonKey ( ) + "<STR_LIT>" <EOL> if name : keyStr = keyStr + "<STR_LIT:\\>" + name <EOL> win32api . RegSetValue ( GetRootKey ( ) , keyStr , win32con . REG_SZ , path ) <EOL> def UnregisterNamedPath ( name ) : <EOL> """<STR_LIT>""" <EOL> keyStr = BuildDefaultPythonKey ( ) + "<STR_LIT>" + name <EOL> try : <EOL> win32api . RegDeleteKey ( GetRootKey ( ) , keyStr ) <EOL> except win32api . error , ( code , fn , details ) : <EOL> import winerror <EOL> if code != winerror . ERROR_FILE_NOT_FOUND : <EOL> raise win32api . error , ( code , fn , desc ) <EOL> return <EOL> def GetRegisteredNamedPath ( name ) : <EOL> """<STR_LIT>""" <EOL> keyStr = BuildDefaultPythonKey ( ) + "<STR_LIT>" <EOL> if name : keyStr = keyStr + "<STR_LIT:\\>" + name <EOL> try : <EOL> return win32api . RegQueryValue ( GetRootKey ( ) , keyStr ) <EOL> except win32api . error , ( code , fn , details ) : <EOL> import winerror <EOL> if code != winerror . ERROR_FILE_NOT_FOUND : <EOL> raise win32api . error , ( code , fn , details ) <EOL> return None <EOL> def RegisterModule ( modName , modPath ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> import os <EOL> os . stat ( modPath ) <EOL> except os . error : <EOL> print "<STR_LIT>" % modPath <EOL> win32api . RegSetValue ( GetRootKey ( ) , <EOL> BuildDefaultPythonKey ( ) + "<STR_LIT>" % modName , <EOL> win32con . REG_SZ , modPath ) <EOL> def UnregisterModule ( modName ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> win32api . RegDeleteKey ( GetRootKey ( ) , <EOL> BuildDefaultPythonKey ( ) + "<STR_LIT>" % modName ) <EOL> except win32api . error , ( code , fn , desc ) : <EOL> import winerror <EOL> if code != winerror . ERROR_FILE_NOT_FOUND : <EOL> raise win32api . error , ( code , fn , desc ) <EOL> def GetRegisteredHelpFile ( helpDesc ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return GetRegistryDefaultValue ( BuildDefaultPythonKey ( ) + "<STR_LIT>" + helpDesc ) <EOL> except win32api . error : <EOL> try : <EOL> return GetRegistryDefaultValue ( BuildDefaultPythonKey ( ) + "<STR_LIT>" + helpDesc , win32con . HKEY_CURRENT_USER ) <EOL> except win32api . error : <EOL> pass <EOL> return None <EOL> def RegisterHelpFile ( helpFile , helpPath , helpDesc = None , bCheckFile = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if helpDesc is None : helpDesc = helpFile <EOL> fullHelpFile = os . path . join ( helpPath , helpFile ) <EOL> try : <EOL> if bCheckFile : os . stat ( fullHelpFile ) <EOL> except os . error : <EOL> raise ValueError , "<STR_LIT>" <EOL> win32api . RegSetValue ( GetRootKey ( ) , <EOL> BuildDefaultPythonKey ( ) + "<STR_LIT>" % helpDesc , win32con . REG_SZ , fullHelpFile ) <EOL> def UnregisterHelpFile ( helpFile , helpDesc = None ) : <EOL> """<STR_LIT>""" <EOL> key = win32api . RegOpenKey ( win32con . HKEY_LOCAL_MACHINE , "<STR_LIT>" , <NUM_LIT:0> , win32con . KEY_ALL_ACCESS ) <EOL> try : <EOL> try : <EOL> win32api . RegDeleteValue ( key , helpFile ) <EOL> except win32api . error , ( code , fn , desc ) : <EOL> import winerror <EOL> if code != winerror . ERROR_FILE_NOT_FOUND : <EOL> raise win32api . error , ( code , fn , desc ) <EOL> finally : <EOL> win32api . RegCloseKey ( key ) <EOL> if helpDesc is None : helpDesc = helpFile <EOL> try : <EOL> win32api . RegDeleteKey ( GetRootKey ( ) , <EOL> BuildDefaultPythonKey ( ) + "<STR_LIT>" % helpDesc ) <EOL> except win32api . error , ( code , fn , desc ) : <EOL> import winerror <EOL> if code != winerror . ERROR_FILE_NOT_FOUND : <EOL> raise win32api . error , ( code , fn , desc ) <EOL> def RegisterCoreDLL ( coredllName = None ) : <EOL> """<STR_LIT>""" <EOL> if coredllName is None : <EOL> coredllName = win32api . GetModuleFileName ( sys . dllhandle ) <EOL> else : <EOL> try : <EOL> os . stat ( coredllName ) <EOL> except os . error : <EOL> print "<STR_LIT>" % coredllName <EOL> hKey = win32api . RegCreateKey ( GetRootKey ( ) , BuildDefaultPythonKey ( ) ) <EOL> try : <EOL> win32api . RegSetValue ( hKey , "<STR_LIT>" , win32con . REG_SZ , coredllName ) <EOL> finally : <EOL> win32api . RegCloseKey ( hKey ) <EOL> win32api . RegSetValue ( GetRootKey ( ) , "<STR_LIT>" , win32con . REG_SZ , sys . winver ) <EOL> def RegisterFileExtensions ( defPyIcon , defPycIcon , runCommand ) : <EOL> """<STR_LIT>""" <EOL> pythonFileId = RegistryIDPyFile <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , "<STR_LIT>" , win32con . REG_SZ , pythonFileId ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , pythonFileId , win32con . REG_SZ , "<STR_LIT>" ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , "<STR_LIT>" % pythonFileId , win32con . REG_SZ , CLSIDPyFile ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , "<STR_LIT>" % pythonFileId , win32con . REG_SZ , defPyIcon ) <EOL> base = "<STR_LIT>" % RegistryIDPyFile <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" , win32con . REG_SZ , "<STR_LIT>" ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" , win32con . REG_SZ , runCommand ) <EOL> pythonFileId = RegistryIDPycFile <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , "<STR_LIT>" , win32con . REG_SZ , pythonFileId ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , pythonFileId , win32con . REG_SZ , "<STR_LIT>" ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , "<STR_LIT>" % pythonFileId , win32con . REG_SZ , defPycIcon ) <EOL> base = "<STR_LIT>" % pythonFileId <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" , win32con . REG_SZ , "<STR_LIT>" ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" , win32con . REG_SZ , runCommand ) <EOL> def RegisterShellCommand ( shellCommand , exeCommand , shellUserCommand = None ) : <EOL> base = "<STR_LIT>" % RegistryIDPyFile <EOL> if shellUserCommand : <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" % ( shellCommand ) , win32con . REG_SZ , shellUserCommand ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" % ( shellCommand ) , win32con . REG_SZ , exeCommand ) <EOL> def RegisterDDECommand ( shellCommand , ddeApp , ddeTopic , ddeCommand ) : <EOL> base = "<STR_LIT>" % RegistryIDPyFile <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" % ( shellCommand ) , win32con . REG_SZ , ddeCommand ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" % ( shellCommand ) , win32con . REG_SZ , ddeApp ) <EOL> win32api . RegSetValue ( win32con . HKEY_CLASSES_ROOT , base + "<STR_LIT>" % ( shellCommand ) , win32con . REG_SZ , ddeTopic ) </s>
