toxygen/src/settings.py

29 lines
676 B
Python
Raw Normal View History

2016-02-16 21:03:37 +01:00
from platform import system
2016-02-16 19:11:56 +01:00
import json
2016-02-16 20:57:45 +01:00
import os
2016-02-16 19:11:56 +01:00
class Settings(object):
def __init__(self):
2016-02-16 20:57:45 +01:00
self.path = Settings.get_default_path() + 'toxygen.json'
with open(self.path) as fl:
2016-02-16 19:11:56 +01:00
data = fl.read()
self.data = json.loads(data)
def __get__(self, attr):
return self.data[attr]
2016-02-16 20:57:45 +01:00
def save(self):
text = json.dumps(self.data)
with open(self.path, 'w') as fl:
fl.write(text)
2016-02-16 19:11:56 +01:00
@staticmethod
def get_default_path():
2016-02-16 21:03:37 +01:00
if system() == 'Linux':
2016-02-16 20:57:45 +01:00
return os.getenv('HOME') + '/.config/tox/'
2016-02-16 21:03:37 +01:00
elif system() == 'Windows':
2016-02-16 20:57:45 +01:00
return os.getenv('APPDATA') + '/Tox/'