当前位置: 首页>>代码示例>>Python>>正文


Python argparse.Namespace方法代码示例

本文整理汇总了Python中argparse.Namespace方法的典型用法代码示例。如果您正苦于以下问题:Python argparse.Namespace方法的具体用法?Python argparse.Namespace怎么用?Python argparse.Namespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在argparse的用法示例。


在下文中一共展示了argparse.Namespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grant

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def grant(args):
    """
    Given an IAM role or instance name, attach an IAM policy granting
    appropriate permissions to subscribe to deployments. Given a
    GitHub repo URL, create and record deployment keys for the repo
    and any of its private submodules, making the keys accessible to
    the IAM role.
    """
    try:
        role = resources.iam.Role(args.iam_role_or_instance)
        role.load()
    except ClientError:
        role = get_iam_role_for_instance(args.iam_role_or_instance)
    role.attach_policy(PolicyArn=ensure_deploy_iam_policy().arn)
    for private_repo in [args.repo] + list(private_submodules(args.repo)):
        gh_owner_name, gh_repo_name = parse_repo_name(private_repo)
        secret = secrets.put(argparse.Namespace(secret_name="deploy.{}.{}".format(gh_owner_name, gh_repo_name),
                                                iam_role=role.name,
                                                instance_profile=None,
                                                iam_group=None,
                                                iam_user=None,
                                                generate_ssh_key=True))
        get_repo(private_repo).create_key(__name__ + "." + role.name, secret["ssh_public_key"])
        logger.info("Created deploy key %s for IAM role %s to access GitHub repo %s",
                    secret["ssh_key_fingerprint"], role.name, private_repo) 
开发者ID:kislyuk,项目名称:aegea,代码行数:27,代码来源:deploy.py

示例2: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def __init__(self, arguments: argparse.Namespace, help_text: str):
        self.profile_name = arguments.profile_name
        self.access_key = arguments.access_key
        self.secret_access_key = arguments.secret_access_key
        self.session_token = arguments.session_token
        self.region = arguments.region
        self.command = arguments.command
        self.api_id = arguments.api_id
        self.url = arguments.url
        self.api_list = []
        self.client = None
        self.help = help_text

        if self.access_key and self.secret_access_key:
            if not self.region:
                self.error('Please provide a region with AWS credentials')

        if not self.load_creds():
            self.error('Unable to load AWS credentials')

        if not self.command:
            self.error('Please provide a valid command') 
开发者ID:ustayready,项目名称:fireprox,代码行数:24,代码来源:fire.py

示例3: parse_arguments

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def parse_arguments() -> Tuple[argparse.Namespace, str]:
    """Parse command line arguments and return namespace

    :return: Namespace for arguments and help text as a tuple
    """
    parser = argparse.ArgumentParser(description='FireProx API Gateway Manager')
    parser.add_argument('--profile_name',
                        help='AWS Profile Name to store/retrieve credentials', type=str, default=None)
    parser.add_argument('--access_key',
                        help='AWS Access Key', type=str, default=None)
    parser.add_argument('--secret_access_key',
                        help='AWS Secret Access Key', type=str, default=None)
    parser.add_argument('--session_token',
                        help='AWS Session Token', type=str, default=None)
    parser.add_argument('--region',
                        help='AWS Region', type=str, default=None)
    parser.add_argument('--command',
                        help='Commands: list, create, delete, update', type=str, default=None)
    parser.add_argument('--api_id',
                        help='API ID', type=str, required=False)
    parser.add_argument('--url',
                        help='URL end-point', type=str, required=False)
    return parser.parse_args(), parser.format_help() 
开发者ID:ustayready,项目名称:fireprox,代码行数:25,代码来源:fire.py

示例4: test_build_kabob_params

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_build_kabob_params(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='0.1', test_test="test", arg_arg="argy")

        mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path)
        mock_getcwd.return_value = folderPath

        config = sb.systems.generators.yaml.loadConfig()
        job = config.jobs[0]
        param = sb.objects.param.Param("test-test", "t")
        arg = sb.objects.arg.Arg("arg-arg")
        job.params.append(param)
        job.args.append(arg)

        expected = "bash build.sh 0.1 argy --env local --test-test test --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:19,代码来源:test_systems_execution_commandBuilder.py

