Pin defined paths on tool scripts to root of project

So it can run inside tools folders and on the root folder
This commit is contained in:
Hans5958 2023-07-01 23:39:59 +07:00
parent 0093632d0e
commit a19418b02c
5 changed files with 35 additions and 17 deletions

View File

@ -7,6 +7,7 @@ import json
import math
import traceback
import tqdm
import os
END_NORMAL_IMAGE = "164"
END_WHITEOUT_IMAGE = "166"
@ -420,4 +421,7 @@ def go(path):
if __name__ == '__main__':
go("../web/atlas.json")
while not os.path.exists('README.md'):
os.chdir('..')
go("web/atlas.json")

View File

@ -6,16 +6,20 @@ from jsonschema import validate, RefResolver
from pathlib import Path, PurePosixPath
import os
instance_path = "../../web/atlas.json"
if len(sys.argv) == 1:
while not os.path.exists('README.md'):
os.chdir('..')
instance_path = "web/atlas.json"
# path override as 1st param: validate_json.py path_to_file.json
if (len(sys.argv) > 1):
if len(sys.argv) > 1:
instance_path = sys.argv[1]
schema_path = "../schema/atlas.json"
schema_path = "tools/schema/atlas.json"
# schema override as 2nd param: validate_json.py [...] path_to_schema.json
if (len(sys.argv) > 2):
if len(sys.argv) > 2:
schema_path = sys.argv[2]
relative_path = "file:" + str(PurePosixPath(Path(os.getcwd(), schema_path)))

View File

@ -3,7 +3,10 @@ import os
import secrets
from pathlib import Path
patches_dir = "../data/patches/"
while not os.path.exists('README.md'):
os.chdir('..')
patches_dir = "data/patches/"
Path(patches_dir).mkdir(parents=True, exist_ok=True)
entry = None

View File

@ -9,13 +9,16 @@ out_ids = []
atlas_ids = {}
authors = []
with open('../web/all-authors.txt', 'r', encoding='utf-8') as authors_file:
while not os.path.exists('README.md'):
os.chdir('..')
with open('web/all-authors.txt', 'r', encoding='utf-8') as authors_file:
authors = authors_file.read().strip().split()
with open('../data/read-ids.txt', 'r', encoding='utf-8') as ids_file:
with open('data/read-ids.txt', 'r', encoding='utf-8') as ids_file:
out_ids = ids_file.read().strip().split()
with open('../web/atlas.json', 'r', encoding='utf-8') as atlas_file:
with open('web/atlas.json', 'r', encoding='utf-8') as atlas_file:
atlas_data = json.loads(atlas_file.read())
last_id = 0
@ -26,13 +29,13 @@ for i, entry in enumerate(atlas_data):
if id.isnumeric() and int(id) > last_id and int(id) - last_id < 100:
last_id = int(id)
patches_dir = "../data/patches/"
permanent_patch_file = "temp-atlas.json"
patches_dir = "data/patches/"
permanent_patch_file = "tools/temp-atlas.json"
if not os.path.exists(patches_dir):
print("Patches folder not found. Exiting.")
exit()
base_image_path = os.path.join('..', 'web', '_img', 'canvas', 'place30')
base_image_path = os.path.join('web', '_img', 'canvas', 'place30')
ScaleConfig.image1 = os.path.join(base_image_path, '159.png')
filenames = os.listdir(patches_dir)
@ -111,13 +114,13 @@ for filename in filenames:
traceback.print_exc()
print('Writing...')
with open('../web/atlas.json', 'w', encoding='utf-8') as atlas_file:
with open('web/atlas.json', 'w', encoding='utf-8') as atlas_file:
per_line_entries(atlas_data, atlas_file)
with open('../data/read-ids.txt', 'w', encoding='utf-8') as ids_file:
with open('data/read-ids.txt', 'w', encoding='utf-8') as ids_file:
ids_file.write("\n".join(out_ids) + "\n")
with open('../web/all-authors.txt', 'w', encoding='utf-8') as authors_file:
with open('web/all-authors.txt', 'w', encoding='utf-8') as authors_file:
authors_file.write("\n".join(authors) + "\n")
print('All done.')

View File

@ -34,8 +34,12 @@ from pathlib import Path
import humanize
from datetime import datetime
import secrets
import os
patches_dir = "../data/patches/"
while not os.path.exists('README.md'):
os.chdir('..')
patches_dir = "data/patches/"
Path(patches_dir).mkdir(parents=True, exist_ok=True)
def set_flair(submission, flair):
@ -69,7 +73,7 @@ print("Running...")
existing_ids = []
with open('../data/read-ids.txt', 'r') as edit_ids_file:
with open('data/read-ids.txt', 'r') as edit_ids_file:
for id in [x.strip() for x in edit_ids_file.readlines()]:
existing_ids.append(id)