Move python scripts outside of game dir
This commit is contained in:
parent
6b717a39f7
commit
8ea7a858d0
2 changed files with 2 additions and 2 deletions
30
create_listing.py
Normal file
30
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']
|
||||
|
||||
|
||||
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