home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32_scripts_regsetup.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  21.9 KB  |  622 lines

  1. # A tool to setup the Python registry.
  2.  
  3. error = "Registry Setup Error"
  4.  
  5. import sys # at least we can count on this!
  6.  
  7. def FileExists(fname):
  8.     """Check if a file exists.  Returns true or false.
  9.     """
  10.     import os
  11.     try:
  12.         os.stat(fname)
  13.         return 1
  14.     except os.error, details:
  15.         return 0
  16.  
  17. def IsPackageDir(path, packageName, knownFileName):
  18.     """Given a path, a ni package name, and possibly a known file name in
  19.            the root of the package, see if this path is good.
  20.       """
  21.     import os
  22.     if knownFileName is None:
  23.         knownFileName = "."
  24.     return FileExists(os.path.join(os.path.join(path, packageName),knownFileName))
  25.  
  26. def IsDebug():
  27.         """Return "_d" if we're running a debug version.
  28.         
  29.         This is to be used within DLL names when locating them.
  30.         """
  31.         import _winreg
  32.         if _winreg.__file__[-6:] == '_d.pyd':
  33.                 return '_d'
  34.         return ''
  35.  
  36. def FindPackagePath(packageName, knownFileName, searchPaths):
  37.     """Find a package.
  38.  
  39.            Given a ni style package name, check the package is registered.
  40.  
  41.            First place looked is the registry for an existing entry.  Then
  42.            the searchPaths are searched.
  43.       """
  44.     import regutil, os
  45.     pathLook = regutil.GetRegisteredNamedPath(packageName)
  46.     if pathLook and IsPackageDir(pathLook, packageName, knownFileName):
  47.         return pathLook, None # The currently registered one is good.
  48.     # Search down the search paths.
  49.     for pathLook in searchPaths:
  50.         if IsPackageDir(pathLook, packageName, knownFileName):
  51.             # Found it
  52.             ret = os.path.abspath(pathLook)
  53.             return ret, ret
  54.     raise error, "The package %s can not be located" % packageName
  55.  
  56. def FindHelpPath(helpFile, helpDesc, searchPaths):
  57.     # See if the current registry entry is OK
  58.     import os, _winreg
  59.     try:
  60.         key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Help", 0, _winreg.KEY_ALL_ACCESS)
  61.         try:
  62.             try:
  63.                 path = _winreg.QueryValueEx(key, helpDesc)[0]
  64.                 if FileExists(os.path.join(path, helpFile)):
  65.                     return os.path.abspath(path)
  66.             except EnvironmentError:
  67.                 pass # no registry entry.
  68.         finally:
  69.             key.Close()
  70.     except EnvironmentError:
  71.         pass
  72.     for pathLook in searchPaths:
  73.         if FileExists(os.path.join(pathLook, helpFile)):
  74.             return os.path.abspath(pathLook)
  75.         pathLook = os.path.join(pathLook, "Help")
  76.         if FileExists(os.path.join( pathLook, helpFile)):
  77.             return os.path.abspath(pathLook)
  78.     raise error, "The help file %s can not be located" % helpFile
  79.  
  80. def FindAppPath(appName, knownFileName, searchPaths):
  81.     """Find an application.
  82.  
  83.          First place looked is the registry for an existing entry.  Then
  84.          the searchPaths are searched.
  85.       """
  86.     # Look in the first path.
  87.     import regutil, string, os
  88.     regPath = regutil.GetRegisteredNamedPath(appName)
  89.     if regPath:
  90.         pathLook = string.split(regPath,";")[0]
  91.     if regPath and FileExists(os.path.join(pathLook, knownFileName)):
  92.         return None # The currently registered one is good.
  93.     # Search down the search paths.
  94.     for pathLook in searchPaths:
  95.         if FileExists(os.path.join(pathLook, knownFileName)):
  96.             # Found it
  97.             return os.path.abspath(pathLook)
  98.     raise error, "The file %s can not be located for application %s" % (knownFileName, appName)
  99.  
  100. def FindRegisteredModule(moduleName, possibleRealNames, searchPaths):
  101.     """Find a registered module.
  102.  
  103.          First place looked is the registry for an existing entry.  Then
  104.          the searchPaths are searched.
  105.          
  106.        Returns the full path to the .exe or None if the current registered entry is OK.
  107.       """
  108.     import _winreg, regutil, string
  109.     try:
  110.         fname = _winreg.QueryValue(regutil.GetRootKey(), \
  111.                        regutil.BuildDefaultPythonKey() + "\\Modules\\%s" % moduleName)
  112.  
  113.         if FileExists(fname):
  114.             return None # Nothing extra needed
  115.  
  116.     except EnvironmentError:
  117.         pass
  118.     return LocateFileName(possibleRealNames, searchPaths)
  119.  
  120. def FindPythonExe(exeAlias, possibleRealNames, searchPaths):
  121.     """Find an exe.
  122.  
  123.          First place looked is the registry for an existing entry.  Then
  124.          the searchPaths are searched.
  125.          
  126.        Returns the full path to the .exe, and a boolean indicating if the current 
  127.        registered entry is OK.
  128.       """
  129.     import _winreg, regutil, string
  130.     if possibleRealNames is None:
  131.         possibleRealNames = exeAlias
  132.     try:
  133.         fname = _winreg.QueryValue(regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exeAlias)
  134.         if FileExists(fname):
  135.             return fname, 1 # Registered entry OK
  136.  
  137.     except EnvironmentError:
  138.         pass
  139.     return LocateFileName(possibleRealNames, searchPaths), 0
  140.  
  141. def QuotedFileName(fname):
  142.     """Given a filename, return a quoted version if necessary
  143.       """
  144.     import regutil, string
  145.     try:
  146.         string.index(fname, " ") # Other chars forcing quote?
  147.         return '"%s"' % fname
  148.     except ValueError:
  149.         # No space in name.
  150.         return fname
  151.  
  152. def LocateFileName(fileNamesString, searchPaths):
  153.     """Locate a file name, anywhere on the search path.
  154.  
  155.        If the file can not be located, prompt the user to find it for us
  156.        (using a common OpenFile dialog)
  157.  
  158.        Raises KeyboardInterrupt if the user cancels.
  159.     """
  160.     import regutil, string, os
  161.     fileNames = string.split(fileNamesString,";")
  162.     for path in searchPaths:
  163.         for fileName in fileNames:
  164.             try:
  165.                 retPath = os.path.join(path, fileName)
  166.                 os.stat(retPath)
  167.                 break
  168.             except os.error:
  169.                 retPath = None
  170.         if retPath:
  171.             break
  172.     else:
  173.         fileName = fileNames[0]
  174.         try:
  175.             import win32ui, win32con
  176.         except ImportError:
  177.             raise error, "Need to locate the file %s, but the win32ui module is not available\nPlease run the program again, passing as a parameter the path to this file." % fileName
  178.         # Display a common dialog to locate the file.
  179.         flags=win32con.OFN_FILEMUSTEXIST
  180.         ext = os.path.splitext(fileName)[1]
  181.         filter = "Files of requested type (*%s)|*%s||" % (ext,ext)
  182.         dlg = win32ui.CreateFileDialog(1,None,fileName,flags,filter,None)
  183.         dlg.SetOFNTitle("Locate " + fileName)
  184.         if dlg.DoModal() <> win32con.IDOK:
  185.             raise KeyboardInterrupt, "User cancelled the process"
  186.         retPath = dlg.GetPathName()
  187.     return os.path.abspath(retPath)
  188.  
  189. def LocatePath(fileName, searchPaths):
  190.     """Like LocateFileName, but returns a directory only.
  191.     """
  192.     import os
  193.     return os.path.abspath(os.path.split(LocateFileName(fileName, searchPaths))[0])
  194.  
  195. def LocateOptionalPath(fileName, searchPaths):
  196.     """Like LocatePath, but returns None if the user cancels.
  197.     """
  198.     try:
  199.         return LocatePath(fileName, searchPaths)
  200.     except KeyboardInterrupt:
  201.         return None
  202.  
  203.  
  204. def LocateOptionalFileName(fileName, searchPaths = None):
  205.     """Like LocateFileName, but returns None if the user cancels.
  206.     """
  207.     try:
  208.         return LocateFileName(fileName, searchPaths)
  209.     except KeyboardInterrupt:
  210.         return None
  211.  
  212. def LocatePythonCore(searchPaths):
  213.     """Locate and validate the core Python directories.  Returns a list
  214.          of paths that should be used as the core (ie, un-named) portion of
  215.          the Python path.
  216.     """
  217.     import string, os, regutil
  218.     currentPath = regutil.GetRegisteredNamedPath(None)
  219.     if currentPath:
  220.         presearchPaths = string.split(currentPath, ";")
  221.     else:
  222.         presearchPaths = [os.path.abspath(".")]
  223.     libPath = None
  224.     for path in presearchPaths:
  225.         if FileExists(os.path.join(path, "os.py")):
  226.             libPath = path
  227.             break
  228.     if libPath is None and searchPaths is not None:
  229.         libPath = LocatePath("os.py", searchPaths)
  230.     if libPath is None:
  231.         raise error, "The core Python library could not be located."
  232.  
  233.     corePath = None
  234.     suffix = IsDebug()
  235.     for path in presearchPaths:
  236.         if FileExists(os.path.join(path, "parser%s.pyd" % suffix)):
  237.             corePath = path
  238.             break
  239.     if corePath is None and searchPaths is not None:
  240.         corePath = LocatePath("parser%s.pyd" % suffix, searchPaths)
  241.     if corePath is None:
  242.         raise error, "The core Python path could not be located."
  243.  
  244.     installPath = os.path.abspath(os.path.join(libPath, ".."))
  245.     return installPath, [libPath, corePath]
  246.  
  247. def FindRegisterPackage(packageName, knownFile, searchPaths, registryAppName = None):
  248.     """Find and Register a package.
  249.  
  250.        Assumes the core registry setup correctly.
  251.  
  252.        In addition, if the location located by the package is already
  253.            in the **core** path, then an entry is registered, but no path.
  254.        (no other paths are checked, as the application whose path was used
  255.        may later be uninstalled.  This should not happen with the core)
  256.     """
  257.     import regutil, string
  258.     if not packageName: raise error, "A package name must be supplied"
  259.     corePaths = string.split(regutil.GetRegisteredNamedPath(None),";")
  260.     if not searchPaths: searchPaths = corePaths
  261.     registryAppName = registryAppName or packageName
  262.     try:
  263.         pathLook, pathAdd = FindPackagePath(packageName, knownFile, searchPaths)
  264.         if pathAdd is not None:
  265.             if pathAdd in corePaths:
  266.                 pathAdd = ""
  267.             regutil.RegisterNamedPath(registryAppName, pathAdd)
  268.         return pathLook
  269.     except error, details:
  270.         print "*** The %s package could not be registered - %s" % (packageName, details)
  271.         print "*** Please ensure you have passed the correct paths on the command line."
  272.         print "*** - For packages, you should pass a path to the packages parent directory,"
  273.         print "*** - and not the package directory itself..."
  274.  
  275.  
  276. def FindRegisterApp(appName, knownFiles, searchPaths):
  277.     """Find and Register a package.
  278.  
  279.        Assumes the core registry setup correctly.
  280.  
  281.     """
  282.     import regutil, string
  283.     if type(knownFiles)==type(''):
  284.         knownFiles = [knownFiles]
  285.     paths=[]
  286.     try:
  287.         for knownFile in knownFiles:
  288.             pathLook = FindAppPath(appName, knownFile, searchPaths)
  289.             if pathLook:
  290.                 paths.append(pathLook)
  291.     except error, details:
  292.         print "*** ", details
  293.         return
  294.  
  295.     regutil.RegisterNamedPath(appName, string.join(paths,";"))
  296.  
  297. def FindRegisterModule(modName, actualFileNames, searchPaths):
  298.     """Find and Register a module.
  299.  
  300.        Assumes the core registry setup correctly.
  301.     """
  302.     import regutil
  303.     try:
  304.         fname = FindRegisteredModule(modName, actualFileNames, searchPaths)
  305.         if fname is not None:
  306.             regutil.RegisterModule(modName, fname)
  307.     except error, details:
  308.         print "*** ", details
  309.  
  310. def FindRegisterPythonExe(exeAlias, searchPaths, actualFileNames = None):
  311.     """Find and Register a Python exe (not necessarily *the* python.exe)
  312.  
  313.        Assumes the core registry setup correctly.
  314.     """
  315.     import regutil, string
  316.     fname, ok = FindPythonExe(exeAlias, actualFileNames, searchPaths)
  317.     if not ok:
  318.         regutil.RegisterPythonExe(fname, exeAlias)
  319.     return fname
  320.  
  321.  
  322. def FindRegisterHelpFile(helpFile, searchPaths, helpDesc = None ):
  323.     import regutil
  324.     
  325.     try:
  326.         pathLook = FindHelpPath(helpFile, helpDesc, searchPaths)
  327.     except error, details:
  328.         print "*** ", details
  329.         return
  330. #    print "%s found at %s" % (helpFile, pathLook)
  331.     regutil.RegisterHelpFile(helpFile, pathLook, helpDesc)
  332.     
  333. def SetupCore(searchPaths):
  334.     """Setup the core Python information in the registry.
  335.  
  336.        This function makes no assumptions about the current state of sys.path.
  337.  
  338.        After this function has completed, you should have access to the standard
  339.        Python library, and the standard Win32 extensions
  340.     """
  341.  
  342.     import sys    
  343.     for path in searchPaths:
  344.         sys.path.append(path)
  345.  
  346.     import string, os
  347.     import regutil, _winreg, win32api
  348.     
  349.     installPath, corePaths = LocatePythonCore(searchPaths)
  350.     # Register the core Pythonpath.
  351.     print corePaths
  352.     regutil.RegisterNamedPath(None, string.join(corePaths,";"))
  353.  
  354.     # Register the install path.
  355.     hKey = _winreg.CreateKey(regutil.GetRootKey() , regutil.BuildDefaultPythonKey())
  356.     try:
  357.         # Core Paths.
  358.         _winreg.SetValue(hKey, "InstallPath", _winreg.REG_SZ, installPath)
  359.     finally:
  360.         _winreg.CloseKey(hKey)
  361.     # The core DLL.
  362. #    regutil.RegisterCoreDLL()
  363.  
  364.     # Register the win32 extensions, as some of them are pretty much core!
  365.     # Why doesnt win32con.__file__ give me a path? (ahh - because only the .pyc exists?)
  366.  
  367.     # Register the win32 core paths.
  368.     win32paths = os.path.abspath( os.path.split(win32api.__file__)[0]) + ";" + \
  369.                  os.path.abspath( os.path.split(LocateFileName("win32con.py;win32con.pyc", sys.path ) )[0] )
  370.  
  371.     suffix = IsDebug()
  372.     ver_str = hex(sys.hexversion)[2] + hex(sys.hexversion)[4]
  373.     FindRegisterModule("pywintypes", "pywintypes%s%s.dll" % (ver_str, suffix), [".", win32api.GetSystemDirectory()])
  374.     regutil.RegisterNamedPath("win32",win32paths)
  375.  
  376.  
  377. def RegisterShellInfo(searchPaths):
  378.     """Registers key parts of the Python installation with the Windows Shell.
  379.  
  380.        Assumes a valid, minimal Python installation exists
  381.        (ie, SetupCore() has been previously successfully run)
  382.     """
  383.     import regutil, win32con
  384.     suffix = IsDebug()
  385.     # Set up a pointer to the .exe's
  386.     exePath = FindRegisterPythonExe("Python%s.exe" % suffix, searchPaths)
  387.     regutil.SetRegistryDefaultValue(".py", "Python.File", win32con.HKEY_CLASSES_ROOT)
  388.     regutil.RegisterShellCommand("Open", QuotedFileName(exePath)+" \"%1\" %*", "&Run")
  389.     regutil.SetRegistryDefaultValue("Python.File\\DefaultIcon", "%s,0" % exePath, win32con.HKEY_CLASSES_ROOT)
  390.     
  391.     FindRegisterHelpFile("Python.hlp", searchPaths, "Main Python Documentation")
  392.     FindRegisterHelpFile("ActivePython.chm", searchPaths, "Main Python Documentation")
  393.  
  394.     # We consider the win32 core, as it contains all the win32 api type
  395.     # stuff we need.
  396. #    FindRegisterApp("win32", ["win32con.pyc", "win32api%s.pyd" % suffix], searchPaths)
  397.  
  398. def RegisterPythonwin(searchPaths):
  399.     """Knows how to register Pythonwin components
  400.     """
  401.     import regutil
  402.     suffix = IsDebug()
  403. #    FindRegisterApp("Pythonwin", "docview.py", searchPaths)
  404.  
  405.     FindRegisterHelpFile("PyWin32.chm", searchPaths, "Pythonwin Reference")
  406.     
  407.     FindRegisterPythonExe("pythonwin%s.exe" % suffix, searchPaths, "Pythonwin%s.exe" % suffix)
  408.  
  409.     fnamePythonwin = regutil.GetRegisteredExe("Pythonwin%s.exe" % suffix)
  410.     fnamePython = regutil.GetRegisteredExe("Python%s.exe" % suffix)
  411.  
  412.     regutil.RegisterShellCommand("Edit", QuotedFileName(fnamePythonwin)+" /edit \"%1\"")
  413.     regutil.RegisterDDECommand("Edit", "Pythonwin", "System", '[self.OpenDocumentFile(r"%1")]')
  414.  
  415.     FindRegisterPackage("pywin", "__init__.py", searchPaths, "Pythonwin")
  416. #    FindRegisterModule("win32ui", "win32ui%s.pyd" % suffix, searchPaths)
  417. #    FindRegisterModule("win32uiole", "win32uiole%s.pyd" % suffix, searchPaths)
  418.     
  419.     regutil.RegisterFileExtensions(defPyIcon=fnamePythonwin+",0", 
  420.                                    defPycIcon = fnamePythonwin+",5",
  421.                                    runCommand = QuotedFileName(fnamePython)+" \"%1\" %*")
  422.  
  423. def UnregisterPythonwin():
  424.     """Knows how to unregister Pythonwin components
  425.     """
  426.     import regutil
  427.     regutil.UnregisterNamedPath("Pythonwin")
  428.     regutil.UnregisterHelpFile("Pythonwin.hlp")
  429.     regutil.UnregisterHelpFile("PyWin32.chm")
  430.  
  431.     suffix = IsDebug()
  432.     regutil.UnregisterPythonExe("pythonwin%s.exe" % suffix)
  433.     
  434.     #regutil.UnregisterShellCommand("Edit")
  435.  
  436.     regutil.UnregisterModule("win32ui")
  437.     regutil.UnregisterModule("win32uiole")
  438.     
  439.  
  440. def RegisterWin32com(searchPaths):
  441.     """Knows how to register win32com components
  442.     """
  443.     import win32api
  444. #    import ni,win32dbg;win32dbg.brk()
  445.     corePath = FindRegisterPackage("win32com", "olectl.py", searchPaths)
  446.     if corePath:
  447.         FindRegisterHelpFile("PyWin32.chm", searchPaths + [corePath+"\\win32com"], "Python COM Reference")
  448.         suffix = IsDebug()
  449.         ver_str = hex(sys.hexversion)[2] + hex(sys.hexversion)[4]
  450.         FindRegisterModule("pythoncom", "pythoncom%s%s.dll" % (ver_str, suffix), [win32api.GetSystemDirectory(), '.'])
  451.  
  452. usage = """\
  453. regsetup.py - Setup/maintain the registry for Python apps.
  454.  
  455. Run without options, (but possibly search paths) to repair a totally broken
  456. python registry setup.  This should allow other options to work.
  457.  
  458. Usage:   %s [options ...] paths ...
  459. -p packageName  -- Find and register a package.  Looks in the paths for
  460.                    a sub-directory with the name of the package, and
  461.                    adds a path entry for the package.
  462. -a appName      -- Unconditionally add an application name to the path.
  463.                    A new path entry is create with the app name, and the
  464.                    paths specified are added to the registry.
  465. -c              -- Add the specified paths to the core Pythonpath.
  466.                    If a path appears on the core path, and a package also 
  467.                    needs that same path, the package will not bother 
  468.                    registering it.  Therefore, By adding paths to the 
  469.                    core path, you can avoid packages re-registering the same path.  
  470. -m filename     -- Find and register the specific file name as a module.
  471.                    Do not include a path on the filename!
  472. --shell         -- Register everything with the Win95/NT shell.
  473. --pythonwin     -- Find and register all Pythonwin components.
  474. --unpythonwin   -- Unregister Pythonwin
  475. --win32com      -- Find and register all win32com components
  476. --upackage name -- Unregister the package
  477. --uapp name     -- Unregister the app (identical to --upackage)
  478. --umodule name  -- Unregister the module
  479.  
  480. --description   -- Print a description of the usage.
  481. --examples      -- Print examples of usage.
  482. """ % sys.argv[0]
  483.  
  484. description="""\
  485. If no options are processed, the program attempts to validate and set 
  486. the standard Python path to the point where the standard library is
  487. available.  This can be handy if you move Python to a new drive/sub-directory,
  488. in which case most of the options would fail (as they need at least string.py,
  489. os.py etc to function.)
  490. Running without options should repair Python well enough to run with 
  491. the other options.
  492.  
  493. paths are search paths that the program will use to seek out a file.
  494. For example, when registering the core Python, you may wish to
  495. provide paths to non-standard places to look for the Python help files,
  496. library files, etc.  When registering win32com, you should pass paths
  497. specific to win32com.
  498.  
  499. See also the "regcheck.py" utility which will check and dump the contents
  500. of the registry.
  501. """
  502.  
  503. examples="""\
  504. Examples:
  505. "regsetup c:\\wierd\\spot\\1 c:\\wierd\\spot\\2"
  506. Attempts to setup the core Python.  Looks in some standard places,
  507. as well as the 2 wierd spots to locate the core Python files (eg, Python.exe,
  508. python14.dll, the standard library and Win32 Extensions.
  509.  
  510. "regsetup --win32com"
  511. Attempts to register win32com.  No options are passed, so this is only
  512. likely to succeed if win32com is already successfully registered, or the
  513. win32com directory is current.  If neither of these are true, you should pass
  514. the path to the win32com directory.
  515.  
  516. "regsetup -a myappname . .\subdir"
  517. Registers a new Pythonpath entry named myappname, with "C:\\I\\AM\\HERE" and
  518. "C:\\I\\AM\\HERE\subdir" added to the path (ie, all args are converted to
  519. absolute paths)
  520.  
  521. "regsetup -c c:\\my\\python\\files"
  522. Unconditionally add "c:\\my\\python\\files" to the 'core' Python path.
  523.  
  524. "regsetup -m some.pyd \\windows\\system"
  525. Register the module some.pyd in \\windows\\system as a registered
  526. module.  This will allow some.pyd to be imported, even though the
  527. windows system directory is not (usually!) on the Python Path.
  528.  
  529. "regsetup --umodule some"
  530. Unregister the module "some".  This means normal import rules then apply
  531. for that module.
  532. """
  533.  
  534. if __name__=='__main__':
  535.     if len(sys.argv)>1 and sys.argv[1] in ['/?','-?','-help','-h']:
  536.         print usage
  537.     elif len(sys.argv)==1 or not sys.argv[1][0] in ['/','-']:
  538.         # No args, or useful args.
  539.         searchPath = sys.path[:]
  540.         for arg in sys.argv[1:]:
  541.             searchPath.append(arg)
  542.         # Good chance we are being run from the "regsetup.py" directory.
  543.         # Typically this will be "\somewhere\win32\Scripts" and the 
  544.         # "somewhere" and "..\Lib" should also be searched.
  545.         searchPath.append("..\\Build")
  546.         searchPath.append("..\\Lib")
  547.         searchPath.append("..")
  548.         searchPath.append("..\\..")
  549.  
  550.                 # for developers:
  551.                 # also search somewhere\lib, ..\build, and ..\..\build
  552.         searchPath.append("..\\..\\lib")
  553.         searchPath.append("..\\build")
  554.         searchPath.append("..\\..\\pcbuild")
  555.  
  556.         print "Attempting to setup/repair the Python core"
  557.         
  558.         SetupCore(searchPath)
  559.         RegisterShellInfo(searchPath)    
  560.         # Check the registry.
  561.         print "Registration complete - checking the registry..."
  562.         import regcheck
  563.         regcheck.CheckRegistry()
  564.     else:
  565.         searchPaths = []
  566.         import getopt, string
  567.         opts, args = getopt.getopt(sys.argv[1:], 'p:a:m:c', 
  568.             ['pythonwin','unpythonwin','win32com','shell','upackage=','uapp=','umodule=','description','examples'])
  569.         for arg in args:
  570.             searchPaths.append(arg)
  571.         for o,a in opts:
  572.             if o=='--description':
  573.                 print description
  574.             if o=='--examples':
  575.                 print examples
  576.             if o=='--shell':
  577.                 print "Registering the Python core."
  578.                 RegisterShellInfo(searchPaths)
  579.             if o=='--pythonwin':
  580.                 print "Registering Pythonwin"
  581.                 RegisterPythonwin(searchPaths)
  582.             if o=='--win32com':
  583.                 print "Registering win32com"
  584.                 RegisterWin32com(searchPaths)
  585.             if o=='--unpythonwin':
  586.                 print "Unregistering Pythonwin"
  587.                 UnregisterPythonwin()
  588.             if o=='-m':
  589.                 import os
  590.                 print "Registering module",a
  591.                 FindRegisterModule(os.path.splitext(a)[0],a, searchPaths)
  592.             if o=='--umodule':
  593.                 import os, regutil
  594.                 print "Unregistering module",a
  595.                 regutil.UnregisterModule(os.path.splitext(a)[0])
  596.             if o=='-p':
  597.                 print "Registering package", a
  598.                 FindRegisterPackage(a,None,searchPaths)
  599.             if o in ['--upackage', '--uapp']:
  600.                 import regutil
  601.                 print "Unregistering application/package", a
  602.                 regutil.UnregisterNamedPath(a)
  603.             if o=='-a':
  604.                 import regutil
  605.                 path = string.join(searchPaths,";")
  606.                 print "Registering application", a,"to path",path
  607.                 regutil.RegisterNamedPath(a,path)
  608.             if o=='-c':
  609.                 if not len(searchPaths):
  610.                     raise error, "-c option must provide at least one additional path"
  611.                 import win32api, regutil
  612.                 currentPaths = string.split(regutil.GetRegisteredNamedPath(None),";")
  613.                 oldLen = len(currentPaths)
  614.                 for newPath in searchPaths:
  615.                     if newPath not in currentPaths:
  616.                         currentPaths.append(newPath)
  617.                 if len(currentPaths)<>oldLen:
  618.                     print "Registering %d new core paths" % (len(currentPaths)-oldLen)
  619.                     regutil.RegisterNamedPath(None,string.join(currentPaths,";"))
  620.                 else:
  621.                     print "All specified paths are already registered."
  622.