예제 #1
0
def LocatePythonCore(searchPaths):
    """Locate and validate the core Python directories.  Returns a list
     of paths that should be used as the core (ie, un-named) portion of
     the Python path.
    """
    import string, os, regutil
    currentPath = regutil.GetRegisteredNamedPath(None)
    if currentPath:
        presearchPaths = string.split(currentPath, ";")
    else:
        presearchPaths = [os.path.abspath(".")]
    libPath = None
    for path in presearchPaths:
        if FileExists(os.path.join(path, "os.py")):
            libPath = path
            break
    if libPath is None and searchPaths is not None:
        libPath = LocatePath("os.py", searchPaths)
    if libPath is None:
        raise error, "The core Python library could not be located."

    corePath = None
    suffix = IsDebug()
    for path in presearchPaths:
        if FileExists(os.path.join(path, "unicodedata%s.pyd" % suffix)):
            corePath = path
            break
    if corePath is None and searchPaths is not None:
        corePath = LocatePath("unicodedata%s.pyd" % suffix, searchPaths)
    if corePath is None:
        raise error, "The core Python path could not be located."

    installPath = os.path.abspath(os.path.join(libPath, ".."))
    return installPath, [libPath, corePath]
예제 #2
0
def FindRegisterPackage(packageName,
                        knownFile,
                        searchPaths,
                        registryAppName=None):
    """Find and Register a package.

       Assumes the core registry setup correctly.

       In addition, if the location located by the package is already
       in the **core** path, then an entry is registered, but no path.
       (no other paths are checked, as the application whose path was used
       may later be uninstalled.  This should not happen with the core)
    """
    import regutil, string
    if not packageName: raise error, "A package name must be supplied"
    corePaths = string.split(regutil.GetRegisteredNamedPath(None), ";")
    if not searchPaths: searchPaths = corePaths
    registryAppName = registryAppName or packageName
    try:
        pathLook, pathAdd = FindPackagePath(packageName, knownFile,
                                            searchPaths)
        if pathAdd is not None:
            if pathAdd in corePaths:
                pathAdd = ""
            regutil.RegisterNamedPath(registryAppName, pathAdd)
        return pathLook
    except error, details:
        print "*** The %s package could not be registered - %s" % (packageName,
                                                                   details)
        print "*** Please ensure you have passed the correct paths on the command line."
        print "*** - For packages, you should pass a path to the packages parent directory,"
        print "*** - and not the package directory itself..."
예제 #3
0
 def GetSubList(self):
     paths = regutil.GetRegisteredNamedPath(self.projectName)
     pathList = paths.split(";")
     if len(pathList) == 1:  # Single dir - dont bother putting the dir in
         ret = MakePathSubList(pathList[0])
     else:
         ret = list(map(HLIDirectoryItem, pathList))
     return ret
예제 #4
0
def FindPackagePath(packageName, knownFileName, searchPaths):
    """Find a package.

       Given a ni style package name, check the package is registered.

       First place looked is the registry for an existing entry.  Then
       the searchPaths are searched.
    """
    import regutil, os
    pathLook = regutil.GetRegisteredNamedPath(packageName)
    if pathLook and IsPackageDir(pathLook, packageName, knownFileName):
        return pathLook, None  # The currently registered one is good.
    # Search down the search paths.
    for pathLook in searchPaths:
        if IsPackageDir(pathLook, packageName, knownFileName):
            # Found it
            ret = os.path.abspath(pathLook)
            return ret, ret
    raise error, "The package %s can not be located" % packageName
예제 #5
0
def FindAppPath(appName, knownFileName, searchPaths):
    """Find an application.

     First place looked is the registry for an existing entry.  Then
     the searchPaths are searched.
    """
    # Look in the first path.
    import regutil, string, os
    regPath = regutil.GetRegisteredNamedPath(appName)
    if regPath:
        pathLook = regPath.split(";")[0]
    if regPath and FileExists(os.path.join(pathLook, knownFileName)):
        return None # The currently registered one is good.
    # Search down the search paths.
    for pathLook in searchPaths:
        if FileExists(os.path.join(pathLook, knownFileName)):
            # Found it
            return os.path.abspath(pathLook)
    raise error("The file %s can not be located for application %s" % (knownFileName, appName))
예제 #6
0
                RegisterShellInfo(searchPaths)
            if o == '-p':
                print "Registering package", a
                FindRegisterPackage(a, None, searchPaths)
            if o in ['--upackage', '--uapp']:
                import regutil
                print "Unregistering application/package", a
                regutil.UnregisterNamedPath(a)
            if o == '-a':
                import regutil
                path = string.join(searchPaths, ";")
                print "Registering application", a, "to path", path
                regutil.RegisterNamedPath(a, path)
            if o == '-c':
                if not len(searchPaths):
                    raise error, "-c option must provide at least one additional path"
                import win32api, regutil
                currentPaths = string.split(
                    regutil.GetRegisteredNamedPath(None), ";")
                oldLen = len(currentPaths)
                for newPath in searchPaths:
                    if newPath not in currentPaths:
                        currentPaths.append(newPath)
                if len(currentPaths) <> oldLen:
                    print "Registering %d new core paths" % (
                        len(currentPaths) - oldLen)
                    regutil.RegisterNamedPath(None,
                                              string.join(currentPaths, ";"))
                else:
                    print "All specified paths are already registered."
예제 #7
0
                print("Registering the Python core.")
                RegisterShellInfo(searchPaths)
            if o == '-p':
                print("Registering package", a)
                FindRegisterPackage(a, None, searchPaths)
            if o in ['--upackage', '--uapp']:
                import regutil
                print("Unregistering application/package", a)
                regutil.UnregisterNamedPath(a)
            if o == '-a':
                import regutil
                path = ";".join(searchPaths)
                print("Registering application", a, "to path", path)
                regutil.RegisterNamedPath(a, path)
            if o == '-c':
                if not len(searchPaths):
                    raise error(
                        "-c option must provide at least one additional path")
                import win32api, regutil
                currentPaths = regutil.GetRegisteredNamedPath(None).split(";")
                oldLen = len(currentPaths)
                for newPath in searchPaths:
                    if newPath not in currentPaths:
                        currentPaths.append(newPath)
                if len(currentPaths) != oldLen:
                    print("Registering %d new core paths" %
                          (len(currentPaths) - oldLen))
                    regutil.RegisterNamedPath(None, ";".join(currentPaths))
                else:
                    print("All specified paths are already registered.")
예제 #8
0
                print examples
            if o=='--shell':
                print "Registering the Python core."
                RegisterShellInfo(searchPaths)
            if o=='-p':
                print "Registering package", a
                FindRegisterPackage(a,None,searchPaths)
            if o in ['--upackage', '--uapp']:
                import regutil
                print "Unregistering application/package", a
                regutil.UnregisterNamedPath(a)
            if o=='-a':
                import regutil
                path = string.join(searchPaths,";")
                print "Registering application", a,"to path",path
                regutil.RegisterNamedPath(a,path)
            if o=='-c':
                if not len(searchPaths):
                    raise error, "-c option must provide at least one additional path"
                import win32api, regutil
                currentPaths = string.split(regutil.GetRegisteredNamedPath(None),";")
                oldLen = len(currentPaths)
                for newPath in searchPaths:
                    if newPath not in currentPaths:
                        currentPaths.append(newPath)
                if len(currentPaths)<>oldLen:
                    print "Registering %d new core paths" % (len(currentPaths)-oldLen)
                    regutil.RegisterNamedPath(None,string.join(currentPaths,";"))
                else:
                    print "All specified paths are already registered."