def __call__()

in obfuscator-cli/obfuscation_manager.py [0:0]


    def __call__(self, dump_directory: Path, to: Optional[Path],
                 dictionary: List[Path]):
        if not to:
            if query_yes_no('Parameter --to was not provided. '
                            'De-obfuscated files will override the dump'):
                to = dump_directory
            else:
                _LOG.error('Aborting')
                sys.exit(1)
        if dump_directory.is_dir() and to.is_file():
            _LOG.error('If --dump-directory is a directory --to must '
                       'be a directory as well')
            sys.exit(1)
        if dump_directory.is_file():
            to.parent.mkdir(parents=True, exist_ok=True)
            to.touch()
        _LOG.info('Loading dictionary')
        dct = {}
        for i in dictionary:
            try:
                with open(i, 'r') as file:
                    dct.update(json.load(file))
            except Exception as e:
                _LOG.error(f'Could not load {i}: {e}')

        for full, relative in self.yield_files(dump_directory):
            _LOG.info(f'De-obfuscating {full}')
            _path = to if to.is_file() else to / relative
            _path.parent.mkdir(parents=True, exist_ok=True)
            deobfuscator = DeobfuscatorFactory(relative).build()
            if not deobfuscator:
                _LOG.warning(f'Not supported file type: {relative}')
                continue
            deobfuscator.deobfuscate(full).to(_path).using(dct)
        _LOG.info('Done!')