Skip to content

Commit

Permalink
change path to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
hakaishi committed Dec 16, 2020
1 parent 4090621 commit 7006c80
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
from tkinter.ttk import *
from tkinter import messagebox

from sys import executable
from os.path import join, dirname, basename
from sys import executable, platform
from os.path import join, dirname, basename, expandvars, expanduser, exists
from os import mkdir

try:
from tkinter.ttk import Spinbox
Expand Down Expand Up @@ -167,7 +168,14 @@ def move_dwn(self, e):
def load_file():
"""load settings file"""
try:
with open(join(dirname(executable) if basename(executable) == "tramet" else "", "config"), "r+") as file:
path = ""
if platform in ["nt", "win32"]:
path += join(expandvars("%APPDATA%"), "tramet")
elif platform.startswith("linux"):
path += join(expanduser("~"), ".config", "tramet")
if not exists(path):
mkdir(path)
with open(join(path, "config"), "r+") as file:
d = load(file)
if "profiles" not in d:
d = {"profiles": {}}
Expand All @@ -184,8 +192,15 @@ def save_file(cls, obj):
:param obj: settings object
:type obj: dict
"""
path = ""
if platform in ["nt", "win32"]:
path += join(expandvars("%APPDATA%"), "tramet")
elif platform.startswith("linux"):
path += join(expanduser("~"), ".config", "tramet")
if not exists(path):
mkdir(path)
try:
with open(join(dirname(executable) if basename(executable) == "tramet" else "", "config"), "w+") as file:
with open(join(path, "config"), "w+") as file:
dump(obj, file, indent=4, sort_keys=True)
except Exception as e:
print(e)
Expand Down

0 comments on commit 7006c80

Please sign in to comment.