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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. import warnings
  5. warnings.warn('The regcheck module has been pending deprecation since build 210', category = PendingDeprecationWarning)
  6. import win32con
  7. import regutil
  8. import win32api
  9. import os
  10. import sys
  11.  
  12. def CheckRegisteredExe(exename):
  13.     
  14.     try:
  15.         os.stat(win32api.RegQueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + '\\' + exename))
  16.     except (os.error, win32api.error):
  17.         print 'Registration of %s - Not registered correctly' % exename
  18.  
  19.  
  20.  
  21. def CheckPathString(pathString):
  22.     for path in pathString.split(';'):
  23.         if not os.path.isdir(path):
  24.             return "'%s' is not a valid directory!" % path
  25.     
  26.  
  27.  
  28. def CheckPythonPaths(verbose):
  29.     if verbose:
  30.         print 'Python Paths:'
  31.     if verbose:
  32.         print '\tCore Path:',
  33.     
  34.     try:
  35.         appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + '\\PythonPath')
  36.     except win32api.error:
  37.         exc = None
  38.         print '** does not exist - ', exc.strerror
  39.  
  40.     problem = CheckPathString(appPath)
  41.     if problem:
  42.         print problem
  43.     elif verbose:
  44.         print appPath
  45.     key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + '\\PythonPath', 0, win32con.KEY_READ)
  46.     
  47.     try:
  48.         keyNo = 0
  49.         while None:
  50.             
  51.             try:
  52.                 appName = win32api.RegEnumKey(key, keyNo)
  53.                 appPath = win32api.RegQueryValue(key, appName)
  54.                 if verbose:
  55.                     print '\t' + appName + ':',
  56.                 if appPath:
  57.                     problem = CheckPathString(appPath)
  58.                     if problem:
  59.                         print problem
  60.                     elif verbose:
  61.                         print appPath
  62.                     
  63.                 elif verbose:
  64.                     print '(empty)'
  65.                 keyNo = keyNo + 1
  66.             continue
  67.             except win32api.error:
  68.                 break
  69.                 continue
  70.             
  71.  
  72.         win32api.RegCloseKey(key)
  73.         return None
  74.  
  75.  
  76.  
  77. def CheckHelpFiles(verbose):
  78.     if verbose:
  79.         print 'Help Files:'
  80.     
  81.     try:
  82.         key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + '\\Help', 0, win32con.KEY_READ)
  83.     except win32api.error:
  84.         exc = None
  85.         import winerror
  86.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  87.             raise 
  88.         return None
  89.  
  90.     
  91.     try:
  92.         keyNo = 0
  93.         while None:
  94.             
  95.             try:
  96.                 helpDesc = win32api.RegEnumKey(key, keyNo)
  97.                 helpFile = win32api.RegQueryValue(key, helpDesc)
  98.                 if verbose:
  99.                     print '\t' + helpDesc + ':',
  100.                 
  101.                 try:
  102.                     os.stat(helpFile)
  103.                     if verbose:
  104.                         print helpFile
  105.                 except os.error:
  106.                     print '** Help file %s does not exist' % helpFile
  107.  
  108.                 keyNo = keyNo + 1
  109.             continue
  110.             except win32api.error:
  111.                 exc = None
  112.                 import winerror
  113.                 if exc.winerror != winerror.ERROR_NO_MORE_ITEMS:
  114.                     raise 
  115.                 break
  116.                 continue
  117.             
  118.  
  119.         win32api.RegCloseKey(key)
  120.         return None
  121.  
  122.  
  123.  
  124. def CheckRegisteredModules(verbose):
  125.     k = regutil.BuildDefaultPythonKey() + '\\Modules'
  126.     
  127.     try:
  128.         keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
  129.         print "WARNING: 'Modules' registry entry is deprectated and evil!"
  130.     except win32api.error:
  131.         exc = None
  132.         import winerror
  133.         if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  134.             raise 
  135.         return None
  136.  
  137.  
  138.  
  139. def CheckRegistry(verbose = 0):
  140.     if verbose and 'pythonpath' in os.environ:
  141.         print 'Warning - PythonPath in environment - please check it!'
  142.     CheckPythonPaths(verbose)
  143.     CheckHelpFiles(verbose)
  144.     CheckRegisteredModules(verbose)
  145.     CheckRegisteredExe('Python.exe')
  146.  
  147. if __name__ == '__main__':
  148.     if len(sys.argv) > 1 and sys.argv[1] == '-q':
  149.         verbose = 0
  150.     else:
  151.         verbose = 1
  152.     CheckRegistry(verbose)
  153.