home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2535 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  8.2 KB  |  253 lines

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