Esempio n. 1
0
def createProxyDir(sitRoot, sitProxy, verbose=True):
    """
        Creates an SIT proxy directory for the current user in the
        directory <sitProxy> with symlinks pointing into <sitRoot>.
    """
    sitRootPkgList = []

    if not os.path.isdir(sitRoot):
        msg = '%s: No such directory (please check $SIT)' % sitRoot
        raise AssertionError(msg)

    if os.path.exists(sitProxy):
        msg = '%s: Directory exists' % sitProxy
        raise AssertionError(msg)

    if os.path.exists(os.path.join(sitRoot, SIT.parentLink)):
        msg = '$SIT=%s already points to a proxy ' % sitRoot + \
              'directory (cascades are not allowed)'
        raise AssertionError(msg)

    if os.path.realpath(sitRoot) == os.path.realpath(sitProxy):
        msg = 'SIT proxy path must be different from parent SIT!'
        raise AssertionError(msg)

    SIT.getProjectsWithErrorHandling(sitRoot, sitRootPkgList)

    for package in sitRootPkgList:
        linkName = os.path.join(sitProxy, package)
        target = os.path.join(sitRoot, package)

        if verbose:
            logging.info('linking %s' % package)

        # create directory where the link shall be created
        FastScript.mkdir(os.path.dirname(linkName))

        logging.debug('linking %s --> %s', linkName, target)
        os.symlink(target, linkName)

    # create a symlink inside the proxy that points to the parent
    linkName = os.path.join(sitProxy, SIT.parentLink)
    os.symlink(sitRoot, linkName)

    logging.info('')
    logging.info('Proxy created in %s' % sitProxy)
Esempio n. 2
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)