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


Python yaml.CDumper方法代码示例

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


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

示例1: add_rom

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def add_rom(codename, link, info):
    update = {}
    file_size = naturalsize(int(get(link, stream=True).headers['Content-Length']))
    file = link.split('/')[-1]
    version = link.split('/')[3]
    android = link.split('_')[-2]
    update.update({"android": android})
    update.update({"codename": codename})
    update.update({"device": info['name']})
    update.update({"download": link})
    update.update({"filename": file})
    update.update({"size": file_size})
    update.update({"md5": "null"})
    update.update({"version": version})
    DATA.append(update)
    with open(f'stable_fastboot/{codename}.yml', 'w', newline='\n') as output:
        yaml.dump(update, output, Dumper=yaml.CDumper) 
开发者ID:XiaomiFirmwareUpdater,项目名称:miui-updates-tracker,代码行数:19,代码来源:ao.py

示例2: archive

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def archive(update: dict):
    """Append new update to the archive"""
    codename = update['codename']
    link = update['download']
    version = update['version']
    branch = get_branch(version)
    rom_type = 'recovery' if update['filename'].endswith('.zip') else 'fastboot'
    try:
        with open(f'archive/{branch}_{rom_type}/{codename}.yml', 'r') as yaml_file:
            data = yaml.load(yaml_file, Loader=yaml.CLoader)
            data[codename].update({version: link})
            data.update({codename: data[codename]})
            with open(f'archive/{branch}_{rom_type}/{codename}.yml', 'w') as output:
                yaml.dump(data, output, Dumper=yaml.CDumper)
    except FileNotFoundError:
        data = {codename: {version: link}}
        with open(f'archive/{branch}_{rom_type}/{codename}.yml', 'w') as output:
            yaml.dump(data, output, Dumper=yaml.CDumper) 
开发者ID:XiaomiFirmwareUpdater,项目名称:miui-updates-tracker,代码行数:20,代码来源:tracker.py

示例3: save_settings

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def save_settings(self):
    with open(self.settings_path, "w") as f:
      yaml.dump(self.settings, f, default_flow_style=False, Dumper=yaml.Dumper) 
开发者ID:LagoLunatic,项目名称:wwrando,代码行数:5,代码来源:randomizer_window.py

示例4: upload_object_to_container

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def upload_object_to_container(
        self, block_blob_client, container_name, blob_name, obj
    ):
        """
        Uploads a local file to an Azure Blob storage container.

        :param block_blob_client: A blob service client.
        :type block_blob_client: `azure.storage.blob.BlockBlobService`
        :param str container_name: The name of the Azure Blob storage container.
        :param str file_path: The local path to the file.
        :rtype: `azure.batch.models.ResourceFile`
        :return: A ResourceFile initialized with a SAS URL appropriate for Batch
        tasks.
        """
        # print("Uploading file {} to container [{}]...".format(blob_name, container_name))

        block_blob_client.create_blob_from_text(
            container_name, blob_name, dump(obj, Dumper=Dumper)
        )

        sas_token = block_blob_client.generate_blob_shared_access_signature(
            container_name,
            blob_name,
            permission=azureblob.BlobPermissions.READ,
            expiry=datetime.datetime.utcnow()
            + datetime.timedelta(hours=self.config.STORAGE_ACCESS_DURATION_HRS),
        )

        sas_url = block_blob_client.make_blob_url(
            container_name, blob_name, sas_token=sas_token
        )

        return models.ResourceFile(http_url=sas_url, file_path=blob_name) 
开发者ID:microsoft,项目名称:SparseSC,代码行数:35,代码来源:gradient_batch_client.py

示例5: __init__

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def __init__(self, common_data, K):
        subprocess.call(["python", "-m", "SparseSC.cli.scgrad", "start"])
        # CREATE THE RESPONSE FIFO
        # replace any missing values with environment variables
        self.common_data = common_data
        self.K = K

        # BUILT THE TEMPORARY FILE NAMES
        self.tmpDirManager = tempfile.TemporaryDirectory()
        self.tmpdirname = self.tmpDirManager.name
        print("Created temporary directory:", self.tmpdirname)
        self.GRAD_PART_FILE = os.path.join(self.tmpdirname, _GRAD_PART_FILE)
        self.CONTAINER_OUTPUT_FILE = os.path.join(self.tmpdirname, _CONTAINER_OUTPUT_FILE)

        # WRITE THE COMMON DATA TO FILE:
        with open(os.path.join(self.tmpdirname, _GRAD_COMMON_FILE), "w") as fh:
            fh.write(dump(self.common_data, Dumper=Dumper))


#--         # A UTILITY FUNCTION
#--         def tarify(x,name):
#--             with tarfile.open(os.path.join(self.tmpdirname, '{}.tar.gz'.format(name)), mode='w:gz') as dest_file:
#--                 for i, k in itertools.product( range(len(x)), range(len(x[0]))):
#--                     fname = 'arr_{}_{}'.format(i,k)
#--                     array_bytes = x[i][k].tobytes()
#--                     info = tarfile.TarInfo(fname)
#--                     info.size = len(array_bytes)
#--                     dest_file.addfile(info,io.BytesIO(array_bytes) )
#-- 
#--         tarify(part_data["dA_dV_ki"],"dA_dV_ki") 
#--         tarify(part_data["dB_dV_ki"],"dB_dV_ki") 
#--         import pdb; pdb.set_trace() 
开发者ID:microsoft,项目名称:SparseSC,代码行数:34,代码来源:local_grad_daemon.py

