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


Python oyaml.dump方法代码示例

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


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

示例1: save_json

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def save_json(path, obj, **kwargs):
    # default
    if 'indent' not in kwargs:
        kwargs['indent'] = 4
    if 'separators' not in kwargs:
        kwargs['separators'] = (',', ': ')

    path = _check_ext(path, 'json')

    # wrap json.dump
    with open(path, 'w') as f:
        json.dump(obj, f, **kwargs) 
开发者ID:LynnHo,项目名称:DCGAN-LSGAN-WGAN-GP-DRAGAN-Tensorflow-2,代码行数:14,代码来源:serialization.py

示例2: save_yaml

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def save_yaml(path, data, **kwargs):
    import oyaml as yaml

    path = _check_ext(path, 'yml')

    with open(path, 'w') as f:
        yaml.dump(data, f, **kwargs) 
开发者ID:LynnHo,项目名称:DCGAN-LSGAN-WGAN-GP-DRAGAN-Tensorflow-2,代码行数:9,代码来源:serialization.py

示例3: save_pickle

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def save_pickle(path, obj, **kwargs):

    path = _check_ext(path, 'pkl')

    # wrap pickle.dump
    with open(path, 'wb') as f:
        pickle.dump(obj, f, **kwargs) 
开发者ID:LynnHo,项目名称:DCGAN-LSGAN-WGAN-GP-DRAGAN-Tensorflow-2,代码行数:9,代码来源:serialization.py

示例4: export

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def export(prefix, search):
    logger.info('exporting rules')
    kwargs = {"EventBusName": "default"}
    if prefix is not None:
        kwargs["NamePrefix"] = prefix
    if search is not None:
        query = "Rules[?contains(Name, '{0}')] | {{Rules: @}}".format(search)
        kwargs["query"] = query
    rules = events("list_rules", **kwargs)['Rules']
    print(yaml.dump([_export_rule(rule) for rule in rules])) 
开发者ID:cronyo,项目名称:cronyo,代码行数:12,代码来源:cron_rules.py

示例5: delete

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def delete(name):
    rules = _find([name, _namespaced(name)])
    for rule in rules:
        logger.info("deleting rule:\n{}".format(yaml.dump(_export_rule(rule))))
    _delete(rules) 
开发者ID:cronyo,项目名称:cronyo,代码行数:7,代码来源:cron_rules.py

示例6: save_yaml

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def save_yaml(config, f):
    yaml.dump(config, f, default_flow_style=False, sort_keys=False) 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:4,代码来源:config.py

示例7: write

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def write(self, file=None):
            if file is not None:
                self.file = file
                with open(self.file, 'w') as yf:
                    yf.write(yaml.dump(self.data)) 
开发者ID:FairwindsOps,项目名称:pentagon,代码行数:7,代码来源:__init__.py

示例8: save

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def save(self, config="keybinding"):
		"""
		Save key binding map to file
		
		Parameters
		----------
		config : str,optional
			Name of configuration to save - the file <config>.yaml will be saved to the Zynthian config directory
			Default: 'keybinding'
		
		Returns
		-------
		bool
			True on success
		"""
		
		logging.info("Saving key binding to %s.yaml", config)
		config_dir = environ.get('ZYNTHIAN_CONFIG_DIR',"/zynthian/config")
		config_fpath = config_dir + "/" + config + ".yaml"
		try:
			with open(config_fpath,"w") as fh:
				yaml.dump(self.config, fh)
				logging.info("Saving keyboard binding config file {}".format(config_fpath))
				return True

		except Exception as e:
			logging.error("Can't save keyboard binding config file '{}': {}".format(config_fpath,e))
			return False 
开发者ID:zynthian,项目名称:zynthian-ui,代码行数:30,代码来源:zynthian_gui_keybinding.py

示例9: get_hash

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def get_hash(x):
    """Return hash of x."""
    if isinstance(x, str):
        return hash(x)
    elif isinstance(x, dict):
        return hash(yaml.dump(x)) 
开发者ID:ungarj,项目名称:mapchete,代码行数:8,代码来源:config.py

