toxygen/src/settings.py

29 lines
676 B
Python
Raw Normal View History

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