示例6: save_to_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def save_to_yaml(signatures: Sequence[Type[GeneSignature]], fname: str):
    """

    :param signatures:
    :return:
    """
    with openfile(fname, 'w') as f:
        f.write(dump(signatures, default_flow_style=False, Dumper=Dumper)) 
开发者ID:aertslab,项目名称:pySCENIC,代码行数:10,代码来源:utils.py

示例7: dump_to_fileobj

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def dump_to_fileobj(self, obj, file, **kwargs):
        kwargs.setdefault('Dumper', Dumper)
        yaml.dump(obj, file, **kwargs) 
开发者ID:open-mmlab,项目名称:mmcv,代码行数:5,代码来源:yaml_handler.py

示例8: dump_to_str

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def dump_to_str(self, obj, **kwargs):
        kwargs.setdefault('Dumper', Dumper)
        return yaml.dump(obj, **kwargs) 
开发者ID:open-mmlab,项目名称:mmcv,代码行数:5,代码来源:yaml_handler.py

示例9: main

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def main():
    """
    MIUI Updates Tracker
    """
    initialize()
    names, sr_devices, sf_devices, wr_devices, wf_devices = load_devices()
    versions = {'stable_fastboot': {'branch': 'F', 'devices': sf_devices},
                'stable_recovery': {'branch': '1', 'devices': sr_devices},
                'weekly_fastboot': {'branch': 'X', 'devices': wf_devices},
                'weekly_recovery': {'branch': '0', 'devices': wr_devices}}
    for name, data in versions.items():
        # fetch based on version
        if "_fastboot" in name:
            fastboot.fetch(data['devices'], data['branch'], f'{name}/', names)
        elif "_recovery" in name:
            recovery.get_roms(name)
        print("Fetched " + name.replace('_', ' '))
        # Merge files
        print("Creating YAML")
        yaml_files = [x for x in sorted(glob(f'{name}/*.yml')) if not x.startswith('old_')]
        yaml_data = []
        for file in yaml_files:
            with open(file, "r") as yaml_file:
                yaml_data.append(yaml.load(yaml_file, Loader=yaml.CLoader))
        with open(f'{name}/{name}', "w") as output:
            yaml.dump(yaml_data, output, Dumper=yaml.CDumper)
        # Cleanup
        for file in glob(f'{name}/*.yml'):
            remove(file)
        if path.exists(f'{name}/{name}'):
            rename(f'{name}/{name}', f'{name}/{name}.yml') 
开发者ID:XiaomiFirmwareUpdater,项目名称:miui-updates-tracker,代码行数:33,代码来源:EOL.py

示例10: merge_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def merge_yaml(name: str):
    """
    merge all devices yaml files into one file
    """
    print("Creating YAML files")
    yaml_files = [x for x in sorted(glob(f'{name}/*.yml')) if not x.endswith('recovery.yml')
                  and not x.endswith('fastboot.yml')]
    yaml_data = []
    for file in yaml_files:
        with open(file, "r") as yaml_file:
            yaml_data.append(yaml.load(yaml_file, Loader=yaml.CLoader))
    with open(f'{name}/{name}', "w") as output:
        yaml.dump(yaml_data, output, Dumper=yaml.CDumper)
    if path.exists(f'{name}/{name}'):
        rename(f'{name}/{name}', f'{name}/{name}.yml') 
开发者ID:XiaomiFirmwareUpdater,项目名称:miui-updates-tracker,代码行数:17,代码来源:tracker.py

示例11: _to_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def _to_yaml(data):
    """Dump data into a YAML string."""
    from yaml import dump
    try:
        from yaml import CDumper as Dumper
    except ImportError:
        from yaml import Dumper
    return dump(data, Dumper=Dumper) 
开发者ID:zhihu,项目名称:tache,代码行数:10,代码来源:serializer.py

示例12: _nc_dict_encoder

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def _nc_dict_encoder(data):
        dump_options = {'Dumper': _DictYamlDumper, 'line_break': '\n', 'indent': 4}
        data_as_string = yaml.dump(data, **dump_options)
        packaged_string = nc_string_encoder(data_as_string)
        return packaged_string 
开发者ID:choderalab,项目名称:openmmtools,代码行数:7,代码来源:iodrivers.py

示例13: write_tags

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def write_tags(tags, tags_file_path=constants.default_tags_file):
    """
    Writes tags to tags_file_path

    Arguments:
      - tags (dict): the tags to write
      - tags_file_path (string): path to which tag data will be written

    Returns: None
    """
    with open(tags_file_path, mode="w+") as f:
        data = yaml.dump(tags, Dumper=Dumper, default_flow_style=False)
        f.write(data) 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:15,代码来源:utilities.py

示例14: SaveYaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def SaveYaml(filename,demo):
    '''
    SaveYaml
    Really simple function to quickly load from a yaml file
    '''

    stream = file(filename,'w')
    yaml.dump(demo,stream,Dumper=Dumper) 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:10,代码来源:types.py

示例15: serialize_report

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import CDumper [as 别名]
def serialize_report(self, output_file, report_data):
        with open(output_file, "wb") as fp:
            dump(report_data, fp, Dumper=Dumper)


    #-------------------------------------------------------------------------- 
开发者ID:blackye,项目名称:luscan-devel,代码行数:8,代码来源:yaml.py


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