Move python to scripts dir

This commit is contained in:
OleSTEEP 2024-07-05 00:13:22 +03:00
parent e85110f4eb
commit a8a23150d9
6 changed files with 5 additions and 6 deletions

30
scripts/create_listing.py Normal file
View 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)

21
scripts/generate_icons.py Normal file
View file

@ -0,0 +1,21 @@
#/usr/bin/env python3
import cv2
original_icons = ["ic_launcher_background.png",
"ic_launcher_foreground.png",
"ic_launcher_monochrome.png",
"ic_launcher.png"]
resolutions = [
["ldpi", 36, cv2.INTER_AREA],
["mdpi", 48, cv2.INTER_AREA],
["hdpi", 72, cv2.INTER_AREA],
["xhdpi", 216, cv2.INTER_NEAREST],
["xxhdpi", 324, cv2.INTER_NEAREST]]
for res in resolutions:
for icon in original_icons:
image = cv2.imread(f"res/android/xxxhdpi/{icon}", cv2.IMREAD_UNCHANGED)
print(f"* [{res[0]}] {icon}")
resize = cv2.resize(image, (res[1], res[1]), interpolation=res[2])
cv2.imwrite(f"res/android/{res[0]}/{icon}", resize)

View file

@ -0,0 +1,27 @@
# 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('www/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)