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