def write_yaml(path, dictionary): """ Writes a dictionary to a file in .yaml format. Parameters ---------- path: :obj:`str` Location to where the .yaml should be written. dictionary: :obj:`dict` Dictionary that should be stored in the file.""" with open(path) as f: yamldump(dictionary, f)
def Main(): database = [] fp = open('/tmp/data1.yaml', 'w') for i in range(10): data = {} data['a'] = [i, i * i, i * i * i] data['b'] = [str(i), str(i * i)] database.append(data) fp.write(yamldump([data], Dumper=Dumper)) fp.flush() fp.close() open('/tmp/data2.yaml', 'w').write(yamldump(database, Dumper=Dumper))
def dump(self, ordoc): """Return a string yaml formated native Open Rocket Doc """ # We want some control over what is printed # (not a naive dump of everything in every object) # So we build a dictionary first doc = {} # rocket top level if type(ordoc) is rdoc.Rocket: doc['rocket'] = {'name': ordoc.name} if ordoc.description: doc['rocket']['description'] = ordoc.description if ordoc.manufacturer: doc['rocket']['manufacturer'] = ordoc.manufacturer doc['rocket']['aerodynamics'] = ordoc.aero_properties doc['rocket']['stages'] = [] for stage in ordoc.stages: s = {'name': stage.name} s['components'] = [] for component in stage.components: s['components'].append(self._component_dict(component)) doc['rocket']['stages'].append(s) return yamldump(doc, default_flow_style=False)
def setup(self): """Save module versions.""" fname = "{}_config.yml".format(self.root) f = open(fname, "w") f.write(yamldump(self.pipeline_config)) f.close() self.done = True
def output_fs_estimate(data): fs = [ Stats(), Fat32(), ExFat(), UnixFS(), Ext2FS(), F2FS(), FFS(), Ext4FS() ] for i in data: for f in fs: f.fallocate(i) pdict = OrderedDict() for f in fs: pdict[f'{f}'] = f.to_dict() #pprint(pdict, indent=4, width=os.get_terminal_size().columns) print(yamldump(pdict, width=os.get_terminal_size().columns))
def SaveYAML(d, file_name, except_cnv=lambda y:y): OpenW(file_name).write(yamldump(ToStdType(d,except_cnv), Dumper=YDumper))
def SaveYAML(d, file_name, except_cnv=lambda y:y, interactive=True): OpenW(file_name,interactive=interactive).write(yamldump(ToStdType(d,except_cnv), Dumper=YDumper))
def SaveYAML(d, file_name, except_cnv=lambda y: y): file(file_name, 'w').write(yamldump(ToStdType(d, except_cnv), Dumper=Dumper))
def write_back_yaml(data, filename): with open(filename, 'w') as output_yaml: yamldump(data, output_yaml)
def GetSHA1HashOfDict(d): d_yaml = yamldump(d, Dumper=YDumper) return hashlib.sha1(d_yaml).hexdigest()