示例5: test_build_list_param

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_build_list_param(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='0.1', test_test=[1, 2, 3], arg_arg="argy")

        mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path)
        mock_getcwd.return_value = folderPath

        config = sb.systems.generators.yaml.loadConfig()
        job = config.jobs[0]
        param = sb.objects.param.Param("test-test", "t", accepts="list")
        arg = sb.objects.arg.Arg("arg-arg")
        job.params.append(param)
        job.args.append(arg)

        expected = "bash build.sh 0.1 argy --env local --test-test 1 2 3 --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:19,代码来源:test_systems_execution_commandBuilder.py

示例6: test_execute_push_conflict_s3

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_execute_push_conflict_s3(self, mock_boto3_session):
        mock_client = mock.Mock()
        mock_session = mock.Mock()
        mock_client.list_objects_v2.return_value = {"Contents": [{"Key": "test_v1.0.0.pkl"}]}
        mock_session.client.return_value = mock_client
        mock_boto3_session.return_value = mock_session

        config = sb.objects.config.Config(version="1.0.0")
        args = argparse.Namespace(job="push", force=False, artifact='test', user='sean', token='abc123')
        expectedException = "This artifact version already exists. Please bump the version or use the force parameter (-f) to overwrite the artifact."

        try:
            self.s3.execute(config, args)
            self.fail("Exception Not Thrown")
        except Exception as exc:
            self.assertEqual(str(exc), expectedException)
            mock_client.list_objects_v2.assert_called_with(Bucket="my-bucket", Prefix="test_v1.0.0.pkl") 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:19,代码来源:test_components_repository_repository.py

示例7: test_execute_push_artifactory_all

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_execute_push_artifactory_all(self, mock_artifactory, mock_remove, mock_copy):
        config = sb.objects.config.Config(version="1.0.0")
        args = argparse.Namespace(job="push", force=True, artifact='ALL', user='sean', token='abc123')

        self.artifactory.execute(config, args)

        mock_artifactory.assert_has_calls([
            mock.call("artifactory.test.com/ml/test/test_v1.0.0.pkl", auth=('sean', 'abc123')),
            mock.call("artifactory.test.com/ml/test/test2_v1.0.0.pkl", auth=('sean', 'abc123'))
        ], any_order=True)
        mock_copy.assert_has_calls([
            mock.call("test.pkl", "test_v1.0.0.pkl"),
            mock.call("test2.pkl", "test2_v1.0.0.pkl")
        ], any_order=True)
        mock_remove.assert_has_calls([
            mock.call("test_v1.0.0.pkl"),
            mock.call("test2_v1.0.0.pkl")
        ], any_order=True) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:20,代码来源:test_components_repository_repository.py

