예제 #1
0
    def read_all_sequences(
            cls,
            input_dir: str,
            executor: futures.Executor = None
    ) -> typing.List[typing.List[knowledge_graph.KnowledgeGraph]]:
        """Loads all knowledge-graph sequences that are discovered in the specified directory.

        Args:
            input_dir (str): The path of the directory that is being searched.
            executor (futures.Executor, optional): An optional executor for loading multiple knowledge-graph sequences
                concurrently.

        Returns:
            list[list[:class:`knowledge_graph.KnowledgeGraph`]]: All knowledge-graph sequences that were found in
                ``input_dir``.

        Raises:
            ValueError: If the specified directory does not exist.
        """
        # sanitize args
        input_dir = str(input_dir)
        if not os.path.isdir(input_dir):
            raise ValueError("The specified <input_dir> does not exist: '{}'!".format(input_dir))
        insanity.sanitize_type("executor", executor, futures.Executor, none_allowed=True)
    
        # find all knowledge-graph sequences in the input directory
        all_seq = io.find_knowledge_graph_sequences(input_dir)
    
        # load all knowledge graphs that were found
        if executor is None:
            return [cls.read_sequence(input_dir, seq) for seq in all_seq]
        else:
            all_seq = [os.path.join(input_dir, seq) for seq in all_seq]
            return list(executor.map(cls._read_seq_from_one, all_seq))
예제 #2
0
def convert_file(conf: GeneratorConfig, executor: Executor, template: Template,
                 file: str) -> typing.Optional[typing.Tuple[str, str, str]]:
    file = pathlib.Path(file)
    output_file = pathlib.Path('{}/{}'.format(
        conf.temporary_generated_contents_directory, file))

    if file.is_dir():
        print('  mkdir: {}'.format(file))
        output_file.mkdir(parents=True, exist_ok=True)
        executor.map(lambda f: convert_file(conf, executor, template, str(f)),
                     output_file.glob('*'))
        return None

    file_ext = file.suffix
    if file_ext in ['.md', '.markdown']:
        print('  markdown: {}'.format(file))
        output_file = pathlib.Path('{}/{}.html'.format(
            conf.temporary_generated_contents_directory, file.stem))
        return __convert_markdown_file(conf, template, str(file), output_file)

    print('  copy: {}'.format(file))
    shutil.copy(str(file), str(output_file))
    return None
예제 #3
0
파일: ops.py 프로젝트: ms-jpq/chadtree
def copy(pool: Executor, operations: Mapping[PurePath, PurePath]) -> None:
    _op = lambda op: _copy(*op)
    tuple(pool.map(_op, operations.items()))
예제 #4
0
파일: ops.py 프로젝트: ms-jpq/chadtree
def remove(pool: Executor, paths: Iterable[PurePath]) -> None:
    tuple(pool.map(_remove, paths))
예제 #5
0
파일: ops.py 프로젝트: ms-jpq/chadtree
def new(pool: Executor, paths: Iterable[PurePath]) -> None:
    tuple(pool.map(_new, paths))
예제 #6
0
파일: ops.py 프로젝트: ms-jpq/chadtree
def mkdir(pool: Executor, paths: Iterable[PurePath]) -> None:
    tuple(pool.map(_mkdir, paths))