示例#1
0
    def test_prompt_with_non_existing_user_input(self, patched_input):
        context = Context(name="test",
                          registry=Registry(),
                          mode=Mode.INTERACTIVE)
        key = uuid4()

        self.assertEqual(random_user_input,
                         context.get_or_request_user_input(key, "some prompt"))
示例#2
0
    def test_user_input_fails_in_non_interactive_mode(self):
        context = Context(name="test",
                          registry=Registry(),
                          mode=Mode.BACKGROUND)

        self.assertRaises(
            Exception, lambda *args: context.get_or_request_user_input(
                "any", "some prompt"))
示例#3
0
    def test_existing_user_input(self):
        context = Context(name="test",
                          registry=Registry(),
                          mode=Mode.INTERACTIVE)
        key = uuid4()
        value = uuid4()

        context._user_inputs[key] = value

        self.assertEqual(value,
                         context.get_or_request_user_input(key, "some prompt"))
示例#4
0
def parse_context(name, registry: Registry, description=""):
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument("--mode", "-m",
                        choices=["interactive", "background"],
                        dest="mode",
                        default="interactive",
                        help="one of [ interactive | background ]. "
                             "Note that some actions cannot be executed in non-interactive mode")
    parser.add_argument("--dry-run",
                        default=False,
                        dest="dryrun",
                        action="store_true",
                        help="runs in dry run mode. In that mode actions that modify your environment will not be "
                             "executed")
    parser.add_argument("--plan", "-p",
                        default=False,
                        dest="plan",
                        action="store_true",
                        help="prints out an execution plan (takes into account your platform and program flags)")
    parser.add_argument("--debug", "-d",
                        default=False,
                        dest="debug",
                        action="store_true",
                        help="logs debug information to the console")
    parser.add_argument("--experimental", "-e",
                        default=False,
                        dest="experimental",
                        action="store_true",
                        help="turns on experimental features")
    parser.add_argument("--log-file",
                        dest="log_file",
                        help="absolute path to optional log file")
    parser.add_argument("--config",
                        dest="config_file",
                        help="optional JSON config file path")
    parser.add_argument("--components",
                        default=None,
                        dest="components",
                        help="optional comma separated list of component names. Supported components are: {}"
                        .format(list(registry.component_ids())))

    args = parser.parse_args()

    if args.components is not None:
        components = [comp.strip() for comp in args.components.split(",")]
    else:
        components = None

    return Context(
        name=name,
        config_file=args.config_file,
        registry=registry,
        mode=Mode.from_str(args.mode),
        debug=args.debug,
        log_file=args.log_file,
        plan=args.plan,
        dryrun=args.dryrun,
        experimental=args.experimental,
        components=components
    )
示例#5
0
    def resolve(self, ctx: Context):
        resolved_cmd = []

        for value in self._cmd:
            if type(value) == UserInput:
                resolved_cmd.append(
                    ctx.get_or_request_user_input(value.key, value.prompt))
            else:
                resolved_cmd.append(value)

        return resolved_cmd
示例#6
0
文件: app.py 项目: sha1n/devenv-tools
def _parse_context():
    parser = argparse.ArgumentParser(
        description=
        "Collects environment information and packs it all into a tar archive for support "
        "purposes.")
    parser.add_argument("--debug",
                        "-d",
                        default=False,
                        dest="debug",
                        action="store_true",
                        help="logs debug information to the console")
    parser.add_argument("--experimental",
                        "-e",
                        default=False,
                        dest="experimental",
                        action="store_true",
                        help="turns on experimental features")
    parser.add_argument("--log-file",
                        dest="log_file",
                        help="absolute path to optional log file")
    parser.add_argument("--config",
                        dest="config_file",
                        help="optional JSON config file path")
    parser.add_argument("--output",
                        "-o",
                        default=None,
                        dest="out_file",
                        help="absolute path to the output tar archive")

    args = parser.parse_args()

    context = Context(
        name="dump",
        config_file=args.config_file,
        registry=Registry(),
        debug=args.debug,
        log_file=args.log_file,
        experimental=args.experimental,
    )

    context.flags.out_file = resolve_output_file_path(args)

    return context
示例#7
0
def test_context(mode=None) -> Context:
    resolved_mode = mode
    if resolved_mode is None:
        resolved_mode = Mode.from_str(os.environ.get('INSPECTOR_TEST_MODE', str(Mode.BACKGROUND)))

    return Context(name="test", mode=resolved_mode, dryrun=True, registry=Registry())
示例#8
0
 def parse_context(name, registry, description):
     return Context(name, registry, mode=Mode.BACKGROUND)
示例#9
0
def test_context(mode=Mode.BACKGROUND) -> Context:
    mode = Mode.from_str(os.environ.get('INSPECTOR_TEST_MODE', str(mode)))

    return Context(name="test", registry=Registry(), mode=mode, dryrun=True)