forked from d4nj1/TLPUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
82 lines (61 loc) · 1.96 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
class TlpConfig:
def __init__(self, raw, linenumber, state, name, value, quote):
self.raw = raw
self.linenumber = linenumber
self.state = state
self.name = name
self.value = value
self.quote = quote
self.newvalue = None
self.newstate = None
def get_raw(self):
return self.raw
def get_linenumber(self):
return self.linenumber
def get_state(self):
return self.state
def get_name(self):
return self.name
def get_value(self):
return self.value
def get_quote(self):
return self.quote
def get_new_value(self):
return self.newvalue
def set_new_value(self, newvalue):
if newvalue != self.value:
self.newvalue = newvalue
else:
self.newvalue = None
def get_new_state(self):
return self.newstate
def set_new_state(self, newstate):
if newstate != self.state:
self.newstate = newstate
else:
self.newstate = None
def get_changed_properties(tlpconfig) -> list:
changedproperties = list()
for configid in tlpconfig:
config = tlpconfig[configid]
newstate = config.get_new_state()
newvalue = config.get_new_value()
if newstate == None and newvalue == None:
continue
newconfigvalue = ''
if newstate != None:
if newstate == False:
newconfigvalue = '#'
else:
if config.get_state() == False:
newconfigvalue = '#'
newconfigvalue = newconfigvalue + config.get_name() + '='
if newvalue != None:
value = config.get_new_value()
else:
value = config.get_value()
if config.get_quote():
value = '\"' + value + '\"'
newconfigvalue += value
changedproperties.append([config.get_raw(), config.get_linenumber(), newconfigvalue])
return changedproperties