summaryrefslogtreecommitdiff
path: root/src/pyssg/discovery.py
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2021-05-05 09:37:43 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2021-05-05 09:37:43 -0600
commit6f143604c28c3165db35c2cad99a0dc76d7ccdaa (patch)
treeaddf3517732d753bde1c258574318bac51b6ca24 /src/pyssg/discovery.py
parent43ed04c6740a3ac11f7e2fc6d75429951536286e (diff)
Add working file discovery and destination file structure creation
Diffstat (limited to 'src/pyssg/discovery.py')
-rw-r--r--src/pyssg/discovery.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/pyssg/discovery.py b/src/pyssg/discovery.py
new file mode 100644
index 0000000..39c8bb1
--- /dev/null
+++ b/src/pyssg/discovery.py
@@ -0,0 +1,40 @@
+import os
+
+
+def get_file_list(extensions: list[str], exclude: list[str]=None) -> list[str]:
+ cwd = os.getcwd()
+
+ out = []
+ for root, dirs, files in os.walk(cwd):
+ if exclude is not None:
+ dirs[:] = [d for d in dirs if d not in exclude]
+
+ for f in files:
+ if f.endswith(tuple(extensions)):
+ out.append(os.path.join(root, f))
+
+ return out
+
+
+def get_dir_structure(exclude: list[str]=None) -> list[str]:
+ cwd = os.getcwd()
+
+ out = []
+ for root, dirs, files in os.walk(cwd):
+ if exclude is not None:
+ dirs[:] = [d for d in dirs if d not in exclude]
+
+ for d in dirs:
+ if root in out:
+ out.remove(root)
+ out.append(os.path.join(root, d).replace(cwd, ''))
+
+ return out
+
+
+def get_all_files():
+ md_files = get_file_list(['.md', '.markdown'], ['templates'])
+ html_files = get_file_list(['.html'], ['templates'])
+ dirs = get_dir_structure(['templates'])
+
+ return (dirs, md_files, html_files)