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


Python yaml.round_trip_load方法代码示例

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


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

示例1: sync

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def sync(name, metrics):
    """Write markdown docs"""
    metrics_file = Path().resolve().parent / name / "metrics.yaml"
    cur = {}

    if metrics_file.exists():
        cur = yaml.round_trip_load(metrics_file.read_text())

    for m in metrics:
        entry = cur.setdefault(m.title, asdict(m))

        # If the fetched value exists override it, otherwise leave the current one alone.
        if m.description:
            entry["description"] = m.description
        if m.brief:
            entry["brief"] = m.brief
        if m.metric_type:
            entry["metric_type"] = m.metric_type

    with metrics_file.open("wt") as f:
        yaml.round_trip_dump(cur, f) 
开发者ID:signalfx,项目名称:integrations,代码行数:23,代码来源:cloudsync.py

示例2: generate_sample_configuration

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def generate_sample_configuration(source_filename, destination_filename, schema_filename):
    '''
    Given an optional source configuration filename, and a required destination configuration
    filename, and the path to a schema filename in pykwalify YAML schema format, write out a
    sample configuration file based on that schema. If a source filename is provided, merge the
    parsed contents of that configuration into the generated configuration.
    '''
    schema = yaml.round_trip_load(open(schema_filename))
    source_config = None

    if source_filename:
        source_config = load.load_configuration(source_filename)

    destination_config = merge_source_configuration_into_destination(
        _schema_to_sample_configuration(schema), source_config
    )

    write_configuration(
        destination_filename,
        _comment_out_optional_configuration(_render_configuration(destination_config)),
    ) 
开发者ID:witten,项目名称:borgmatic,代码行数:23,代码来源:generate.py

示例3: write_auto_config_data

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def write_auto_config_data(
    service: str, extra_info: str, data: Dict[str, Any], soa_dir: str = DEFAULT_SOA_DIR
) -> Optional[str]:
    """
    Replaces the contents of an automated config file for a service, or creates the file if it does not exist.

    Returns the filename of the modified file, or None if no file was written.
    """
    service_dir = f"{soa_dir}/{service}"
    if not os.path.exists(service_dir):
        log.warning(
            f"Service {service} does not exist in configs, skipping auto config update"
        )
        return None
    subdir = f"{service_dir}/{AUTO_SOACONFIG_SUBDIR}"
    if not os.path.exists(subdir):
        os.mkdir(subdir)
    filename = f"{subdir}/{extra_info}.yaml"
    with open(filename, "w") as f:
        content = yaml.round_trip_load(
            HEADER_COMMENT.format(regular_filename=f"{service}/{extra_info}.yaml")
        )
        content.update(data)
        f.write(yaml.round_trip_dump(content))
    return filename 
开发者ID:Yelp,项目名称:paasta,代码行数:27,代码来源:config_utils.py

示例4: import_config

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def import_config(args, input_file=None):
    if not input_file:
        input_file = sys.stdin
    source = input_file.read().strip()
    if source[0] == "{":
        # JSON input
        config = json.loads(source)
    else:
        # YAML input
        config = yaml.round_trip_load(source)

    STATE["stages"] = config["stages"]
    config["config"] = _encrypt_dict(config["config"])
    with open(args.config, "wt") as f:
        if config:
            yaml.round_trip_dump(config, f) 
开发者ID:rackerlabs,项目名称:fleece,代码行数:18,代码来源:config.py

示例5: export_config

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def export_config(args, output_file=None):
    if not output_file:
        output_file = sys.stdout
    if os.path.exists(args.config):
        with open(args.config, "rt") as f:
            config = yaml.round_trip_load(f.read())
        STATE["stages"] = config["stages"]
        config["config"] = _decrypt_dict(config["config"])
    else:
        config = {
            "stages": {
                env["name"]: {"environment": env["name"], "key": "enter-key-name-here"}
                for env in STATE["awscreds"].environments
            },
            "config": {},
        }

    if args.json:
        output_file.write(json.dumps(config, indent=4))
    elif config:
        yaml.round_trip_dump(config, output_file) 
