示例#1
0
def handlePackage(package, buildAction, directTargets):
    with CraftTimer.Timer(f"HandlePackage {package}", 3) as timer:
        success = True
        actions = []
        timer.hook = lambda: utils.notify(
            f"Craft {buildAction} {'succeeded' if success else 'failed'}",
            f"{package} after {timer}", buildAction)
        CraftCore.debug.debug_line()
        CraftCore.debug.step(
            f"Handling package: {package}, action: {buildAction}")

        if buildAction == "all":
            if CraftCore.settings.getboolean("Packager", "UseCache", "False"):
                if doExec(package, "fetch-binary"):
                    return True
            actions = ["fetch", "unpack", "compile", "cleanimage", "install"]

            if CraftCore.settings.getboolean("ContinuousIntegration",
                                             "ClearBuildFolder", False):
                actions += ["cleanbuild"]
            actions += ["qmerge", "post-install"]
            if CraftCore.settings.getboolean("Packager", "CreateCache"):
                onlyDirect = CraftCore.settings.getboolean(
                    "Packager", "CacheDirectTargetsOnly")
                if not onlyDirect or (onlyDirect and package in directTargets):
                    actions += ["package"]
        else:
            actions = [buildAction]
        for action in actions:
            success = doExec(package, action)
            if not success:
                return False
        return True
示例#2
0
def doExec(package, action, continueFlag=False):
    with CraftTimer.Timer("%s for %s" % (action, package), 1):
        craftDebug.step("Action: %s for %s" % (action, package))
        ret = package.instance.execute(action)
        if not ret:
            craftDebug.log.warning("Action: %s for %s FAILED" %
                                   (action, package))
        return ret or continueFlag
示例#3
0
def doExec(package, action):
    with CraftTimer.Timer("%s for %s" % (action, package), 1):
        CraftCore.debug.step("Action: %s for %s" % (action, package))
        ret = package.instance.execute(action)
        if not ret:
            if action == "fetch-binary":
                CraftCore.debug.step(f"{package} not found in cache")
                return False
            CraftCore.log.warning("Action: %s for %s FAILED" % (action, package))
        return ret
示例#4
0
def printSearch(search_package, maxDist=2):
    searchPackageLower = search_package.lower()
    isPath = "/" in searchPackageLower
    with CraftTimer.Timer("Search", 0) as timer:
        similar = []
        match = None
        package_re = re.compile(f".*{search_package}.*", re.IGNORECASE)
        for searchPackage in packages():
            packageString = searchPackage.path if isPath else searchPackage.name
            levDist = abs(len(searchPackageLower) - len(packageString))
            if levDist <= maxDist:
                levDist = utils.levenshtein(searchPackageLower,
                                            packageString.lower())
            if levDist == 0:
                match = (levDist, searchPackage)
                break
            elif package_re.match(searchPackage.path):
                similar.append((levDist - maxDist, searchPackage))
            elif len(packageString) > maxDist and levDist <= maxDist:
                similar.append((levDist, searchPackage))
            else:
                if package_re.match(searchPackage.description) or \
                        package_re.match(searchPackage.tags):
                    similar.append((100, searchPackage))

        if match is None:
            if len(similar) > 0:
                CraftCore.log.info(
                    f"Craft was unable to find {search_package}, similar packages are:"
                )
                similar.sort(key=lambda x: x[0])
            else:
                CraftCore.log.info(
                    f"Craft was unable to find {search_package}")
        else:
            CraftCore.log.info(f"Package {search_package} found:")
            similar = [match]

        for levDist, searchPackage in similar:
            CraftCore.log.debug((vars(searchPackage), levDist))
            CraftCore.log.info(searchPackage)
示例#5
0
def handlePackage(package, buildAction, continueFlag, directTargets):
    with CraftTimer.Timer(f"HandlePackage {package}", 3) as timer:
        craftDebug.debug_line()
        craftDebug.step(f"Handling package: {package}, action: {buildAction}")

        success = True

        if buildAction == "all":
            if craftSettings.getboolean("Packager", "UseCache", "False") \
                    and not package.isVirtualPackage():
                if doExec(package, "fetch-binary"):
                    return True
            success = success and doExec(package, "fetch", continueFlag)

            success = success and doExec(package, "unpack", continueFlag)
            success = success and doExec(package, "compile")
            success = success and doExec(package, "cleanimage")
            success = success and doExec(package, "install")
            if buildAction == "all":
                success = success and doExec(package, "qmerge")
            if craftSettings.getboolean("Packager", "CreateCache"):
                if craftSettings.getboolean("Packager",
                                            "CacheDirectTargetsOnly"):
                    nameRe = re.compile(".*\/.*")
                    for target in directTargets:
                        if not nameRe.match(target):
                            craftDebug.log.error(
                                "Error:\n"
                                "[Packager]\n"
                                "CacheDirectTargetsOnly = True\n"
                                "Only works with fully specified packages 'category/package'"
                            )
                            return False
                    if package in directTargets:
                        success = success and doExec(package, "package")
                    else:
                        craftDebug.log.info(
                            "skip packaging of non direct targets")
                else:
                    success = success and doExec(package, "package")
            success = success or continueFlag
        elif buildAction in [
                "fetch", "fetch-binary", "unpack", "configure", "compile",
                "make", "test", "package", "unmerge", "createpatch",
                "print-files"
        ]:
            success = doExec(package, buildAction, continueFlag)
        elif buildAction == "install":
            success = doExec(package, "cleanimage")
            success = success and doExec(package, "install", continueFlag)
        elif buildAction == "qmerge":
            success = success and doExec(package, "qmerge")
        else:
            success = craftDebug.log.error(
                "could not understand this buildAction: %s" % buildAction)

        timer.stop()
        utils.notify(
            f"Craft {buildAction} {'succeeded' if success else 'failed'}",
            f"{package} after {timer}", buildAction)
        return success
示例#6
0
                if child.isCategory():
                    package.children.update(child.children)
                else:
                    if tempArgs.target:
                        craftSettings.set("BlueprintVersions", child.path,
                                          args.target)
                    package.children[child.name] = child
            if not run(package, action, tempArgs, package.children.values()):
                return False
    return True


if __name__ == '__main__':
    success = False
    with CraftTimer.Timer("Craft", 0) as timer:
        CraftTitleUpdater.instance = CraftTitleUpdater()
        CraftTitleUpdater.instance.start(
            f"({CraftStandardDirs.craftRoot()}) craft " +
            " ".join(sys.argv[1:]), timer)
        try:
            success = main()
        except KeyboardInterrupt:
            pass
        except BlueprintException as e:
            craftDebug.log.error(e, exc_info=e.exception or e)
        except Exception as e:
            craftDebug.log.error(e, exc_info=e)
        finally:
            CraftTitleUpdater.instance.stop()
    if not success: