home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / regutil.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  7.9 KB  |  234 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. import win32api
  5. import win32con
  6. import sys
  7. import os
  8. error = 'Registry utility error'
  9. CLSIDPyFile = '{b51df050-06ae-11cf-ad3b-524153480001}'
  10. RegistryIDPyFile = 'Python.File'
  11. RegistryIDPycFile = 'Python.CompiledFile'
  12.  
  13. def GetRootKey():
  14.     return win32con.HKEY_LOCAL_MACHINE
  15.  
  16.  
  17. def GetRegistryDefaultValue(subkey, rootkey = None):
  18.     if rootkey is None:
  19.         rootkey = GetRootKey()
  20.     return win32api.RegQueryValue(rootkey, subkey)
  21.  
  22.  
  23. def SetRegistryDefaultValue(subKey, value, rootkey = None):
  24.     if rootkey is None:
  25.         rootkey = GetRootKey()
  26.     if type(value) == str:
  27.         typeId = win32con.REG_SZ
  28.     elif type(value) == int:
  29.         typeId = win32con.REG_DWORD
  30.     else:
  31.         raise TypeError('Value must be string or integer - was passed ' + repr(value))
  32.     None.RegSetValue(rootkey, subKey, typeId, value)
  33.  
  34.  
  35. def BuildDefaultPythonKey():
  36.     return 'Software\\Python\\PythonCore\\' + sys.winver
  37.  
  38.  
  39. def GetAppPathsKey():
  40.     return 'Software\\Microsoft\\Windows\\CurrentVersion\\App Paths'
  41.  
  42.  
  43. def RegisterPythonExe(exeFullPath, exeAlias = None, exeAppPath = None):
  44.     if exeAppPath:
  45.         raise error('Do not support exeAppPath argument currently')
  46.     if exeAlias is None:
  47.         exeAlias = os.path.basename(exeFullPath)
  48.     win32api.RegSetValue(GetRootKey(), GetAppPathsKey() + '\\' + exeAlias, win32con.REG_SZ, exeFullPath)
  49.  
  50.  
  51. def GetRegisteredExe(exeAlias):
  52.     return win32api.RegQueryValue(GetRootKey(), GetAppPathsKey() + '\\' + exeAlias)
  53.  
  54.  
  55. def UnregisterPythonExe(exeAlias):
  56.     
  57.     try:
  58.         win32api.RegDeleteKey(GetRootKey(), GetAppPathsKey() + '\\' + exeAlias)
  59.     except win32api.error:
  60.         exc = None
  61.         import winerror
  62.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  63.             raise 
  64.         return None
  65.  
  66.  
  67.  
  68. def RegisterNamedPath(name, path):
  69.     keyStr = BuildDefaultPythonKey() + '\\PythonPath'
  70.     if name:
  71.         keyStr = keyStr + '\\' + name
  72.     win32api.RegSetValue(GetRootKey(), keyStr, win32con.REG_SZ, path)
  73.  
  74.  
  75. def UnregisterNamedPath(name):
  76.     keyStr = BuildDefaultPythonKey() + '\\PythonPath\\' + name
  77.     
  78.     try:
  79.         win32api.RegDeleteKey(GetRootKey(), keyStr)
  80.     except win32api.error:
  81.         exc = None
  82.         import winerror
  83.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  84.             raise 
  85.         return None
  86.  
  87.  
  88.  
  89. def GetRegisteredNamedPath(name):
  90.     keyStr = BuildDefaultPythonKey() + '\\PythonPath'
  91.     if name:
  92.         keyStr = keyStr + '\\' + name
  93.     
  94.     try:
  95.         return win32api.RegQueryValue(GetRootKey(), keyStr)
  96.     except win32api.error:
  97.         exc = None
  98.         import winerror
  99.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  100.             raise 
  101.         return None
  102.  
  103.  
  104.  
  105. def RegisterModule(modName, modPath):
  106.     
  107.     try:
  108.         import os
  109.         os.stat(modPath)
  110.     except os.error:
  111.         print 'Warning: Registering non-existant module %s' % modPath
  112.  
  113.     win32api.RegSetValue(GetRootKey(), BuildDefaultPythonKey() + '\\Modules\\%s' % modName, win32con.REG_SZ, modPath)
  114.  
  115.  
  116. def UnregisterModule(modName):
  117.     
  118.     try:
  119.         win32api.RegDeleteKey(GetRootKey(), BuildDefaultPythonKey() + '\\Modules\\%s' % modName)
  120.     except win32api.error:
  121.         exc = None
  122.         import winerror
  123.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  124.             raise 
  125.  
  126.  
  127.  
  128. def GetRegisteredHelpFile(helpDesc):
  129.     
  130.     try:
  131.         return GetRegistryDefaultValue(BuildDefaultPythonKey() + '\\Help\\' + helpDesc)
  132.     except win32api.error:
  133.         
  134.         try:
  135.             return GetRegistryDefaultValue(BuildDefaultPythonKey() + '\\Help\\' + helpDesc, win32con.HKEY_CURRENT_USER)
  136.         except win32api.error:
  137.             pass
  138.         
  139.  
  140.  
  141.  
  142.  
  143. def RegisterHelpFile(helpFile, helpPath, helpDesc = None, bCheckFile = 1):
  144.     if helpDesc is None:
  145.         helpDesc = helpFile
  146.     fullHelpFile = os.path.join(helpPath, helpFile)
  147.     
  148.     try:
  149.         if bCheckFile:
  150.             os.stat(fullHelpFile)
  151.     except os.error:
  152.         raise ValueError('Help file does not exist')
  153.  
  154.     win32api.RegSetValue(GetRootKey(), BuildDefaultPythonKey() + '\\Help\\%s' % helpDesc, win32con.REG_SZ, fullHelpFile)
  155.  
  156.  
  157. def UnregisterHelpFile(helpFile, helpDesc = None):
  158.     key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\Help', 0, win32con.KEY_ALL_ACCESS)
  159.     
  160.     try:
  161.         win32api.RegDeleteValue(key, helpFile)
  162.     except win32api.error:
  163.         exc = None
  164.         import winerror
  165.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  166.             raise 
  167.     finally:
  168.         win32api.RegCloseKey(key)
  169.  
  170.     if helpDesc is None:
  171.         helpDesc = helpFile
  172.     
  173.     try:
  174.         win32api.RegDeleteKey(GetRootKey(), BuildDefaultPythonKey() + '\\Help\\%s' % helpDesc)
  175.     except win32api.error:
  176.         exc = None
  177.         import winerror
  178.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  179.             raise 
  180.  
  181.  
  182.  
  183. def RegisterCoreDLL(coredllName = None):
  184.     if coredllName is None:
  185.         coredllName = win32api.GetModuleFileName(sys.dllhandle)
  186.     else:
  187.         
  188.         try:
  189.             os.stat(coredllName)
  190.         except os.error:
  191.             print 'Warning: Registering non-existant core DLL %s' % coredllName
  192.  
  193.     hKey = win32api.RegCreateKey(GetRootKey(), BuildDefaultPythonKey())
  194.     
  195.     try:
  196.         win32api.RegSetValue(hKey, 'Dll', win32con.REG_SZ, coredllName)
  197.     finally:
  198.         win32api.RegCloseKey(hKey)
  199.  
  200.     win32api.RegSetValue(GetRootKey(), 'Software\\Python\\PythonCore\\CurrentVersion', win32con.REG_SZ, sys.winver)
  201.  
  202.  
  203. def RegisterFileExtensions(defPyIcon, defPycIcon, runCommand):
  204.     pythonFileId = RegistryIDPyFile
  205.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, '.py', win32con.REG_SZ, pythonFileId)
  206.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, pythonFileId, win32con.REG_SZ, 'Python File')
  207.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, '%s\\CLSID' % pythonFileId, win32con.REG_SZ, CLSIDPyFile)
  208.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, '%s\\DefaultIcon' % pythonFileId, win32con.REG_SZ, defPyIcon)
  209.     base = '%s\\Shell' % RegistryIDPyFile
  210.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\Open', win32con.REG_SZ, 'Run')
  211.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\Open\\Command', win32con.REG_SZ, runCommand)
  212.     pythonFileId = RegistryIDPycFile
  213.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, '.pyc', win32con.REG_SZ, pythonFileId)
  214.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, pythonFileId, win32con.REG_SZ, 'Compiled Python File')
  215.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, '%s\\DefaultIcon' % pythonFileId, win32con.REG_SZ, defPycIcon)
  216.     base = '%s\\Shell' % pythonFileId
  217.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\Open', win32con.REG_SZ, 'Run')
  218.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\Open\\Command', win32con.REG_SZ, runCommand)
  219.  
  220.  
  221. def RegisterShellCommand(shellCommand, exeCommand, shellUserCommand = None):
  222.     base = '%s\\Shell' % RegistryIDPyFile
  223.     if shellUserCommand:
  224.         win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\%s' % shellCommand, win32con.REG_SZ, shellUserCommand)
  225.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\%s\\Command' % shellCommand, win32con.REG_SZ, exeCommand)
  226.  
  227.  
  228. def RegisterDDECommand(shellCommand, ddeApp, ddeTopic, ddeCommand):
  229.     base = '%s\\Shell' % RegistryIDPyFile
  230.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\%s\\ddeexec' % shellCommand, win32con.REG_SZ, ddeCommand)
  231.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\%s\\ddeexec\\Application' % shellCommand, win32con.REG_SZ, ddeApp)
  232.     win32api.RegSetValue(win32con.HKEY_CLASSES_ROOT, base + '\\%s\\ddeexec\\Topic' % shellCommand, win32con.REG_SZ, ddeTopic)
  233.  
  234.