當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。