def updateInstalled(args) -> bool: package = CraftPackageObject(None) for packageName, _ in CraftCore.installdb.getDistinctInstalled(): p = CraftPackageObject.get(packageName) if p: package.children[p.name] = p return run(package, "all", args)
def upgrade(packages, args) -> bool: if packages.children: deps = CraftDependencyPackage(packages) else: deps = CraftDependencyPackage(CraftPackageObject(None)) for packageName, _, _ in CraftCore.installdb.getDistinctInstalled(): p = CraftPackageObject.get(packageName) # package in the db might have been renamed and has no blueprint anymore if p: deps.children[p.path] = p.path packageList = deps.getDependencies() return __recurseCraft( [], ["-i", "--options", "virtual.ignored=True", "craft" ]) and __recurseCraft(["--update"], [x.path for x in packageList])
def __readDependenciesForChildren(self, deps: [(str, str)]) -> []: children = [] if deps: for packaheName, requiredVersion in deps: if (packaheName, self.depenendencyType ) not in CraftDependencyPackage._packageCache: package = CraftPackageObject.get(packaheName) if not package: raise BlueprintException( f"Failed to resolve {packaheName} as a dependency of {self}", self) if requiredVersion and requiredVersion != None and CraftVersion( package.version) < CraftVersion(requiredVersion): raise BlueprintException( f"{self} requries {package} version {requiredVersion!r} but {package.version!r} is installed", self) p = CraftDependencyPackage(package) CraftCore.log.debug(f"adding package {packaheName}") CraftDependencyPackage._packageCache[( packaheName, self.depenendencyType)] = p p.depenendencyType = self.depenendencyType else: p = CraftDependencyPackage._packageCache[( packaheName, self.depenendencyType)] children.append(p) return children
def resolvePackage(packageNames : [str], version : str=None) -> [CraftPackageObject]: package = CraftPackageObject(None) def resolveChildren(child): if child.isCategory(): for c in child.children.values(): resolveChildren(c) else: if version: UserOptions.addPackageOption(child, "version", version) package.children[child.name] = child for packageName in packageNames: child = CraftPackageObject.get(packageName) if not child: raise BlueprintNotFoundException(packageName) resolveChildren(child) return package
def upgrade(args, argv=None) -> bool: ENV_KEY = "CRAFT_CORE_UPDATED" if ENV_KEY not in os.environ: if argv is None: argv = sys.argv[1:] os.environ[ENV_KEY] = "1" # update the core if not run(CraftPackageObject.get("craft"), "all", args): return False return __recurseCraft([], argv) else: package = CraftPackageObject(None) for packageName, _, _ in CraftCore.installdb.getDistinctInstalled(): p = CraftPackageObject.get(packageName) if p: package.children[p.name] = p return run(package, "update", args)
def updateInstalled(args) -> bool: ENV_KEY = "CRAFT_CORE_UPDATED" if ENV_KEY not in os.environ: os.environ[ENV_KEY] = "1" # update the core if not run(CraftPackageObject.get("craft"), "all", args): return False # close the log file and the db CraftTitleUpdater.instance.stop() CraftCore.debug._fileHandler.close() del CraftCore.installdb return subprocess.call([sys.executable] + sys.argv) == 0 else: package = CraftPackageObject(None) for packageName, _ in CraftCore.installdb.getDistinctInstalled(): p = CraftPackageObject.get(packageName) if p: package.children[p.name] = p return run(package, "all", args)
def upgrade(packages, args) -> bool: packageList = set() for packageName, _, _ in CraftCore.installdb.getDistinctInstalled(): p = CraftPackageObject.get(packageName) # package in the db might have been renamed and has no blueprint anymore if p: packageList.add(p) # only packages that are part of the selection if packages.children: packageList = packageList.intersection(set(packages.children.values())) return __recurseCraft([], ["craft"]) and __recurseCraft(["--update"], list(packageList))
def __readDependenciesForChildren(self, deps): children = [] if deps: for line in deps: if line not in CraftDependencyPackage._packageCache: p = CraftDependencyPackage(CraftPackageObject.get(line)) craftDebug.log.debug(f"adding package {line}") CraftDependencyPackage._packageCache[line] = p else: p = CraftDependencyPackage._packageCache[line] p.depenendencyType = self.depenendencyType children.append(p) return children
def setTargets(self): self.svnTargets[ "master"] = "https://code.qt.io/qt-creator/qt-creator.git" for ver in ["4.10.1"]: majorVer = ".".join(ver.split(".")[:2]) self.targets[ ver] = f"http://download.qt.io/official_releases/qtcreator/{majorVer}/{ver}/qt-creator-opensource-src-{ver}.tar.xz" self.targetInstSrc[ver] = f"qt-creator-opensource-src-{ver}" self.targetDigestUrls[ ver] = f"https://download.qt.io/official_releases/qtcreator/{majorVer}/{ver}/qt-creator-opensource-src-{ver}.tar.xz.sha256" if CraftPackageObject.get("libs/llvm-meta/llvm").version == "9.0.0": self.patchToApply["4.10.1"] = [("qtcreator-4.10.1-20191017.diff", 1)] self.defaultTarget = "4.10.1"
def __readDependenciesForChildren(self, deps: [(str, str)]) -> []: children = [] if deps: for packaheName, requiredVersion in deps: if (packaheName, self.depenendencyType ) not in CraftDependencyPackage._packageCache: package = CraftPackageObject.get(packaheName) if not package: raise BlueprintException( f"Failed to resolve {packaheName} as a dependency of {self}", self) if isinstance(requiredVersion, tuple): requiredVersion, type = requiredVersion if type == DependencyRequirementType.Required: if not bool(package.categoryInfo.compiler & CraftCore.compiler.compiler): raise BlueprintException( f"{self} requries {package}, but it is not supported on {CraftCore.compiler.compiler}", self) if not bool(package.categoryInfo.platforms & CraftCore.compiler.platform): raise BlueprintException( f"{self} requries {package}, but it is not supported on {CraftCore.compiler.platform}", self) if package.isIgnored() or isinstance( package.instance, VirtualPackageBase.VirtualPackageBase): raise BlueprintException( f"{self} requries {package}, but it is ignored", self) if requiredVersion and requiredVersion != None and CraftVersion( package.version) < CraftVersion(requiredVersion): raise BlueprintException( f"{self} requries {package} version {requiredVersion!r} but {package.version!r} is installed", self) p = CraftDependencyPackage(package) CraftCore.log.debug(f"adding package {packaheName}") CraftDependencyPackage._packageCache[( packaheName, self.depenendencyType)] = p p.depenendencyType = self.depenendencyType else: p = CraftDependencyPackage._packageCache[( packaheName, self.depenendencyType)] children.append(p) return children
def setOption(packageNames: [str], option: str) -> bool: if "=" not in option: CraftCore.log.error(f"Invalid option {option}") return False key, value = option.split("=", 1) for name in packageNames: package = CraftPackageObject.get(name) if not package: raise BlueprintNotFoundException(name) # create instance to make sure options are registered if not package.isCategory(): package.instance if not package: raise BlueprintNotFoundException(name) options = UserOptions.get(package) if not options.setOption(key, value): return False CraftCore.log.info(f"[{package}]\n{key}={getattr(options, key)}") return True
def setOption(packageNames: [str], option: str) -> bool: if "=" not in option: CraftCore.log.error(f"Invalid option {option}") return False key, value = option.split("=", 1) for name in packageNames: package = CraftPackageObject.get(name) if not package: raise BlueprintNotFoundException(name) # create instance to make sure options are registered # version is a special case, it is build in and a non existing version causes an error during construction # skipping the check allows to replace an invalid version if option != "version" and not package.isCategory(): package.instance options = UserOptions.get(package) if not options.setOption(key, value): return False CraftCore.log.info(f"[{package}]\n{key}={getattr(options, key)}") return True
def addBlueprintsRepository(url: str) -> bool: templateDir = os.path.join(CraftCore.standardDirs.craftBin(), "..", "internal_blueprints") with tempfile.TemporaryDirectory() as tmp: iniPath = os.path.join(tmp, "version.ini") parser = configparser.ConfigParser() parser.read(iniPath) parser.add_section("General") parser["General"]["branches"] = "master" parser["General"]["defaulttarget"] = "master" parser["General"]["gitUrl"] = url with open(iniPath, "wt", encoding="UTF-8") as out: parser.write(out) CraftCore.settings.set("Blueprints", "Locations", templateDir) CraftCore.settings.set("InternalTemp", "add-bluprints-template.ini", iniPath) pkg = CraftPackageObject.get("add-bluprints-template") if pkg._instance: # reset the pkg to pick up the values del pkg._instance pkg._instance = None return handlePackage(pkg, "fetch", [])
def cleanBuildFiles(cleanArchives, cleanImages, cleanInstalledImages, cleanBuildDir, packages): def cleanDir(dir): CraftCore.debug.printOut(f"Cleaning: {dir}") utils.cleanDirectory(dir) os.rmdir(dir) for p in packages: package = CraftPackageObject.get(p.path) if not package or package.isCategory(): continue CraftCore.log.debug(f"Checking package for unused files: {p.path}") instance = package.instance version = instance.version if version: imageGlob = instance.imageDir().replace(version, "*") builddirGlob = instance.buildDir().replace(version, "*") else: imageGlob = instance.imageDir() builddirGlob = instance.buildDir() # image directories if cleanImages: for dir in glob.glob(imageGlob): if package.isInstalled and not cleanInstalledImages: if dir == instance.imageDir(): continue cleanDir(dir) # archive directory if cleanArchives and os.path.exists(instance.archiveDir()): cleanDir(instance.archiveDir()) # build directory if cleanBuildDir: for dir in glob.glob(builddirGlob): cleanDir(dir)
def __init__(self, path): CraftPackageObject.__init__(self, path) self._depenendencyType = None self.dependencies = [] # tuple (name, required version) self.state = CraftDependencyPackage.State.Unvisited
def shelve(target: str): target = Path(target) CraftCore.log.info(f"Creating shelve: {target}") listFile = configparser.ConfigParser(allow_no_value=True) updating = target.exists() if updating: listFile.read(target, encoding="UTF-8") oldSections = set(listFile.sections()) if "General" in oldSections: oldSections.remove("General") if not listFile.has_section("General"): listFile.add_section("General") listFile["General"]["version"] = "2" blueprintRepos = [] for p in CraftPackageObject.get("craft").children.values(): if p.path in {"craft/craft-core", "craft/craftmaster"}: continue blueprintRepos.append(p.instance.repositoryUrl()) listFile["General"]["blueprintRepositories"] = ";".join(blueprintRepos) reDate = re.compile(r"\d\d\d\d\.\d\d\.\d\d") def _set(package, key: str, value: str): if updating: old = package.get(key, value) if old != value: CraftCore.log.info( f"Updating {package.name} {key}: {old} -> {value}") package[key] = value newPackages = set() for package, version, revision in CraftCore.installdb.getDistinctInstalled( ): packageObject = CraftPackageObject.get(package) if not packageObject: CraftCore.log.warning( f"{package} is no longer known to Craft, it will not be added to the list" ) continue if not packageObject.subinfo.shelveAble: continue if not listFile.has_section(package): listFile.add_section(package) if updating: newPackages.add(package) package = listFile[package] # TODO: clean our database patchLvl = version.split("-", 1) if len(patchLvl) == 2: # have we encoded a date or a patch lvl? clean = packageObject.subinfo.options.dailyUpdate and bool( reDate.match(patchLvl[1])) clean |= patchLvl[0] in packageObject.subinfo.patchLevel and str( packageObject.subinfo.patchLevel[patchLvl[0]] + packageObject.categoryInfo.patchLevel) == patchLvl[1] if clean: version = patchLvl[0] _set(package, "version", version) if version != packageObject.subinfo.defaultTarget: CraftCore.debug.printOut( f"For {packageObject} {version} is an update availible: {packageObject.subinfo.defaultTarget}" ) if revision: # sadly we combine the revision with the branch "master-1234ac" revParts = revision.split("-", 1) if len(revParts) == 2: _set(package, "revision", revParts[1]) if updating: removed = oldSections - newPackages added = newPackages - oldSections CraftCore.log.info( f"The following packages where removed from {target}: {removed}") CraftCore.log.info( f"The following packages where added to {target}: {added}") utils.createDir(target.parent) listFile._sections = OrderedDict( sorted(listFile._sections.items(), key=lambda k: k[0])) with open(target, "wt", encoding="UTF-8") as out: listFile.write(out) return True
def isActive(self, package): if isinstance(package, str): package = CraftPackageObject.get(package) return not package.isIgnored()
def __init__(self, path): CraftPackageObject.__init__(self, path) self._depenendencyType = None self.runtimeChildren = [] self.dependencies = [] self.state = CraftDependencyPackage.State.Unvisited