]> Softwares of Agnibho - ddstorm.git/blob - conf.py
First commit
[ddstorm.git] / conf.py
1 #! /usr/bin/python3
2
3 # DDStorm
4 # -------
5 # Copyright (c) 2015 Agnibho Mondal
6 # All rights reserved
7
8 # This file is part of DDStorm.
9
10 # DDStorm is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # DDStorm is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with DDStorm. If not, see <http://www.gnu.org/licenses/>.
22
23 import os, logging
24 from const import *
25 logging.basicConfig(filename=LOG_FILE)
26
27 class Conf:
28 conf={}
29 def __init__(self, filename=CONF_FILE):
30 self.filename=filename
31 self.default()
32 self.read()
33
34 def default(self):
35 self.conf["library_path"]="./library/"
36 self.conf["custom_path"]="./custom/"
37 self.conf["index_path"]="./index/"
38 self.conf["alias_path"]="./alias/"
39 self.conf["module_path"]="./modules/"
40 self.conf["splash_screen"]="yes"
41 self.conf["clean_log"]="no"
42 self.conf["status_message"]="on"
43
44 def read(self):
45 if(os.path.isfile(self.filename)):
46 with open(self.filename) as f:
47 for line in f:
48 line="".join(line.split())
49 if(line.startswith("#")):
50 pass
51 elif(line.startswith("library_path=")):
52 self.conf["library_path"]=line[13:]
53 if(os.path.isdir(self.conf["library_path"])):
54 if(not self.conf["library_path"].endswith("/")):
55 self.conf["library_path"]+="/"
56 elif(line.startswith("custom_path=")):
57 self.conf["custom_path"]=line[12:]
58 if(os.path.isdir(self.conf["custom_path"])):
59 if(not self.conf["custom_path"].endswith("/")):
60 self.conf["custom_path"]+="/"
61 elif(line.startswith("index_path=")):
62 self.conf["index_path"]=line[11:]
63 if(os.path.isdir(self.conf["index_path"])):
64 if(not self.conf["index_path"].endswith("/")):
65 self.conf["index_path"]+="/"
66 elif(line.startswith("alias_path=")):
67 self.conf["alias_path"]=line[11:]
68 if(os.path.isdir(self.conf["alias_path"])):
69 if(not self.conf["alias_path"].endswith("/")):
70 self.conf["alias_path"]+="/"
71 elif(line.startswith("module_path=")):
72 self.conf["module_path"]=line[12:]
73 if(os.path.isdir(self.conf["module_path"])):
74 if(not self.conf["module_path"].endswith("/")):
75 self.conf["module_path"]+="/"
76 elif(line.startswith("splash_screen=")):
77 self.conf["splash_screen"]=line[14:]
78 elif(line.startswith("clean_log=")):
79 self.conf["clean_log"]=line[10:]
80 elif(line.startswith("status_message=")):
81 self.conf["status_message"]=line[15:]
82 else:
83 logging.warning("Unrecognized configuration: "+line)
84
85 def get(self, key=False):
86 if(key):
87 return self.conf[key]
88 else:
89 return self.conf
90 def set(self, key, value):
91 self.conf[key]=value
92
93 def write(self):
94 with open(CONF_FILE, "w") as f:
95 for k in self.conf:
96 print(k+"="+self.conf[k], file=f)
97
98 if(__name__=="__main__"):
99 c=Conf(CONF_FILE)
100 print(c.get())