Repository cleanup

This commit is contained in:
Wiktor Mazur
2019-10-20 14:59:45 +02:00
parent a15f7ae92c
commit e14dbf66dc
36 changed files with 180 additions and 102 deletions
+48
View File
@@ -0,0 +1,48 @@
import os
import sys
import toml
CFG_VERSION = '0.2'
default = """
[window]
width = 300
height = 230
font-size = '10px'
opacity = 0.5
[app]
skip_non_party_players = true
[config]
# do not change
version = '%s'
""" % (CFG_VERSION)
_script_path = sys.argv[0] # pyinstaller creates tmpdir for python files, thus this is the way to get executable path
_config = None
def config():
global _script_path
global _config
if _config:
return _config
conf_file = os.path.join(os.path.dirname(
_script_path), 'albion-online-stats.cfg')
try:
with open(conf_file, "r") as cfg_file:
cfg = toml.load(cfg_file)
if cfg['config']['version'] != CFG_VERSION:
print('version changed')
raise Exception('Version changed')
return cfg
except(Exception) as e:
with open(conf_file, "w") as cfg_file:
cfg_file.write(default)
return toml.loads(default)
return {}