Пример #1
0
def getFlatDependencies(canonicalPaths, cache=None, sitPath=None):
    """
        Resolves all dependencies recursively and converts them to a flat
        set of overall dependencies.

        This function might be handy to determine all SIT packages that
        need to transferred to another site.
    """
    cache = {} if cache is None else cache
    sitPath = SIT.getPath() if sitPath is None else sitPath

    Any.requireIsIterable(canonicalPaths)
    Any.requireIsDict(cache)
    Any.requireIsTextNonEmpty(sitPath)

    result = set()

    for canonicalPath in canonicalPaths:
        requireIsCanonicalPath(canonicalPath)

        result.add('sit://' + canonicalPath)

        deps = getDependencies(canonicalPath,
                               recursive=True,
                               cache=cache,
                               systemPackages=False,
                               sitPath=sitPath)

        flatDeps = FastScript.flattenList(deps)

        for item in flatDeps:
            result.add(item)

    return result
Пример #2
0
def tryImport(modules):
    """
        Checks that the provided modules can be imported.
        Stops with a message to the user if some are not found.
    """
    import importlib
    import six

    if Any.isText(modules):
        modules = [modules]

    Any.requireIsIterable(modules)

    notFound = set()

    for moduleName in modules:
        Any.requireIsTextNonEmpty(moduleName)

        if six.PY2:
            errorClass = ImportError
        else:
            errorClass = ModuleNotFoundError

        try:
            importlib.import_module(moduleName)
        except errorClass:
            notFound.add(moduleName)

    if notFound:
        raise SystemExit( 'Python module(s) not installed: %s' % \
                          ' '.join( sorted( notFound ) ) )
Пример #3
0
def _cleanDir( path, patternList, verbose, dryRun ):
    Any.requireIsText( path )
    Any.requireIsIterable( patternList )

    for pattern in patternList:
        patternFullPath = os.path.join( path, pattern )
        matchingList    = glob.glob( patternFullPath )

        if matchingList:
            _removeList( matchingList, verbose, dryRun )
Пример #4
0
def printFetchCommands(packageList, asSubModule=True):
    """
        Prints the VCS fetch command for each package in the list.
        Duplicates will be removed, and output will be sorted for better
        readability, e.g.:

        asSubModule = True:
            git submodule add [email protected]:TECH_Team/BPL.git
            git submodule add [email protected]:ToolBOS/BasicComponents.git
            git submodule add [email protected]:ToolBOS/ToolBOSLib.git

        asSubModule = False:
            git clone [email protected]:TECH_Team/BPL.git
            git clone [email protected]:ToolBOS/BasicComponents.git
            git clone [email protected]:ToolBOS/ToolBOSLib.git
    """
    Any.requireIsIterable(packageList)
    Any.requireIsBool(asSubModule)

    sitRootPath = SIT.getRootPath()
    commands = set()  # avoids duplicates

    for canonicalPath in packageList:
        ProjectProperties.requireIsCanonicalPath(canonicalPath)

        installRoot = os.path.join(sitRootPath, canonicalPath)
        Any.requireIsExisting(installRoot)

        detector = PackageDetector.PackageDetector(installRoot)
        detector.retrieveMetaInfoFromSIT()

        vcsRoot = detector.vcsRoot

        if vcsRoot:
            Any.requireIsTextNonEmpty(vcsRoot)
            repo = VersionControl.auto(vcsRoot)

            if isinstance(repo, SVN.SVNRepository):
                repo.setConfiguredUserName()
                command = repo.getSourceCodeCommand()

            elif isinstance(repo, Git.RemoteGitRepository):
                command = repo.getSourceCodeCommand(asSubModule)

            else:
                raise TypeError('unexpected datatype: %s', type(repo))

        else:
            command = '# VCS location unknown: %s' % canonicalPath

        commands.add(command)

    for command in sorted(commands):
        print(command)
Пример #5
0
    def addPackages(self, packageList):
        Any.requireIsIterable(packageList)

        self._packageList.extend(packageList)
Пример #6
0
    def _setupOptOut(self):
        Any.requireIsIterable(self.details.sqOptOutRules)

        for ruleID in self.details.sqOptOutRules:
            logging.debug('%6s: disabled (opt-out via pkgInfo.py)', ruleID)
Пример #7
0
    def _setupOptIn(self):
        Any.requireIsIterable(self.details.sqOptInRules)

        for ruleID in self.details.sqOptInRules:
            logging.debug('%6s: enabled (opt-in via pkgInfo.py)', ruleID)
            self.includeRule(ruleID)