From 896ad89b179cd933336e1e5154b1598b550ea32b Mon Sep 17 00:00:00 2001 From: Christian Cwienk Date: Thu, 6 Jan 2022 09:40:49 +0100 Subject: [PATCH 1/3] set executable bit for main.py --- main.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 main.py diff --git a/main.py b/main.py old mode 100644 new mode 100755 From 0cff4ae3764fa4df33287c8e3428ba9ed467484f Mon Sep 17 00:00:00 2001 From: Christian Cwienk Date: Thu, 6 Jan 2022 09:41:22 +0100 Subject: [PATCH 2/3] calculate paths relative to main.py Avoid requiring that PWD be set to repository root. Instead, determine own directory, and calculate resource file paths relative to it. --- data/types.py | 10 ++++++---- main.py | 13 +++++++------ paths.py | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 paths.py diff --git a/data/types.py b/data/types.py index bdc0263..05deea2 100644 --- a/data/types.py +++ b/data/types.py @@ -1,6 +1,8 @@ from enum import IntEnum from json import load +import paths + # The possible serialisation types the game uses and their binary value (as int) class Types(IntEnum): @@ -39,19 +41,19 @@ class Types(IntEnum): # they are not complete, considering I mostly was in it for the items and perks and so on # But still they may contain spoilers considering quite a few dialogues and so on are in # them so read it at your own risk -with open("./data/locals.json", encoding="utf8") as f: +with open(paths.locals_json, encoding="utf8") as f: id_to_name = load(f) # Generic game information -with open("./data/html/items.json", encoding="utf8") as f: +with open(paths.items_json, encoding="utf8") as f: gamedata = load(f) -with open("./data/data.json", encoding="utf8") as f: +with open(paths.data_json, encoding="utf8") as f: jsongamedata = load(f) # Load a list with default items, if those items have special attributes which would otherwise not work # (using the default item) -with open("./data/new_item_data.json", encoding="utf8") as f: +with open(paths.new_item_data_json, encoding="utf8") as f: item_fallback_data = load(f) # A example item in the case of the inventory being empty and people wanting to add items to it diff --git a/main.py b/main.py index f02f8c6..5879b40 100755 --- a/main.py +++ b/main.py @@ -21,11 +21,12 @@ import psutil import pkg_resources from packaging import version +import paths # Set up global variables and the used classes options = {} -hashes = Hashlist("./data/hashes") +hashes = Hashlist(paths.hashes) decoder = Decoder(hashes) encoder = Encoder() savefiles = {} @@ -35,21 +36,21 @@ loaded_items = {} # Load the version number of this application and already create a newversion variable for a later check for updates -with open("./data/version") as f: +with open(paths.version) as f: currentversion = f.read() newversion = currentversion # Load the information about the item version making it possible to fix bugs without having to make a new release # (when no code was changed) -with open("./data/itemversion") as f: +with open(paths.item_version) as f: currentiversion = f.read() newiversion = currentiversion # Load the settings of the settings file def load_settings(): - with open("./data/settings") as f: + with open(paths.settings) as f: global options, newversion, newiversion, web_app_options options = json.load(f) @@ -357,7 +358,7 @@ def save_json_savefile(data, shash): # If we want to dump it as html file we do so here if file.endswith(".html"): - with open('./data/html/dumpskeleton.html', 'r') as placeholderfile: + with open(paths.dump_skeleton_html) as placeholderfile: placeholder = placeholderfile.read() print("Creating HTML file at " + file) @@ -1035,7 +1036,7 @@ def set_settings(settings): if "path" in options: options["path"] = os.path.expandvars(options["path"]) - with open("./data/settings", "w") as f: + with open(paths.settings, "w") as f: json.dump(settings, f) return True diff --git a/paths.py b/paths.py new file mode 100644 index 0000000..3effa99 --- /dev/null +++ b/paths.py @@ -0,0 +1,16 @@ +import os + +own_dir = os.path.abspath(os.path.dirname(__file__)) +data_dir = os.path.join(own_dir, 'data') +html_dir = os.path.join(data_dir, 'html') + +version = os.path.join(data_dir, 'version') +item_version = os.path.join(data_dir, 'itemversion') +hashes = os.path.join(data_dir, 'hashes') +settings = os.path.join(data_dir, 'settings') +locals_json = os.path.join(data_dir, 'locals.json') +data_json = os.path.join(data_dir, 'data.json') +new_item_data_json = os.path.join(data_dir, 'new_item_data.json') + +dump_skeleton_html = os.path.join(html_dir, 'dumpskeleton.html') +items_json = os.path.join(html_dir, 'items.json') From eaf8f5ca4b46037bdbc334f1b2fc08002b6c25ef Mon Sep 17 00:00:00 2001 From: Christian Cwienk Date: Sun, 9 Jan 2022 09:27:11 +0100 Subject: [PATCH 3/3] mark `data` as python package --- data/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 data/__init__.py diff --git a/data/__init__.py b/data/__init__.py new file mode 100644 index 0000000..e69de29