Exemple #1
0
 def log_diff(self, mod_dir: Path, diff_material: Union[dict, list]):
     if isinstance(diff_material, List):
         diff_material = self.generate_diff(Path, diff_material)
     if diff_material:
         with (mod_dir / 'logs' / self._log_name).open('w', encoding='utf-8') as log:
             dumper = yaml.CSafeDumper
             yaml_util.add_representers(dumper)
             yaml.dump(diff_material, log, Dumper=dumper, allow_unicode=True, encoding='utf-8',
                       default_flow_style=None)
Exemple #2
0
 def log_diff(self, mod_dir: Path, diff_material: Union[dict, List[Path]]):
     if isinstance(diff_material, List):
         diff_material = self.generate_diff(mod_dir, diff_material)
     if diff_material:
         with (mod_dir / 'logs' / self._log_name).open(
                 'w', encoding='utf-8') as log:
             dumper = yaml.CSafeDumper
             yaml_util.add_representers(dumper)
             yaml.dump(diff_material, log, Dumper=dumper)
Exemple #3
0
def byml_to_yml_dir(tmp_dir: Path, ext: str = '.byml'):
    """ Converts BYML files in given temp dir to YAML """
    dumper = yaml.CDumper
    yaml_util.add_representers(dumper)
    for data in tmp_dir.rglob(f'**/*{ext}'):
        yml_data = byml.Byml(data.read_bytes())
        with (data.with_name(data.stem + '.yml')).open(
                'w', encoding='utf-8') as y_file:
            yaml.dump(yml_data.parse(),
                      y_file,
                      Dumper=dumper,
                      allow_unicode=True,
                      encoding='utf-8')
        data.unlink()
Exemple #4
0
def log_modded_maps(tmp_dir: Path,
                    modded_mubins: List[str],
                    no_del: bool = False,
                    link_del: bool = False):
    """Logs modified mainfield maps to a YAML document"""
    diffs = generate_modded_map_log(tmp_dir,
                                    modded_mubins,
                                    no_del=no_del,
                                    link_del=link_del)
    log_file: Path = tmp_dir / 'logs' / 'map.yml'
    log_file.parent.mkdir(parents=True, exist_ok=True)
    dumper = yaml.CSafeDumper
    yaml_util.add_representers(dumper)
    with log_file.open('w', encoding='utf-8') as l_file:
        yaml.dump(diffs, l_file, Dumper=dumper)
Exemple #5
0
def _convert_map_log(log: Path):
    loader = yaml.CLoader
    byu.add_constructors(loader)
    diff = yaml.load(log.read_text("utf-8"), Loader=loader)
    new_diff = {}
    for unit, changes in diff.items():
        new_changes = {
            "add": changes["add"],
            "del": changes["del"],
            "mod":
            {str(hashid): actor
             for hashid, actor in changes["mod"].items()},
        }
        new_diff[unit] = new_changes
    dumper = yaml.CDumper
    byu.add_representers(dumper)
    log.write_text(yaml.dump(new_diff, Dumper=dumper, allow_unicode=True),
                   encoding="utf-8")