开发者ID:rackerlabs,项目名称:fleece,代码行数:23,代码来源:config.py

示例6: main

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def main():  # pragma: no cover
    try:
        args = parse_arguments(*sys.argv[1:])
        schema = yaml.round_trip_load(open(validate.schema_filename()).read())
        source_config = legacy.parse_configuration(
            args.source_config_filename, legacy.CONFIG_FORMAT
        )
        source_config_file_mode = os.stat(args.source_config_filename).st_mode
        source_excludes = (
            open(args.source_excludes_filename).read().splitlines()
            if args.source_excludes_filename
            else []
        )

        destination_config = convert.convert_legacy_parsed_config(
            source_config, source_excludes, schema
        )

        generate.write_configuration(
            args.destination_config_filename, destination_config, mode=source_config_file_mode
        )

        display_result(args)
    except (ValueError, OSError) as error:
        print(error, file=sys.stderr)
        sys.exit(1) 
开发者ID:witten,项目名称:borgmatic,代码行数:28,代码来源:convert_config.py

示例7: load_settings

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def load_settings(file_to_load):
    settings = None
    try:
        settings = yaml.round_trip_load(open(file_to_load, "r"), preserve_quotes=True)
    except Exception:
        log.exception("Exception loading %s: ", file_to_load)
    return settings 
开发者ID:Cloudbox,项目名称:Community,代码行数:9,代码来源:settings-updater.py

示例8: load_yaml

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def load_yaml(cls, filename: str):
        """
        Load a hierarchy of sparse objects from a YAML file.

        :param filename: The filename to open.
        :return: The configuration object hierarchy
        """
        def unpack(mapping, parent=None):
            """
            Recursively create Configuration objects with the parent
            correctly set, returning the top-most parent.
            """
            if mapping is None:
                return None

            children = config = None

            if not isinstance(mapping, cls):
                children = mapping.pop('children', None)
                config = cls(**cls._coerce_types(mapping), parent=parent)

            if children:
                for child in children:
                    unpack(child, parent=config)
            return config

        if filename in cls._yaml_cache:
            return cls._yaml_cache[filename]

        data = None
        with open(filename, 'r') as yaml_file:
            data = unpack(yaml.round_trip_load(yaml_file.read()))

        if data is not None:
            cls._yaml_cache[filename] = data

        return data 
开发者ID:cyanogen,项目名称:uchroma,代码行数:39,代码来源:config.py

示例9: edit_soa_configs

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def edit_soa_configs(filename, instance, cpu, mem, disk):
    if not os.path.exists(filename):
        filename = filename.replace("marathon", "kubernetes")
    if os.path.islink(filename):
        real_filename = os.path.realpath(filename)
        os.remove(filename)
    else:
        real_filename = filename
    try:
        with open(real_filename, "r") as fi:
            yams = fi.read()
            yams = yams.replace("cpus: .", "cpus: 0.")
            data = yaml.round_trip_load(yams, preserve_quotes=True)

        instdict = data[instance]
        if cpu:
            instdict["cpus"] = float(cpu)
        if mem:
            mem = max(128, round(float(mem)))
            instdict["mem"] = mem
        if disk:
            instdict["disk"] = round(float(disk))
        out = yaml.round_trip_dump(data, width=120)

        with open(filename, "w") as fi:
            fi.write(out)
    except FileNotFoundError:
        log.exception(f"Could not find {filename}")
    except KeyError:
        log.exception(f"Error in {filename}. Will continue") 
开发者ID:Yelp,项目名称:paasta,代码行数:32,代码来源:paasta_update_soa_memcpu.py

