-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
104 lines (98 loc) · 3.88 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from configparser import ConfigParser
import Message
class Config:
def __init__(self):
self.read_Sections = []
self.lastFile = ""
self.linesperpage = 100
self.encoding = 'utf-8'
self.dateformate = '%d.%m.%Y'
def createConfig(self, Sections):
config = ConfigParser()
config.insert_comment('Test')
config['settings'] = {
'lastFile': '',
'linessperpage': '100',
'encoding': 'UTF8'
}
x = 0
for s in Sections:
config['Section' + str(x)] = {
'name': s,
'typ': 'O',
'defaultValues': '',
'allowedValues': 'all',
'allowedcharacter': 'default',
'Description': 'missing'
}
x += 1
with open('config.cfg', 'w') as f:
config.write(f)
def read_Config(self):
parser = ConfigParser()
parser.read('config.cfg')
sections = parser.sections()
for s in sections:
if s == 'settings':
if 'lastfile' in parser.options(s):
self.lastFile = parser.get(s, 'lastfile')
else:
print('Missing LastFile-Option')
if 'linessperpage' in parser.options(s):
self.wordsperpage = parser.get(s, 'linessperpage')
else:
print('Missing linessperpage-Option')
if 'encoding' in parser.options(s):
self.encoding = parser.get(s, 'encoding')
else:
print('Missing encoding-Option')
if 'dateformate' in parser.options(s):
self.dateformate = parser.get(s, 'dateformate')
else:
print('Missing dateformate-Option')
else:
name = "?"
typ = "?"
defaultvalues = ""
allowedvalues = "all"
allowedcharacter = "default"
description = "missing"
hide = "False"
if 'name' in parser.options(s):
name = parser.get(s, 'name')
else:
print("Missing name for: " + s)
if 'typ' in parser.options(s):
typ = parser.get(s, 'typ')
else:
print("Missing typ for: " + s)
if 'defaultvalues' in parser.options(s):
defaultvalues = parser.get(s, 'defaultvalues')
else:
print("Missing defaultvalues for: " + s)
if 'allowedvalues' in parser.options(s):
allowedvalues = parser.get(s, 'allowedvalues')
array = allowedvalues.split(';')
else:
print("Missing allowedvalues for: " + s)
if 'allowedcharacter' in parser.options(s):
allowedcharacter = parser.get(s, 'allowedcharacter')
else:
print("Missing allowedcharacter for: " + s)
if 'description' in parser.options(s):
description = parser.get(s, 'description')
else:
print("Missing description for: " + s)
if 'hide' in parser.options(s):
hide = parser.get(s, 'hide')
else:
print("Missing hide for: " + s)
m = Message.Message(name, typ, defaultvalues, array, allowedcharacter, description, hide,
self.dateformate)
self.read_Sections.append(m)
def save_currentFile(self, file):
config = ConfigParser()
config.read('config.cfg')
config.set('settings', 'lastFile', file)
with open('config.cfg', 'w') as f:
config.write(f)