示例10: put

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def put(name,
        cron_expression,
        function_name,
        target_input={},
        description=None):

    logger.info("finding lambda function {}".format(function_name))
    target_arn = \
        _get_target_arn(function_name) or \
        _get_target_arn(_namespaced(function_name))
    if not target_arn:
        logger.error("unable to find lambda function for {}".format(function_name))
        return

    logger.debug(
        "create / update cron rule {0}: {1} for target {2}".format(
            name,
            cron_expression,
            target_arn
        )
    )
    if description:
        rule = events("put_rule",
                      Name=name,
                      ScheduleExpression=cron_expression,
                      Description=description)
    else:
        rule = events("put_rule",
                      Name=name,
                      ScheduleExpression=cron_expression)
    events(
        "put_targets",
        Rule=name,
        Targets=[
            {
                "Id": "1",
                "Arn": target_arn,
                "Input": json.dumps(target_input)
            }
        ]
    )
    try:
        logger.debug("setting lambda permission")
        source_arn = rule["RuleArn"]
        if source_arn.find(NAMESPACE) > 0:
            rule_prefix = rule["RuleArn"].split("/{}".format(NAMESPACE))[0]
            source_arn = "{}/{}*".format(rule_prefix, NAMESPACE)
        logger.debug("lambda permission SourceArn:{}".format(source_arn))
        aws_lambda(
            "add_permission",
            FunctionName=target_arn,
            Action="lambda:InvokeFunction",
            Principal="events.amazonaws.com",
            SourceArn=source_arn,
            StatementId=hashlib.sha1(source_arn.encode("utf-8")).hexdigest()
        )
    except ClientError as error:
        logger.debug("permission already set. {}".format(error))

    for rule in _find([name]):
        logger.info("rule created/updated:\n{}".format(yaml.dump(_export_rule(rule)))) 
开发者ID:cronyo,项目名称:cronyo,代码行数:63,代码来源:cron_rules.py

示例11: lint

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def lint(paths, format, nofail, **kwargs):
    """Lint SQL files via passing a list of files or using stdin.

    PATH is the path to a sql file or directory to lint. This can be either a
    file ('path/to/file.sql'), a path ('directory/of/sql/files'), a single ('-')
    character to indicate reading from *stdin* or a dot/blank ('.'/' ') which will
    be interpreted like passing the current working directory as a path argument.

    Linting SQL files:

        sqlfluff lint path/to/file.sql
        sqlfluff lint directory/of/sql/files

    Linting a file via stdin (note the lone '-' character):

        cat path/to/file.sql | sqlfluff lint -
        echo 'select col from tbl' | sqlfluff lint -

    """
    c = get_config(**kwargs)
    lnt = get_linter(c, silent=format in ('json', 'yaml'))
    verbose = c.get('verbose')

    config_string = format_config(lnt, verbose=verbose)
    if len(config_string) > 0:
        lnt.log(config_string)

    # add stdin if specified via lone '-'
    if ('-',) == paths:
        result = lnt.lint_string_wrapped(sys.stdin.read(), fname='stdin', verbosity=verbose)
    else:
        # Output the results as we go
        lnt.log(format_linting_result_header(verbose=verbose))
        try:
            result = lnt.lint_paths(paths, verbosity=verbose, ignore_non_existent_files=False)
        except IOError:
            click.echo(colorize('The path(s) {0!r} could not be accessed. Check it/they exist(s).'.format(paths), 'red'))
            sys.exit(1)
        # Output the final stats
        lnt.log(format_linting_result_footer(result, verbose=verbose))

    if format == 'json':
        click.echo(json.dumps(result.as_records()))
    elif format == 'yaml':
        click.echo(yaml.dump(result.as_records()))

    if not nofail:
        sys.exit(result.stats()['exit code'])
    else:
        sys.exit(0) 
开发者ID:alanmcruickshank,项目名称:sqlfluff,代码行数:52,代码来源:commands.py

示例12: create

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import dump [as 别名]
def create(
    mapchete_file,
    process_file,
    out_format,
    out_path=None,
    pyramid_type=None,
    force=False
):
    """Create an empty Mapchete and process file in a given directory."""
    if os.path.isfile(process_file) or os.path.isfile(mapchete_file):
        if not force:
            raise IOError("file(s) already exists")

    out_path = out_path if out_path else os.path.join(os.getcwd(), "output")

    # copy file template to target directory
    # Reads contents with UTF-8 encoding and returns str.
    process_template = str(files("mapchete.static").joinpath("process_template.py"))
    process_file = os.path.join(os.getcwd(), process_file)
    copyfile(process_template, process_file)

    # modify and copy mapchete file template to target directory
    mapchete_template = str(
        files("mapchete.static").joinpath("mapchete_template.mapchete")
    )

    output_options = dict(
        format=out_format, path=out_path, **FORMAT_MANDATORY[out_format]
    )

    pyramid_options = {'grid': pyramid_type}

    substitute_elements = {
        'process_file': process_file,
        'output': dump({'output': output_options}, default_flow_style=False),
        'pyramid': dump({'pyramid': pyramid_options}, default_flow_style=False)
    }
    with open(mapchete_template, 'r') as config_template:
        config = Template(config_template.read())
        customized_config = config.substitute(substitute_elements)
    with open(mapchete_file, 'w') as target_config:
        target_config.write(customized_config) 
开发者ID:ungarj,项目名称:mapchete,代码行数:44,代码来源:create.py


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