示例10: _resolve_and_publish

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def _resolve_and_publish(config_file, bucket):
    try:
        gcs_paths = []
        with open(config_file, 'r') as f:
            if 'yaml' not in config_file:
                logging.error('Please provide a valid yaml config file.')
                sys.exit(1)
            project_cfg = yaml.round_trip_load(f, preserve_quotes=True)
            project_name = project_cfg['project']
            for builder in project_cfg['builders']:
                cfg = os.path.abspath(str(builder['file']))
                name = builder['name']
                builder_name = project_name + '-' + name

                templated_file = _resolve_tags(cfg)
                logging.info(templated_file)
                gcs_paths.append(_publish_to_gcs(templated_file,
                                                 builder_name,
                                                 bucket))

        logging.info('Published Runtimes:')
        logging.info(gcs_paths)
    except ValueError as ve:
        logging.error('Error when parsing config! Check file formatting. \n{0}'
                      .format(ve))
    except KeyError as ke:
        logging.error('Config file is missing required field! \n{0}'
                      .format(ke)) 
开发者ID:GoogleCloudPlatform,项目名称:runtimes-common,代码行数:30,代码来源:template_builder.py

示例11: _resolve_tags

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def _resolve_tags(config_file):
    """
    Given a templated YAML cloudbuild config file, parse it, resolve image tags
    on each build step's image to the corresponding digest, and write new
    config with fully qualified images to temporary file for upload to GCS.

    Keyword arguments:
    config_file -- string representing path to
    templated cloudbuild YAML config file

    Return value:
    path to temporary file containing fully qualified config file, to be
    published to GCS.
    """
    with open(config_file, 'r') as infile:
        logging.info('Templating file: {0}'.format(config_file))
        try:
            config = yaml.round_trip_load(infile, preserve_quotes=True)

            for step in config.get('steps'):
                image = step.get('name')
                step['name'] = _resolve_tag(image)
                args = step.get('args', [])
                for i in range(0, len(args)):
                    arg = args[i]
                    m = re.search(IMAGE_REGEX, arg)
                    if m:
                        suffix = m.group()
                        prefix = re.sub(suffix, '', arg)
                        args[i] = prefix + _resolve_tag(suffix)

            return yaml.round_trip_dump(config)
        except yaml.YAMLError as e:
            logging.error(e)
            sys.exit(1) 
开发者ID:GoogleCloudPlatform,项目名称:runtimes-common,代码行数:37,代码来源:template_builder.py

示例12: quick_load_cwl

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def quick_load_cwl(self, cwl_file):
        with open(cwl_file, "r") as input_stream:
            cwl_data = yaml.round_trip_load(input_stream, preserve_quotes=True)
        return cwl_data 
开发者ID:Barski-lab,项目名称:cwl-airflow,代码行数:6,代码来源:cwldag.py

示例13: cwl_dispatch

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import round_trip_load [as 别名]
def cwl_dispatch(self, json):
        try:
            cwlwf, it_is_workflow = load_cwl(self.dag.default_args["cwl_workflow"], self.dag.default_args)
            cwl_context = {"outdir": mkdtemp(dir=get_folder(os.path.abspath(self.tmp_folder)), prefix="dag_tmp_")}

            _jobloaderctx = jobloaderctx.copy()
            _jobloaderctx.update(cwlwf.metadata.get("$namespaces", {}))
            loader = Loader(_jobloaderctx)

            try:
                job_order_object = yaml.round_trip_load(io.StringIO(initial_value=dumps(json)))
                job_order_object, _ = loader.resolve_all(job_order_object,
                                                         file_uri(os.getcwd()) + "/",
                                                         checklinks=False)
            except Exception as e:
                _logger.error("Job Loader: {}".format(str(e)))

            job_order_object = init_job_order(job_order_object, None, cwlwf, loader, sys.stdout)

            cwl_context['promises'] = job_order_object

            logging.info(
                '{0}: Final job: \n {1}'.format(self.task_id, dumps(cwl_context, indent=4)))

            return cwl_context

        except Exception as e:
            _logger.info(
                'Dispatch Exception {0}: \n {1} {2}'.format(self.task_id, type(e), e))
            pass
        return None 
开发者ID:Barski-lab,项目名称:cwl-airflow,代码行数:33,代码来源:cwljobdispatcher.py


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