Move python scripts outside of game dir

This commit is contained in:
OleSTEEP 2024-01-15 18:17:04 +03:00
parent 6b717a39f7
commit 8ea7a858d0
2 changed files with 2 additions and 2 deletions

View file

@ -1,30 +0,0 @@
from json import dumps
from pathlib import Path
import os
import time
SKIPLIST = ('_DIRECTORY.json',)
DIRECTORIES_SUPPLIED = ['img', 'audio', 'maps', '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)

View file

@ -1,27 +0,0 @@
# flake8: noqa
import os
from pathlib import Path
def replace_special_symbols(s: str) -> str:
return s.replace('!', '_PIDOR_').replace('[', '_SUPER_').replace(']', '_PEDIK_').replace('$', '_SEMENCUM_').replace('%', '_RAZRABI_PIDORASI').replace('(', '_SOSI_').replace(')', '_BEBRA_')
DIRECTORY = Path('img')
def cast_symbols(dir_: Path, indent: int = 0) -> int:
renamed = 0
for file_name in os.listdir(dir_):
replaced = replace_special_symbols(file_name)
file_path = dir_ / replaced
if replaced != file_name:
os.rename(dir_ / file_name, file_path)
renamed += 1
if file_path.is_dir():
renamed += cast_symbols(file_path, 1)
print(' ' * (indent * 2) + f'>> renamed {renamed} files in {dir_}')
return renamed
cast_symbols(DIRECTORY, 0)