Exemplo n.º 1
0
    def add_anod_action(self,
                        name,
                        env=None,
                        primitive=None,
                        qualifier=None,
                        upload=True):
        """Add an Anod action to the context.

        :param name: spec name
        :type name: str
        :param env: spec environment
        :type env: BaseEnv | None
        :param primitive: spec primitive
        :type primitive: str
        :param qualifier: qualifier
        :type qualifier: str | None
        :param upload: if True consider uploading to the store
        :type upload: bool
        :return: the root added action
        :rtype: Action
        """
        # First create the subtree for the spec
        result = self.add_spec(name, env, primitive, qualifier)

        # Resulting subtree should be connected to the root node
        self.connect(self.root, result)

        # Ensure decision is set in case of explicit build or install
        if primitive == 'build':
            build_action = None
            for el in self.predecessors(result):
                if isinstance(el, BuildOrInstall):
                    el.set_decision(BuildOrInstall.BUILD)
                    build_action = self[el.left]
            if build_action is None and isinstance(result, Build):
                build_action = result

            if build_action is not None:
                spec = build_action.data
                if spec.component is not None and upload:
                    if spec.has_package:
                        upload_bin = UploadBinaryComponent(spec)
                    else:
                        upload_bin = UploadSourceComponent(spec)
                    self.add(upload_bin)
                    self.connect(self.root, upload_bin)
                    self.connect(upload_bin, build_action)

        elif primitive == 'install':
            for el in self.predecessors(result):
                if isinstance(el, BuildOrInstall):
                    el.set_decision(BuildOrInstall.INSTALL)
        return result
Exemplo n.º 2
0
    def add_anod_action(
        self,
        name,
        env=None,
        primitive=None,
        qualifier=None,
        source_packages=None,
        upload=True,
        plan_line=None,
        plan_args=None,
        sandbox=None,
    ):
        """Add an Anod action to the context.

        :param name: spec name
        :type name: str
        :param env: spec environment
        :type env: BaseEnv | None
        :param primitive: spec primitive
        :type primitive: str
        :param qualifier: qualifier
        :type qualifier: str | None
        :param source_packages: if not empty only create the specified list of
            source packages and not all source packages defined in the anod
            specification file
        :type source_packages: list[str] | None
        :param upload: if True consider uploading to the store
        :type upload: bool
        :param plan_line: corresponding line:linenumber in the plan
        :type plan_line: str
        :param plan_args: action args after plan execution, taking into
            account plan context (such as with defaults(XXX):)
        :type plan_args: dict
        :return: the root added action
        :rtype: Action
        """
        # First create the subtree for the spec
        result = self.add_spec(
            name,
            env,
            primitive,
            qualifier,
            source_packages=source_packages,
            plan_line=plan_line,
            plan_args=plan_args,
            sandbox=sandbox,
            upload=upload,
        )

        # Resulting subtree should be connected to the root node
        self.connect(self.root, result)

        # Ensure decision is set in case of explicit build or install
        if primitive == "build":
            build_action = None
            for el in self.predecessors(result):
                if isinstance(el, BuildOrDownload):
                    el.set_decision(BuildOrDownload.BUILD, plan_line)
                    build_action = self[el.left]
            if build_action is None and isinstance(result, Build):
                build_action = result

            # Create upload nodes
            if build_action is not None:
                spec = build_action.data
                if spec.component is not None and upload:
                    if spec.has_package:
                        upload_bin = UploadBinaryComponent(spec)
                    else:
                        upload_bin = UploadSourceComponent(spec)
                    self.add(upload_bin)
                    # ??? is it needed?
                    if plan_line is not None and plan_args is not None:
                        self.link_to_plan(
                            vertex_id=upload_bin.uid,
                            plan_line=plan_line,
                            plan_args=plan_args,
                        )
                    self.connect(self.root, upload_bin)
                    self.connect(upload_bin, build_action)

        elif primitive == "install":
            for el in self.predecessors(result):
                if isinstance(el, BuildOrDownload):
                    el.set_decision(BuildOrDownload.INSTALL, plan_line)
        return result
