Example #1
0
    def __call__(command,
                 args,
                 resref=None,
                 resref_type="auto",
                 internal=False,
                 trace=False):
        from reproman.ui import ui

        if internal and trace:
            raise NotImplementedError("No --trace for --internal commands")

        if not resref:
            resref = ui.question("Enter a resource name or ID",
                                 error_message="Missing resource name or ID")

        env_resource = get_manager().get_resource(resref, resref_type)
        env_resource.connect()

        if internal:
            cls_key = "internal"
        elif trace:
            cls_key = "trace"
        else:
            cls_key = "plain"
        cmd = CMD_CLASSES[cls_key](env_resource, command, args)

        try:
            error = None
            out, err = cmd()
        except CommandError as exc:
            error = exc
            out, err = exc.stdout, exc.stderr

        lgr.info("Executed the %s command in the environment %s", command,
                 env_resource.name)

        if out:
            sys.stdout.write(out)
        if err:
            sys.stderr.write(err)
        if error:
            lgr.error("Command %s failed to run in %s: %s", command,
                      env_resource.name, error.msg)
            raise SystemExit(error.code)
Example #2
0
    def __call__(name, resource_type, backend_parameters):
        # Load, while possible merging/augmenting sequentially
        # provenance = Provenance.factory(specs)
        #
        # TODO: need to be redone to be able to operate based on a spec
        #  we do want
        #     reproman create --resource_type docker_container --spec analysis.spec
        #  which would choose appropriate base container etc
        #
        # if nothing in cmdline instructed on specific one to use:
        #   resource = Resource.factory(resource_type)
        #   resource_base = resource.guess_base(provenance.distributions)
        #
        # internally it might first just check if base OS could be deduced, so
        # we need helpers like
        #     guess_base_os_spec(distributions)
        # and if none is there, each resource, might provide/use defaults, e.g.
        # a default docker image if there is anaconda used and nothing about base
        # env.
        #
        # if not specs:
        #     specs = question("Enter a spec filename", default="spec.yml")

        from reproman.ui import ui

        if not resource_type:
            resource_type = ui.question(
                "Enter a resource type",
                default="docker-container"
            )
        # if only_env:
        #     raise NotImplementedError

        # TODO: Add ability to clone a resource.

        get_manager().create(name, resource_type,
                             parse_backend_parameters(backend_parameters))
        lgr.info("Created the environment %s", name)

        # TODO: at the end install packages using install and created env
        # if not only_env:
        #     from repronim.api import install
        #     install(provenance, name, resource_id, config)
Example #3
0
 def ask():
     assert_equal(ui.question('what is a?'), 'a')