/
config.py
41 lines (34 loc) · 1.63 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'''
Created on Feb 25, 2015
@author: James Culbertson
'''
from ConfigParser import ConfigParser
import constants as c
import os.path
class Config(object):
'''
Loads and saves the configurations files.
User config is read and written on demand.
'''
def __init__(self):
self.user_config = {}
self.load_user_config()
def save_user_config(self):
cfg_file = open(c.CONFIG_USER + ".ini","w")
config = ConfigParser()
config.add_section(c.CONFIG_USER)
if c.CONFIG_USER_LAST_TEMPLATE_FILE in self.user_config:
config.set(c.CONFIG_USER, c.CONFIG_USER_LAST_TEMPLATE_FILE, self.user_config[c.CONFIG_USER_LAST_TEMPLATE_FILE])
if c.CONFIG_USER_LAST_SAVE_FOLDER in self.user_config:
config.set(c.CONFIG_USER, c.CONFIG_USER_LAST_SAVE_FOLDER, self.user_config[c.CONFIG_USER_LAST_SAVE_FOLDER])
config.write(cfg_file)
cfg_file.close()
def load_user_config(self):
if os.path.exists(c.CONFIG_USER + ".ini"):
config = ConfigParser()
config.read(c.CONFIG_USER + ".ini")
if config.has_section(c.CONFIG_USER):
if config.has_option(c.CONFIG_USER, c.CONFIG_USER_LAST_TEMPLATE_FILE):
self.user_config[c.CONFIG_USER_LAST_TEMPLATE_FILE] = config.get(c.CONFIG_USER, c.CONFIG_USER_LAST_TEMPLATE_FILE).replace('"','')
if config.has_option(c.CONFIG_USER, c.CONFIG_USER_LAST_SAVE_FOLDER):
self.user_config[c.CONFIG_USER_LAST_SAVE_FOLDER] = config.get(c.CONFIG_USER, c.CONFIG_USER_LAST_SAVE_FOLDER).replace('"','')