Exemplo n.º 1
0
    def test_findProxyInstallations(self):
        # check if user has a valid proxy:
        sitRootPath = SIT.getParentPath()
        sitProxyPath = SIT.getPath()

        Any.requireIsDir(sitRootPath)
        Any.requireIsDir(sitProxyPath)
        ProxyDir.requireIsProxyDir(sitProxyPath)

        # create a fake package directory within the proxy...
        packageName = 'UnittestABCDEF123'
        goodNameDir = os.path.join(sitProxyPath, 'Libraries', packageName)
        goodVersionDir = os.path.join(goodNameDir, '42.0')
        badVersionDir = os.path.join(goodNameDir, '21.0')
        FastScript.mkdir(goodVersionDir)

        resultList = ProxyDir.findProxyInstallations()
        self.assertTrue(
            len(resultList) >= 1
        )  # may be greater if developer has real software installed in proxy

        self.assertTrue(goodVersionDir in resultList)
        self.assertFalse(badVersionDir in resultList)

        # clean-up
        FastScript.remove(goodNameDir)
Exemplo n.º 2
0
def findProxyInstallations(checkLinks=False):
    """
        Returns a list of packages installed within the proxy SIT.

        A ValueError will be raised if the current SIT is not a proxy.

        If 'checkLinks' == True, each version symlink will also be tested
        if it really points into the root SIT. For example, it might be
        difficult to localize a manually changed link that points e.g. in
        another group proxy or so.
    """
    resultList = []
    sit = SIT.getPath()
    sitParent = SIT.getParentPath()  # support cascaded proxies
    excludePattern = re.compile('^(parentTree|\d+\.\d+.*)$')
    criteria = re.compile("^(\d+)\.(\d+)(.*)")

    Any.requireIsDir(sit)
    Any.requireIsDir(sitParent)
    requireIsProxyDir(sit)

    # find all entries within the proxy that seem to be a version number
    dirList = FastScript.getDirsInDirRecursive(
        sit,
        excludePattern=excludePattern,
        onError=FastScript.printPermissionDenied)

    # check each found entry if it is a version directory, if so we
    # can expect that this is a local project installation
    for project in dirList:
        for entry in os.listdir(project):
            joinedPath = os.path.join(project, entry)

            # only perform test on version numbers
            if criteria.search(entry):

                # don't use os.path.isdir() as it follows symlinks!
                fileType = os.lstat(joinedPath).st_mode

                if checkLinks == True and stat.S_ISLNK(fileType) == True:
                    # test if symlink points into root SIT
                    target = os.readlink(joinedPath)

                    if target[0] == '/' and not target.startswith(sitParent):
                        logging.warning(joinedPath + ': points to ' + target)

                elif stat.S_ISDIR(fileType):
                    # we found a proxy installation
                    resultList.append(joinedPath)

    return resultList
Exemplo n.º 3
0
def updateProxyDir(removeBrokenSymlinks=True,
                   removeEmptyCategories=True,
                   linkNewPackagesIntoProxy=True,
                   checkProxyLinkTarget=True,
                   checkProxyLinkedVersion=True,
                   removeProxyInstallations=False,
                   cleanHomeDirectory=True,
                   updateRTMapsIndex=True,
                   dryRun=False):
    """
        Updates the SIT proxy directory of the current user.

        The user may influence which worker functions shall be called
        (default: all)

          removeBrokenSymlinks:     remove broken symlinks to uninstalled
                                    packages

          removeEmptyCategories:    remove SIT categories that became empty,
                                    or packages without any version

          linkNewPackagesIntoProxy: if there are new packages in the global
                                    SIT, add a link to them into the proxy

          checkProxyLinkTarget:     verify that links are valid

          checkProxyLinkedVersion:  if there is a higher revision globally
                                    installed (e.g. 1.0.100) and the user
                                    has a link 1.0 pointing to 1.0.99 in the
                                    proxy, the 1.0 link will get updated to
                                    1.0.100 in order not to use an outdated
                                    revision

          removeProxyInstallations: DELETE ALL PACKAGES installed in the
                                    proxy (if any)

          cleanHomeDirectory:       clean-up unused files under ~/.HRI

          updateRTMapsIndex:        update *.pck symlinks in ~/.HRI/RTMaps

        If dryRun=True, nothing will actually be done.
    """
    from ToolBOSCore.Tools import RTMaps

    sitRoot = SIT.getParentPath()
    sitProxy = SIT.getPath()
    proxyChanged = False
    sitRootPkgList = []
    sitProxyPkgList = []
    pluginsEnabled = []

    Any.requireIsBool(removeBrokenSymlinks)
    Any.requireIsBool(removeEmptyCategories)
    Any.requireIsBool(linkNewPackagesIntoProxy)
    Any.requireIsBool(checkProxyLinkTarget)
    Any.requireIsBool(checkProxyLinkedVersion)
    Any.requireIsBool(removeProxyInstallations)
    Any.requireIsBool(cleanHomeDirectory)
    Any.requireIsBool(updateRTMapsIndex)
    Any.requireIsBool(dryRun)

    Any.requireMsg(sitRoot != sitProxy,
                   '%s: Is not a proxy directory' % sitProxy)

    # TBCORE-466: user should be able to disable particular plugins

    #if removeProxyInstallations:               # added later, see below
    #pluginsEnabled.append( _removeProxyInstallations )

    if removeBrokenSymlinks:
        pluginsEnabled.append(_removeBrokenSymlinks)

    if removeEmptyCategories:
        pluginsEnabled.append(_removeEmptyCategories)

    if linkNewPackagesIntoProxy:
        pluginsEnabled.append(_linkNewPackagesIntoProxy)

    if checkProxyLinkTarget:
        pluginsEnabled.append(_checkProxyLinkTarget)

    if checkProxyLinkedVersion:
        pluginsEnabled.append(_checkProxyLinkedVersion)

    if cleanHomeDirectory:
        pluginsEnabled.append(_cleanHomeDirectory)

    if not pluginsEnabled:
        raise ValueError('Nothing to do. Please check your parameters.')

    # in any case, after updating the proxy verify that there are no legacy
    # *.def files laying around
    pluginsEnabled.append(_checkDefFiles)

    tp = ThreadPool.ThreadPool()

    tp.add(SIT.getProjectsWithErrorHandling, sitRoot, sitRootPkgList)
    tp.add(SIT.getProjectsWithErrorHandling, sitProxy, sitProxyPkgList)

    tp.run()

    if removeProxyInstallations:
        changed = _removeProxyInstallations(sitRootPkgList, sitProxyPkgList,
                                            sitRoot, sitProxy, dryRun)

        if changed > 0:
            sitProxyPkgList = []
            SIT.getProjectsWithErrorHandling(sitProxy, sitProxyPkgList)

    for func in pluginsEnabled:
        proxyChanged |= func(sitRootPkgList, sitProxyPkgList, sitRoot,
                             sitProxy, dryRun)

    if updateRTMapsIndex:
        if RTMaps.isInstalled(sitRoot):
            RTMaps.updateComponentIndex(sitRoot, sitProxy, dryRun)
        else:
            logging.debug('RTMaps not installed')

    msg = 'Your proxy is up-to-date%s.' % (' now'
                                           if proxyChanged == True else '')
    logging.info('')
    logging.info(msg)