dropping prepending path in scan_dir function

This commit is contained in:
faildev_mode 2023-05-29 16:20:03 +02:00
parent 4c9846329a
commit e519396b3c
No known key found for this signature in database
GPG Key ID: 70845C70C0F5E205
1 changed files with 8 additions and 6 deletions

View File

@ -45,20 +45,21 @@ def mkdir_this(path: str):
for i in to_create:
os.mkdir(i)
def scan_dir(path: str) -> list:
def scan_dir(path: str, orig_path=None) -> list:
"""Iterates recursively through directory and returns list of all files.
Does not follow symlinks
"""
results = []
if not orig_path: orig_path = path
for entry in os.scandir(path):
# we don't want symlinks right now (smart scanning may be added in the future)
if entry.is_symlink(): continue
if entry.is_file():
results.append(entry.path)
results.append(os.path.relpath(entry.path, start=orig_path))
elif entry.is_dir():
results += scan_dir(entry.path)
results += scan_dir(entry.path, orig_path)
return results
@ -74,6 +75,7 @@ def template_for(path: str) -> str:
template = config['templates'][pattern]
return template
if __name__ == '__main__':
os.chdir(sys.path[0])
@ -92,11 +94,11 @@ if __name__ == '__main__':
# add static files to the project
for path in static_files:
print(path)
link_this(path, '../'+os.path.relpath(path, start='static')) # all paths starts with 'static/'
link_this(path, '../html/'+os.path.relpath(path, start='static'))
link_this('static/'+path, '../'+path)
link_this('static/'+path, '../html/'+path)
# now the actual parsing of content files
for path in content_files:
print(path)
template = template_for(os.path.relpath(path, start='content')) # all paths starts with 'content/'
template = template_for(path)
if template: print(' template:', template)