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
def getProjects(path, keepPath=True, onError=None): """ Recursively searches for projects installed in the specified directory. If 'keepPath' is True, the specified "path" will be part of the strings returned. If False, only the part of the path behind 'path' will be returned, e.g.: getProjects( '/hri/sit/latest' ) True: [ '/hri/sit/latest/Libraries/Serialize/3.0', ... ] False: [ 'Libraries/Serialize/3.0', ... ] You may pass a function callback that will be called upon errors, e.g. permission denied. This function needs to take a single path parameter. If omitted, an OSError will be raised upon errors. """ Any.requireIsDir(path) path = os.path.normpath(path) projectList = [] excludePattern = re.compile("(parentTree|^\d+\.\d+)|.svn") criteria = re.compile("^(\d+)\.(\d+)(.*)") for directory in FastScript.getDirsInDirRecursive(path, excludePattern, onError=onError): for subDir in FastScript.getDirsInDir(directory, onError=FastScript.ignore): if keepPath: pathToAdd = os.path.join(directory, subDir) else: pathToAdd = os.path.join(directory.replace(path + '/', ''), subDir) if criteria.search(subDir): projectList.append(pathToAdd) return projectList
def _distclean_inTree( self ): from ToolBOSCore.Storage import VersionControl requireTopLevelDir( os.getcwd() ) excludeSVN = re.compile( '.svn' ) subDirList = FastScript.getDirsInDirRecursive( excludePattern=excludeSVN ) subDirList.append( '.' ) # do not cache those variables as their change would not be reflected # in such case (interactive sessions will continue to use the value # as it was at module loading time) verbose = True if os.getenv( 'VERBOSE' ) == 'TRUE' else False dryRun = True if os.getenv( 'DRY_RUN' ) == 'TRUE' else False patternList = _getDistcleanPatterns() for subDir in subDirList: _cleanDir( subDir, patternList, verbose, dryRun ) # specifically check for empty directories (mind the ".svn"): for candidate in ( 'doc', 'install', 'lib', 'obj' ): if os.path.isdir( candidate ): content = os.listdir( candidate ) if not content: FastScript.remove( candidate ) # does not contain ".svn" elif content == [ '.svn' ]: # With recent versions of SVN there are no more ".svn" # directories in all the various paths, instead of a # single one in top-level directory. Therefore most # likely this code is dead. try: vcs = VersionControl.auto() vcs.remove( candidate ) except subprocess.CalledProcessError: pass # keep it (safety first) return True
def execInAllProjects(command): Any.requireIsTextNonEmpty(command) # determine list of packages (and versions) to visit dirList = [] oldcwd = os.getcwd() if listfile: Any.requireIsFileNonEmpty(listfile) # read subdirectories from file, and remove trailing newlines dirList = FastScript.getFileContent(listfile, splitLines=True) dirList = map(str.strip, dirList) else: noSVN = re.compile("^.svn$") for path in FastScript.getDirsInDirRecursive(excludePattern=noSVN): if os.path.isfile(os.path.join(path, 'CMakeLists.txt')): dirList.append(path) # execute the task for entry in dirList: workingDir = os.path.realpath(os.path.join(oldcwd, entry)) logging.debug('cd %s' % workingDir) logging.info('workingDir=%s', workingDir) FastScript.changeDirectory(workingDir) try: FastScript.execProgram(command) except subprocess.CalledProcessError as e: if ignoreErrors: logging.warning(e) else: raise FastScript.changeDirectory(oldcwd)