本文整理匯總了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)
示例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)
示例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)
示例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)
示例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()
示例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))
示例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)
示例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)
示例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')
示例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')
示例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)
示例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
示例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)
示例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)
示例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)
#--------------------------------------------------------------------------