Skip to content

Commit 25d385f

Browse files
committed
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.
1 parent 896ad89 commit 25d385f

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

main.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import pkg_resources
2323
from packaging import version
2424

25+
own_dir = os.path.abspath(os.path.dirname(__file__))
26+
2527

2628
# Set up global variables and the used classes
2729
options = {}
28-
hashes = Hashlist("./data/hashes")
30+
hashes = Hashlist(os.path.join(own_dir, "data/hashes"))
2931
decoder = Decoder(hashes)
3032
encoder = Encoder()
3133
savefiles = {}
@@ -35,21 +37,21 @@
3537
loaded_items = {}
3638

3739
# Load the version number of this application and already create a newversion variable for a later check for updates
38-
with open("./data/version") as f:
40+
with open(os.path.join(own_dir, "data/version")) as f:
3941
currentversion = f.read()
4042
newversion = currentversion
4143

4244

4345
# Load the information about the item version making it possible to fix bugs without having to make a new release
4446
# (when no code was changed)
45-
with open("./data/itemversion") as f:
47+
with open(os.path.join(own_dir, "data/itemversion")) as f:
4648
currentiversion = f.read()
4749
newiversion = currentiversion
4850

4951

5052
# Load the settings of the settings file
5153
def load_settings():
52-
with open("./data/settings") as f:
54+
with open(os.path.join("data/settings")) as f:
5355
global options, newversion, newiversion, web_app_options
5456
options = json.load(f)
5557

@@ -357,7 +359,7 @@ def save_json_savefile(data, shash):
357359
# If we want to dump it as html file we do so here
358360
if file.endswith(".html"):
359361

360-
with open('./data/html/dumpskeleton.html', 'r') as placeholderfile:
362+
with open(os.path.join(own_dir, 'data/html/dumpskeleton.html'), 'r') as placeholderfile:
361363
placeholder = placeholderfile.read()
362364

363365
print("Creating HTML file at " + file)
@@ -1035,7 +1037,7 @@ def set_settings(settings):
10351037
if "path" in options:
10361038
options["path"] = os.path.expandvars(options["path"])
10371039

1038-
with open("./data/settings", "w") as f:
1040+
with open(os.path.join(own_dir, "data/settings"), "w") as f:
10391041
json.dump(settings, f)
10401042
return True
10411043

0 commit comments

Comments
 (0)