def rootDirectories(): # this function should return all currently set blueprint directories rootDirs = {utils.normalisePath(CraftStandardDirs.craftRepositoryDir())} if ("Blueprints", "Locations") in craftSettings: for path in craftSettings.getList("Blueprints", "Locations"): rootDirs.add(utils.normalisePath(path)) if os.path.isdir(CraftStandardDirs.blueprintRoot()): for f in os.listdir(CraftStandardDirs.blueprintRoot()): rootDirs.add(utils.normalisePath(os.path.join(CraftStandardDirs.blueprintRoot(), f))) return list(rootDirs)
def rootDirectories(): # this function should return all currently set blueprint directories if not CraftPackageObject.__rootDirectories: rootDirs = {utils.normalisePath(CraftStandardDirs.craftRepositoryDir())} if ("Blueprints", "Locations") in CraftCore.settings: for path in CraftCore.settings.getList("Blueprints", "Locations"): rootDirs.add(utils.normalisePath(path)) if os.path.isdir(CraftStandardDirs.blueprintRoot()): for f in os.listdir(CraftStandardDirs.blueprintRoot()): if CraftPackageObject._isDirIgnored(f): continue rootDirs.add(utils.normalisePath(os.path.join(CraftStandardDirs.blueprintRoot(), f))) CraftCore.log.debug(f"Craft BlueprintLocations: {rootDirs}") CraftPackageObject.__rootDirectories = list(rootDirs) return CraftPackageObject.__rootDirectories
def root(): if not CraftPackageObject.__rootPackage: CraftPackageObject.__rootPackage = root = CraftPackageObject() root.name = "/" for blueprintRoot in CraftPackageObject.rootDirectories(): if not os.path.isdir(blueprintRoot): CraftCore.log.warning(f"{blueprintRoot} does not exist") continue blueprintRoot = utils.normalisePath( os.path.abspath(blueprintRoot)) # create a dummy package to load its children child = CraftPackageObject._expandChildren( None, root, blueprintRoot) root.children.update(child.children) CraftPackageObject.__regiserNodes(root) return CraftPackageObject.__rootPackage
def root(): if not CraftPackageObject.__rootPackage: if ("Blueprints", "Ignores") in craftSettings: CraftPackageObject.Ignores = re.compile("|".join([f"^{entry}$" for entry in craftSettings.get("Blueprints", "Ignores").split(";")])) CraftPackageObject.__rootPackage = root = CraftPackageObject() root.path = "/" for blueprintRoot in CraftPackageObject.rootDirectories(): if not os.path.isdir(blueprintRoot): craftDebug.log.warning(f"{blueprintRoot} does not exist") continue blueprintRoot = utils.normalisePath(os.path.abspath(blueprintRoot)) # create a dummy package to load its children child = root._addNode(None, blueprintRoot) root.children.update(child.children) return CraftPackageObject.__rootPackage
def _addNode(self, path, blueprintRoot): package = CraftPackageObject() if path: path = utils.normalisePath(path) package.path = path[len(blueprintRoot) + 1:] elif blueprintRoot: path = blueprintRoot else: return None for f in os.listdir(path): fPath = os.path.abspath(os.path.join(path, f)) if os.path.isdir(fPath): if f not in CraftPackageObject.IgnoredDirectories: hasChildren = True child = self._addNode(fPath, blueprintRoot) if child: package.children[child.name] = child elif f.endswith(".py"): if package.source: raise BlueprintException(f"Multiple py files in one directory: {package.source} and {f}", package) if f[:-3] != package.name: raise BlueprintException(f"Recipes must match the name of the directory: {fPath}", package) recipe = os.path.splitext(f)[0] if recipe not in CraftPackageObject._recipes: CraftPackageObject._recipes[recipe] = [] CraftPackageObject._recipes[recipe].append(package) package.source = fPath if package.children: if package.source: raise BlueprintException(f"{package} has has children but also a recipe {package.source}!", package) if path != blueprintRoot: if not package.source and not package.children: craftDebug.log.warning(f"Found an dead branch in {blueprintRoot}/{package.path}\n" f"You might wan't to run \"git clean -xdf\" in that directry.") return None if package.path in CraftPackageObject._nodes: existingNode = CraftPackageObject._nodes[package.path] if not existingNode.isCategory(): raise BlueprintException( f"Found a recipe clash {existingNode.source} and {blueprintRoot}/{package.path}", existingNode) package = existingNode else: CraftPackageObject._nodes[package.path] = package return package
def _expandChildren(path, parent, blueprintRoot): if path: path = utils.normalisePath(path) name = path.rsplit("/", 1)[-1] if name in parent.children: package = parent.children[name] else: package = CraftPackageObject(name, parent) package.filePath = path elif blueprintRoot: path = blueprintRoot package = parent else: raise Exception("Unreachable") package.__blueprintRoot = blueprintRoot if not package.categoryInfo: package.categoryInfo = CategoryPackageObject(path) if not package.categoryInfo.valid and package.parent: if package.parent.__blueprintRoot == package.__blueprintRoot: # we actually need a copy package.categoryInfo = copy.copy( package.parent.categoryInfo) if not package.categoryInfo.valid: package.categoryInfo = CategoryPackageObject( blueprintRoot) for f in os.listdir(path): fPath = os.path.abspath(os.path.join(path, f)) if os.path.isdir(fPath): if not CraftPackageObject._isDirIgnored(f): child = CraftPackageObject._expandChildren( fPath, package, blueprintRoot) if child: if f in package.children: existingNode = package.children[f] if not existingNode.isCategory(): CraftCore.log.warning( f"Blueprint clash detected: Ignoring {child.source} in favour of {existingNode.source}" ) continue else: #merge with existing node existingNode.children.update(child.children) else: package.children[f] = child elif f.endswith(".py"): if package.source: raise BlueprintException( f"Multiple py files in one directory: {package.source} and {f}", package) if f[:-3] != package.name: raise BlueprintException( f"Recipes must match the name of the directory: {fPath}", package) package.source = fPath CraftPackageObject._allLeaves[package.path] = package if package.children and package.source: raise BlueprintException( f"{package} has has children but also a recipe {package.source}!", package) if path != blueprintRoot: if not package.source and not package.children: if os.listdir(path) in [["__pycache__"], []]: # the recipe was removed utils.rmtree(path) else: CraftCore.log.warning( f"Found an dead branch in {blueprintRoot}/{package.path}\n" f"You might wan't to run \"git clean -xdf\" in that directry." ) return None return package
def _expandChildren(path, parent, blueprintRoot): if path: path = utils.normalisePath(path) name = path.rsplit("/", 1)[-1] if name in parent.children: package = parent.children[name] else: package = CraftPackageObject(name, parent) elif blueprintRoot: path = blueprintRoot package = parent else: return None for f in os.listdir(path): fPath = os.path.abspath(os.path.join(path, f)) if os.path.isdir(fPath): if not CraftPackageObject._isDirIgnored(f): hasChildren = True child = CraftPackageObject._expandChildren( fPath, package, blueprintRoot) if child: if f in package.children: existingNode = package.children[f] if not existingNode.isCategory(): CraftCore.log.warning( f"Blueprint clash detected: Ignoring {child.source} in favour of {existingNode.source}" ) continue else: #merge with existing node existingNode.children.update(child.children) continue package.children[f] = child elif f.endswith(".py"): if package.source: raise BlueprintException( f"Multiple py files in one directory: {package.source} and {f}", package) if f[:-3] != package.name: raise BlueprintException( f"Recipes must match the name of the directory: {fPath}", package) package.source = fPath if package.children: if package.source: raise BlueprintException( f"{package} has has children but also a recipe {package.source}!", package) else: catInfo = CategoryPackageObject(path) if not catInfo.isActive: CraftCore.log.debug( f"Skipping {package.path}, it's not supported on {CraftCore.compiler.platform}" ) return None if path != blueprintRoot: if not package.source and not package.children: if os.listdir(path) in [["__pycache__"], []]: # the recipe was removed utils.rmtree(path) else: CraftCore.log.warning( f"Found an dead branch in {blueprintRoot}/{package.path}\n" f"You might wan't to run \"git clean -xdf\" in that directry." ) return None return package