示例8: test_run_docker_params

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_run_docker_params(self, mock_getcwd, mock_call, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        memory = 256
        args = Namespace(version='0.1')

        homePath = "{path}/test/plugins".format(path=self.path)
        mock_expanduser.return_value = homePath
        mock_getcwd.return_value = folderPath
        mock_call.return_value = 0

        config = sb.systems.generators.yaml.loadConfig()
        config.components.append(LimitMemory(memory))
        job = sb.objects.job.Job(name='some_command', help='Dummy', source='echo some_command')
        command = sb.systems.execution.commandBuilder.build(config, job, args)

        expected = "docker run --name test-some_command --rm -i --memory {memory}GB test /bin/bash -c \"echo some_command\"".format(memory=memory)
        sb.systems.execution.docker.run(config, command, job.mode, config.ports, job.mappings, job.name)
        mock_call.assert_called_once_with(expected, shell=True) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:20,代码来源:test_systems_execution_docker.py

示例9: test_run_docker_params_entrypoint

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_run_docker_params_entrypoint(self, mock_getcwd, mock_call, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        memory = 256
        args = Namespace(version='0.1')

        homePath = "{path}/test/plugins".format(path=self.path)
        mock_expanduser.return_value = homePath
        mock_getcwd.return_value = folderPath
        mock_call.return_value = 0

        config = sb.systems.generators.yaml.loadConfig()
        config.primaryExe = "ENTRYPOINT"
        config.components.append(LimitMemory(memory))
        job = sb.objects.job.Job(name='some_command', help='Dummy', source='echo some_command')
        command = sb.systems.execution.commandBuilder.build(config, job, args)

        expected = "docker run --name test-some_command --rm -i --memory {memory}GB --entrypoint echo test some_command".format(memory=memory)
        sb.systems.execution.docker.run(config, command, job.mode, config.ports, job.mappings, job.name)
        mock_call.assert_called_once_with(expected, shell=True) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:21,代码来源:test_systems_execution_docker.py

示例10: parse_args

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def parse_args(argv, command_line_options):
  # type: (List[str], List[type]) -> (argparse.Namespace, List[str])
  """Parses the arguments.

  Args:
    argv: A list of string representing the pipeline arguments.
    command_line_options: A list of type ``VariantTransformsOptions`` that
      specifies the options that will be added to parser.
  """
  parser = argparse.ArgumentParser()
  parser.register('type', 'bool', lambda v: v.lower() == 'true')
  options = [option() for option in command_line_options]
  for transform_options in options:
    transform_options.add_arguments(parser)
  known_args, pipeline_args = parser.parse_known_args(argv)
  for transform_options in options:
    transform_options.validate(known_args)
  _raise_error_on_invalid_flags(pipeline_args)
  if hasattr(known_args, 'input_pattern') or hasattr(known_args, 'input_file'):
    known_args.all_patterns = _get_all_patterns(
        known_args.input_pattern, known_args.input_file)
  return known_args, pipeline_args 
开发者ID:googlegenomics,项目名称:gcp-variant-transforms,代码行数:24,代码来源:pipeline_common.py

示例11: cli_args

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def cli_args(args: Sequence[str], search_config_files: bool = True) -> argparse.Namespace:
    """Command line arguments as parsed args.

    If a INI configuration file is set it is used to set additional default arguments, but
    the CLI arguments override any INI file settings.

    Args:
        args: the argument sequence from the command line
        search_config_files: flag for looking through ``SETTINGS_FILES`` for settings

    Returns:
        Parsed args from ArgumentParser
    """
    parser = cli_parser()

    if search_config_files:
        for ini_config_file in SETTINGS_FILES:

            if ini_config_file.path.exists():
                try:
                    ini_config = read_ini_config(ini_config_file.path, ini_config_file.sections)
                    ini_cli_args = parse_ini_config_with_cli(parser, ini_config, args)
                    return parser.parse_args(ini_cli_args)

                except KeyError:
                    # read_ini_config will raise KeyError if the section is not valid
                    continue

    return parser.parse_args(args) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:31,代码来源:cli.py

示例12: ensure_queue

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def ensure_queue(name):
    cq_args = argparse.Namespace(name=name, priority=5, compute_environments=[name])
    try:
        return create_queue(cq_args)
    except ClientError:
        create_compute_environment(cce_parser.parse_args(args=[name]))
        return create_queue(cq_args) 
开发者ID:kislyuk,项目名称:aegea,代码行数:9,代码来源:batch.py

示例13: configure

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def configure(self, args: argparse.Namespace):
        config = self._load_config(args.config)
        if args.check_only:
            self.exit()
        self.create_metrics(config.metrics.values())
        self.query_loop = QueryLoop(config, self.registry, self.logger) 
开发者ID:albertodonato,项目名称:query-exporter,代码行数:8,代码来源:main.py

示例14: test_build

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_build(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='0.1', test=True)

        mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path)
        mock_getcwd.return_value = folderPath

        config = sb.systems.generators.yaml.loadConfig()
        job = config.jobs[0]
        param = sb.objects.param.Param("test", "t", accepts="boolean")
        job.params.append(param)

        expected = "bash build.sh 0.1 --env local --test --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:17,代码来源:test_systems_execution_commandBuilder.py

示例15: test_build_no_boolean

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import Namespace [as 别名]
def test_build_no_boolean(self, mock_getcwd, mock_expanduser):
        folderPath = "{path}/test/files".format(path=self.path)
        args = Namespace(version='1.1')

        mock_expanduser.return_value = "{path}/test/plugins".format(path=self.path)
        mock_getcwd.return_value = folderPath

        config = sb.systems.generators.yaml.loadConfig()
        job = config.jobs[0]
        param = sb.objects.param.Param("test", "t", accepts="boolean")
        job.params.append(param)

        expected = "bash build.sh 1.1 --env local --log info"
        command = sb.systems.execution.commandBuilder.build(config, job, args)
        self.assertEqual(command, expected) 
开发者ID:carsdotcom,项目名称:skelebot,代码行数:17,代码来源:test_systems_execution_commandBuilder.py


注:本文中的argparse.Namespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。