summaryrefslogtreecommitdiff
path: root/src/pyssg/discovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyssg/discovery.py')
-rw-r--r--src/pyssg/discovery.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/pyssg/discovery.py b/src/pyssg/discovery.py
index 606c1d0..7fe5964 100644
--- a/src/pyssg/discovery.py
+++ b/src/pyssg/discovery.py
@@ -1,45 +1,44 @@
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):
+def get_file_list(directory: str,
+ extensions: list[str],
+ exclude: list[str]=None) -> list[str]:
+ out: list[str] = []
+ for root, dirs, files in os.walk(directory):
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).replace(cwd, '')[1:])
+ out.append(os.path.join(root, f).replace(directory, '')[1:])
return out
-def get_dir_structure(exclude: list[str]=None) -> list[str]:
- cwd = os.getcwd()
-
- out = []
- for root, dirs, files in os.walk(cwd):
+def get_dir_structure(directory: str,
+ exclude: list[str]=None) -> list[str]:
+ out: list[str] = []
+ for root, dirs, files in os.walk(directory):
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))
+ out.append(os.path.join(root, d))
- return [o.replace(cwd, '')[1:] for o in out]
+ return [o.replace(directory, '')[1:] for o in out]
def get_all_files(src: str) -> tuple[list[str], list[str], list[str]]:
- iwd = os.getcwd()
- os.chdir(src)
-
- md_files = get_file_list(['.md', '.markdown'], ['templates'])
- html_files = get_file_list(['.html'], ['templates'])
- dirs = get_dir_structure(['templates'])
-
- os.chdir(iwd)
+ md_files: list[str] = get_file_list(src,
+ ['.md', '.markdown'],
+ ['templates'])
+ html_files: list[str] = get_file_list(src,
+ ['.html'],
+ ['templates'])
+ dirs: list[str] = get_dir_structure(src,
+ ['templates'])
return (dirs, md_files, html_files)