def _ValidateName(self, xmlElement: ET.Element, name: str) -> None: allowSubPackages = self.SystemSubPackageSupport.AllowSubPackages # type: bool if not Util.IsValidPackageName(name, allowSubPackages): if allowSubPackages and name.find('..') >= 0: raise XmlUnsupportedSubPackageNameException(xmlElement, name) else: raise XmlUnsupportedPackageNameException(xmlElement, name)
def __init__(self, name: str, smartName: str, baseName: UnresolvedPackageName, flavorSelections: PackageFlavorSelections) -> None: super().__init__() if not Util.IsValidPackageName(name): raise InvalidPackageNameException(name) self.Value = name self.SmartValue = smartName self.Unresolved = baseName self.FlavorSelections = flavorSelections
def AddNew(self, packageName: str, packageProjectId: str) -> None: if not Util.IsValidPackageName(packageName): raise InvalidPackageNameException(packageName) if packageProjectId in self.__projectIdToNameDict: raise Exception( "Package '{0}' uses project id '{1}' already used by package: '{2}'" .format(packageName, packageProjectId, self.__projectIdToNameDict[packageProjectId])) if packageName in self.__projectIdCache.ProjectIdDict: raise Exception("Package '{0}' already added".format(packageName)) self.__projectIdCache.Add(packageName, packageProjectId) self.__projectIdToNameDict[packageProjectId] = packageName
def __init__(self, projectIdDict: Dict[str, str]) -> None: super().__init__() self.Version = JsonProjectIdCache.CURRENT_VERSION self.ProjectIdDict = projectIdDict projectIdToNameDict = {} # type: Dict[str, str] for packageName, packageProjectId in projectIdToNameDict.items(): if not Util.IsValidPackageName(packageName): raise InvalidPackageNameException(packageName) if packageProjectId in projectIdDict: raise Exception( "The package project id '{0}' is registered for multiple package names. First '{1}' Second '{2}'" .format(packageProjectId, projectIdToNameDict[packageName], packageName)) projectIdToNameDict[packageProjectId] = packageName
def Add(self, packageName: str, packageProjectId: str) -> None: if not Util.IsValidPackageName(packageName): raise InvalidPackageNameException(packageName) self.ProjectIdDict[packageName] = packageProjectId
def __CacheLocation(self, rScannedPathsCacheSet: Set[str], rLocationDict: Dict[str, PackageLocationCacheRecord], locationPackageName: str, sourcePath: str, scanMethod: int, sourceLocation: ToolConfigPackageLocation, rNewLocations: Optional[List[PackageLocationCachePath]] = None) -> None: # if rNewLocations is not None all new locations we find will be added to this list # Prevent multiple scannings of the same path if sourcePath in rScannedPathsCacheSet: return rScannedPathsCacheSet.add(sourcePath) directories = IOUtil.GetDirectoriesAt(sourcePath, False) directories.sort() for dirEntry in directories: if not Util.IsValidPackageName(dirEntry, True): if self.Log.Verbosity >= 4: self.Log.LogPrint("Ignored directory '{0}' at '{1}' as it was not a valid package name".format(dirEntry, IOUtil.Join(sourcePath, dirEntry))) continue absoluteDirPath = IOUtil.Join(sourcePath, dirEntry) if absoluteDirPath in self.__RootLocationPaths: if self.Log.Verbosity >= g_verbosityMaxLevel: self.Log.LogPrint("Not scanning '{0}' as a child of '{1}' since it is a root location".format(absoluteDirPath, sourceLocation.ResolvedPath)) continue if self.__IsBlacklisted(absoluteDirPath, sourceLocation.Blacklist): if self.Log.Verbosity >= g_verbosityMaxLevel: self.Log.LogPrint("Not scanning '{0}' as it was blacklisted".format(absoluteDirPath)) continue # This is not a original location path, so we can cache it as a 'child' of this location directoryLocationPackageName = locationPackageName + dirEntry absoluteDirPackageFilename = IOUtil.Join(absoluteDirPath, self.__GenFilename) foundPackageFilePath = absoluteDirPackageFilename if IOUtil.IsFile(absoluteDirPackageFilename) else None newLocationRecord = PackageLocationCachePath(directoryLocationPackageName, absoluteDirPath, foundPackageFilePath, sourceLocation) if directoryLocationPackageName not in rLocationDict: newRecord = PackageLocationCacheRecord(directoryLocationPackageName) rLocationDict[directoryLocationPackageName] = newRecord if self.Log.Verbosity >= g_verbosityMaxLevel: if foundPackageFilePath is None: self.Log.LogPrint("- Cached '{0}' at '{1}'".format(directoryLocationPackageName, absoluteDirPath)) else: self.Log.LogPrint("- Cached '{0}' at '{1}', found package here.".format(directoryLocationPackageName, absoluteDirPath)) elif self.Log.Verbosity >= g_verbosityMaxLevel: if foundPackageFilePath is None: self.Log.LogPrint("- Cached alias to '{0}' at '{1}'".format(directoryLocationPackageName, absoluteDirPath)) else: self.Log.LogPrint("- Cached alias to '{0}' at '{1}', found package here.".format(directoryLocationPackageName, absoluteDirPath)) cacheRecord = rLocationDict[directoryLocationPackageName] cacheRecord.Append(newLocationRecord) if rNewLocations is not None: rNewLocations.append(newLocationRecord) if scanMethod == ScanMethod.Directory: # we already scanned the directory, so do nothing pass elif scanMethod == ScanMethod.OneSubDirectory: newLocationPackageName = directoryLocationPackageName + "." self.__CacheLocation(rScannedPathsCacheSet, rLocationDict, newLocationPackageName, absoluteDirPath, ScanMethod.Directory, sourceLocation, rNewLocations) elif scanMethod == ScanMethod.AllSubDirectories: newLocationPackageName = directoryLocationPackageName + "." self.__CacheLocation(rScannedPathsCacheSet, rLocationDict, newLocationPackageName, absoluteDirPath, ScanMethod.AllSubDirectories, sourceLocation, rNewLocations) else: raise Exception("Unsupported ScanMethod {0}".format(ScanMethod.TryToString(scanMethod, True)))