def updateComponentIndex(sitRootPath, sitProxyPath, dryRun): """ Cleans the index directory and creates all symlinks from scratch. """ Any.requireIsDir(sitRootPath) Any.requireIsDir(sitProxyPath) Any.requireIsBool(dryRun) ProxyDir.requireIsProxyDir(sitProxyPath) indexBaseDir = getIndexBaseDir(sitProxyPath) # We would like to start with a fresh indexBaseDir, however cannot delete # it because it also contains the DTBOS *.def files. Hence we only remove # subdirectories (corresponding to the RTMaps versions) within this # directories and keep *.def files as they are. See TBCORE-974). # #FastScript.remove( indexBaseDir ) for subDir in FastScript.getDirsInDir(indexBaseDir): path = os.path.join(indexBaseDir, subDir) FastScript.remove(path) for version in getVersionsAvailable(sitRootPath): dstDir = os.path.join(indexBaseDir, version) logging.debug('mkdir %s', dstDir) if not dryRun: FastScript.mkdir(dstDir) logging.debug('updating RTMaps component index...') registerDistributionPackages(sitRootPath, sitProxyPath, dryRun) registerNormalPackages(sitRootPath, dryRun) registerNormalPackages(sitProxyPath, dryRun)
def getVersionsAvailable(sitRootPath): """ Returns a list of strings with the RTMaps versions installed in the specified SIT, e.g. ['4.20', '4.21'] """ Any.requireIsDir(sitRootPath) installBaseDir = os.path.join(sitRootPath, 'External', 'RTMaps') Any.requireIsDirNonEmpty(installBaseDir) resultList = FastScript.getDirsInDir(installBaseDir) Any.requireIsListNonEmpty(resultList) 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 getPackageVersions(project, includePatchlevelVersions=False): """ Returns all installed versions of a project. This returns only the versions in the form "Major.Minor". Setting 'includePatchlevelVersions=True' will return all, e.g. those in the form "Major.Minor.Patchlevel" or "Major.Minor-ExtraTag". """ Any.requireIsDir(project) allVersionsList = FastScript.getDirsInDir(project) resultList = [] if includePatchlevelVersions: resultList = allVersionsList else: for version in allVersionsList: if re.match("^\d+\.\d+$", version): resultList.append(version) return resultList
def findFile(fileName): """ Tries to find a file called <fileName> somewhere below the directory named 'path'. If none is found, an IOError will be raised. If multiple files would be present (e.g. within multiple versions of the package), only the first one is returned. However, most likely at module import time there shouldn't be so many parallel versions, yet. And additionally, the package's SIT category most often does not change. """ for subdir in FastScript.getDirsInDir(os.getcwd()): filePath = os.path.join(subdir, fileName) if os.path.exists(filePath): logging.debug('probing for %s: found', filePath) return filePath else: logging.debug('probing for %s: Not found', filePath) raise IOError('No %s found' % fileName)
def createLocalProject(klocworkDir='klocwork', stdout=None, stderr=None): """ Creates a local .kwlp directory so that the analysis can be performed. @Retuns: nothing. Throws an RuntimeError in case of problems. """ Any.requireIsTextNonEmpty(klocworkDir) requireOutsideTmpDir() kwPackage = ToolBOSSettings.getConfigOption('package_klocwork') buildSpec = os.path.join(klocworkDir, 'kwinject.out') kwlpDir = os.path.join(klocworkDir, '.kwlp') # KW local project kwpsDir = os.path.join(klocworkDir, '.kwps') # KW project settings hostPlatform = Platforms.getHostPlatform() licenseServerHost = ToolBOSSettings.getConfigOption('kwLicenseServerHost') licenseServerPort = ToolBOSSettings.getConfigOption('kwLicenseServerPort') Any.requireIsTextNonEmpty(kwPackage) Any.requireIsTextNonEmpty(hostPlatform) ProcessEnv.source(kwPackage) FastScript.mkdir(klocworkDir) # ensure this exists FastScript.remove(kwlpDir) # but those should not exist FastScript.remove(kwpsDir) # but those should not exist if ProcessEnv.which('kwinject') is None: msg = '%s not installed for platform=%s' % (kwPackage, hostPlatform) raise EnvironmentError(msg) # inspect the build process to capture source files, defines, flags,... cmd = 'kwinject -o %s %s' % (buildSpec, 'BST.py -sb') FastScript.execProgram(cmd, stdout=stdout, stderr=stderr) Any.requireIsFileNonEmpty(buildSpec) # create Klocwork project directory cmd = 'kwcheck create --license-host %s --license-port %d -pd %s -sd %s %s' % \ ( licenseServerHost, licenseServerPort, kwlpDir, kwpsDir, buildSpec ) FastScript.execProgram(cmd, stdout=stdout, stderr=stderr) Any.requireIsDir(kwlpDir) Any.requireIsDir(kwpsDir) # import the build specification into project directory cmd = 'kwcheck import -pd %s %s' % (kwlpDir, buildSpec) FastScript.execProgram(cmd, stdout=stdout, stderr=stderr) # install the HIS-Subset taxonomy so that the user may select it tcRoot = FastScript.getEnv('TOOLBOSCORE_ROOT') fileName = 'HIS_Subset_MISRA_C_1.0.2.tconf' srcFile = os.path.join(tcRoot, 'external/emenda.com', fileName) dstDir = os.path.join(kwpsDir, 'servercache') dstFile = os.path.join(dstDir, fileName) Any.requireIsFileNonEmpty(srcFile) FastScript.mkdir(dstDir) FastScript.copy(srcFile, dstFile) # auto-detect source code directories (exclude some blacklisted ones) dirList = [] cwd = os.getcwd() for dirName in FastScript.getDirsInDir(): if dirName not in ('build', 'doc', 'external', 'lib'): dirList.append(os.path.join(cwd, dirName)) # create workingset values = {'dirList': dirList} creator = PackageCreator.PackageCreator('dummy', '1.0', values) srcDir = os.path.join(creator.templateDir, 'KlocworkProject') dstDir = kwlpDir creator.templatize(os.path.join(srcDir, 'workingsets.xml'), os.path.join(dstDir, 'workingsets.xml'))