def save_file(entry): """ Save submission to file """ name = entry['Name'].lower().replace(' ', '-') yaml = YAML() yaml.default_flow_style = False yaml.explicit_start = True yaml.sort_keys = False yaml.indent(mapping=2, offset=2, sequence=2) with open( os.path.join('entries', f'{name}-{datetime.datetime.now()}.yaml'), 'w') as yaml_file: yaml.dump(entry, yaml_file)
def serialize_config(config, escape_dollar=False, original=None): yaml = YAML(typ='rt') if escape_dollar: yaml.representer.add_representer(str, serialize_string_escape_dollar) yaml.representer.add_representer(six.text_type, serialize_string_escape_dollar) else: yaml.representer.add_representer(str, serialize_string) yaml.representer.add_representer(six.text_type, serialize_string) yaml.representer.add_representer(Config, serialize_dict_type) yaml.representer.add_representer(ManifestItemVersion, serialize_dict_type) yaml.default_flow_style = False yaml.sort_keys = False yaml.preserve_quotes = True yaml.explicit_start = True yaml.sort_base_mapping_type_on_output = False yaml.indent(mapping=2, sequence=4, offset=2) ret = io.StringIO("") yaml.dump(config, ret) return ret.getvalue()
import math import re import subprocess import sys import jsonobject import numpy as np import unidecode from ruamel.yaml import YAML log = logging.getLogger(__name__) ## A faster yaml implementation yaml = YAML(typ="safe") # default, if not specfied, is 'rt' (round-trip) yaml.default_flow_style = False yaml.sort_keys = False yaml.indent = 4 def mix_html_colors(*pairs): """Given tuples (html_color, q), output HTML code of color `sum(q_i * color_i)`""" cs = np.zeros(3) for c, q in pairs: c = c.lstrip("#") assert len(c) == 6 cs += np.array([int(ca, base=16) for ca in re.findall("..", c)]) * q return "#" + "".join(f"{int(x):02X}" for x in cs) @contextlib.contextmanager def log_level(logger, level):