diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..257f3c7 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,405 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown.xml b/.idea/markdown.xml new file mode 100644 index 0000000..5648d88 --- /dev/null +++ b/.idea/markdown.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..1d76137 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6a38568 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dragonglass.iml b/dragonglass.iml new file mode 100644 index 0000000..ad3c0a3 --- /dev/null +++ b/dragonglass.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..945a4c1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Jinja2==3.1.3 +Markdown==3.5.2 +MarkupSafe==2.1.5 +PyYAML==6.0.1 diff --git a/src/dragonglass/dragonglass.py b/src/dragonglass/dragonglass.py new file mode 100644 index 0000000..aeb2dd7 --- /dev/null +++ b/src/dragonglass/dragonglass.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import argparse +import sys +from pathlib import Path +from tree import SourceNode + +# The command line parser +parser = argparse.ArgumentParser(prog='dragonglass') +parser.add_argument('source_dir') +parser.add_argument('dest_dir') + + +def main(): + args = parser.parse_args() + + source_dir = Path(args.source_dir).resolve() + if not (source_dir.exists() and source_dir.is_dir()): + print(f"{source_dir} is not a valid directory") + return 1 + + dest_dir = Path(args.dest_dir).resolve() + if dest_dir.exists() and not dest_dir.is_dir(): + print(f"{dest_dir} exists but is not a valid directory") + return 1 + + nodes = SourceNode.generate_list(source_dir) + + # TEMP + for node in nodes: + print(node) + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/src/dragonglass/tree.py b/src/dragonglass/tree.py new file mode 100644 index 0000000..34c064f --- /dev/null +++ b/src/dragonglass/tree.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +# The paths that are always to be ignored. +STATIC_IGNORE = [ + '.obsidian' +] + +MARKDOWN_PAT = '*.md' + + +class SourceNode: + def __init__(self, path, is_dir): + self._path = path + self._is_dir = is_dir + self._is_md = path.match(MARKDOWN_PAT) + + def __str__(self): + return f"SourceNode({self._path}, {self._is_dir}) [is_md={self._is_md}]" + + @classmethod + def generate_list(cls, source_root): + nodes = [] + dirs = [source_root] + while len(dirs) > 0: + current_dir = dirs.pop(0) + for child in current_dir.iterdir(): + rchild = child.relative_to(source_root) + add_me = True + for pat in STATIC_IGNORE: + if rchild.match(pat): + add_me = False + break + if add_me: + nodes.append(SourceNode(rchild, child.is_dir())) + if child.is_dir(): + dirs.append(child) + return nodes