Exemplo n.º 3
0
    def add_anod_action(
        self,
        name: str,
        env: BaseEnv,
        primitive: str,
        qualifier: Optional[str] = None,
        source_packages: Optional[List[str]] = None,
        upload: bool = True,
        plan_line: Optional[str] = None,
        plan_args: Optional[dict] = None,
        sandbox: Optional[SandBox] = None,
    ) -> Action:
        """Add an Anod action to the context (internal function).

        Note that using add_anod_action should be avoided when possible
        and replaced by a call to add_plan_action.

        :param name: spec name
        :param env: context in which to load the spec
        :param primitive: spec primitive
        :param qualifier: qualifier
        :param source_packages: if not empty only create the specified list of
            source packages and not all source packages defined in the anod
            specification file
        :param upload: if True consider uploading to the store
        :param plan_line: corresponding line:linenumber in the plan
        :param plan_args: action args after plan execution, taking into
            account plan context (such as with defaults(XXX):)
        :param sandbox: the SandBox object that will be used to run commands
        :return: the root added action
        """
        # First create the subtree for the spec
        result = self.add_spec(
            name,
            env,
            primitive,
            qualifier,
            source_packages=source_packages,
            plan_line=plan_line,
            plan_args=plan_args,
            sandbox=sandbox,
            upload=upload,
        )

        # Resulting subtree should be connected to the root node
        self.connect(self.root, result)

        # Ensure decision is set in case of explicit build or install
        if primitive == "build":
            build_action = None
            for el in self.predecessors(result):
                if isinstance(el, BuildOrDownload):
                    el.set_decision(BuildOrDownload.BUILD, plan_line)
                    build_action = self[el.left]
            if build_action is None and isinstance(result, Build):
                build_action = result

            # Create upload nodes
            if build_action is not None:
                spec = build_action.data
                if spec.component is not None and upload:
                    upload_bin: Union[UploadBinaryComponent,
                                      UploadSourceComponent]
                    if spec.has_package:
                        upload_bin = UploadBinaryComponent(spec)
                    else:
                        upload_bin = UploadSourceComponent(spec)
                    self.add(upload_bin)
                    # ??? is it needed?
                    if plan_line is not None and plan_args is not None:
                        self.link_to_plan(
                            vertex_id=upload_bin.uid,
                            plan_line=plan_line,
                            plan_args=plan_args,
                        )
                    self.connect(self.root, upload_bin)
                    self.connect(upload_bin, build_action)

        elif primitive == "install":
            for el in self.predecessors(result):
                if isinstance(el, BuildOrDownload):
                    el.set_decision(BuildOrDownload.INSTALL, plan_line)
        return result
Exemplo n.º 4
0
    def add_anod_action(self,
                        name,
                        env=None,
                        primitive=None,
                        qualifier=None,
                        source_packages=None,
                        upload=True,
                        plan_line=None,
                        plan_args=None,
                        force_source_deps=False):
        """Add an Anod action to the context.

        :param name: spec name
        :type name: str
        :param env: spec environment
        :type env: BaseEnv | None
        :param primitive: spec primitive
        :type primitive: str
        :param qualifier: qualifier
        :type qualifier: str | None
        :param source_packages: if not empty only create the specified list of
            source packages and not all source packages defined in the anod
            specification file
        :type source_packages: list[str] | None
        :param upload: if True consider uploading to the store
        :type upload: bool
        :param plan_line: corresponding line:linenumber in the plan
        :type plan_line: str
        :param plan_args: action args after plan execution, taking into
            account plan context (such as with defaults(XXX):)
        :type plan_args: dict
        :param force_source_deps: ??? whether to force loading source deps.
            Idealy we should not need this, but since we're still in transition
            phase we still have tools needed to both create the source package
            and build the component in a single process. They then need to
            parse both source_deps and build_deps.
        :type force_source_deps: bool
        :return: the root added action
        :rtype: Action
        """
        # First create the subtree for the spec
        result = self.add_spec(name,
                               env,
                               primitive,
                               qualifier,
                               source_packages=source_packages,
                               plan_line=plan_line,
                               plan_args=plan_args,
                               force_source_deps=force_source_deps)

        # Resulting subtree should be connected to the root node
        self.connect(self.root, result)

        # Ensure decision is set in case of explicit build or install
        if primitive == 'build':
            build_action = None
            for el in self.predecessors(result):
                if isinstance(el, BuildOrInstall):
                    el.set_decision(BuildOrInstall.BUILD)
                    build_action = self[el.left]
            if build_action is None and isinstance(result, Build):
                build_action = result

            # Create upload nodes
            if build_action is not None:
                spec = build_action.data
                if spec.component is not None and upload:
                    if spec.has_package:
                        upload_bin = UploadBinaryComponent(spec)
                    else:
                        upload_bin = UploadSourceComponent(spec)
                    self.add(upload_bin)
                    # ??? is it needed?
                    if plan_line is not None:
                        self.link_to_plan(vertex_id=upload_bin.uid,
                                          plan_line=plan_line,
                                          plan_args=plan_args)
                    self.connect(self.root, upload_bin)
                    self.connect(upload_bin, build_action)

        elif primitive == 'install':
            for el in self.predecessors(result):
                if isinstance(el, BuildOrInstall):
                    el.set_decision(BuildOrInstall.INSTALL)
        return result