Move python to scripts dir
This commit is contained in:
parent
e85110f4eb
commit
a8a23150d9
6 changed files with 5 additions and 6 deletions
30
scripts/create_listing.py
Normal file
30
scripts/create_listing.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from json import dumps
|
||||
from pathlib import Path
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
SKIPLIST = ('_DIRECTORY.json',)
|
||||
DIRECTORIES_SUPPLIED = ['www/img', 'www/audio', 'www/maps', 'www/data', 'www/Languages']
|
||||
|
||||
|
||||
def legal_file_name(fname: str) -> bool:
|
||||
return not (fname in SKIPLIST or fname.startswith('.'))
|
||||
|
||||
|
||||
def create_listing(path: Path, indent: int = 0) -> None:
|
||||
files = [n for n in os.listdir(path) if legal_file_name(n)]
|
||||
with open(path / '_DIRECTORY.json', 'w') as fp:
|
||||
fp.write(dumps(files))
|
||||
print(' ' * (indent * 2) + f'>> Wrote listing for {path}')
|
||||
|
||||
for file in files:
|
||||
rel_path = path / Path(file)
|
||||
if rel_path.is_dir():
|
||||
create_listing(rel_path, indent + 1)
|
||||
|
||||
|
||||
for directory in DIRECTORIES_SUPPLIED:
|
||||
print(f'>> Beginning of writing listing of the {directory}')
|
||||
time.sleep(2)
|
||||
create_listing(Path(directory), 1)
|
Loading…
Add table
Add a link
Reference in a new issue