-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass_config.py
72 lines (57 loc) · 1.81 KB
/
class_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
import os
class config:
'''Uso: config.get(nome_variabile)
config.set(nome_variabile, valore_variabile)'''
def get(variabile=None):
var_path = '.config/' + variabile
if os.path.exists(var_path):
return open(var_path).read(os.path.getsize(var_path))
else:
return None
def set(*args):
try:
os.mkdir('.config')
if isLinux is 0:
folderPath = os.getcwd() + '/.config'
os.popen('attrib +S +H ' + folderPath)
except:
pass
variabile = args[0]
var_path = '.config/' + variabile
value = args[1]
try:
overwrite = args[2]
except:
overwrite = False
'''Mode -> w = Sovrascrivo Mode -> a = Sposta puntatore a fine file e scrive'''
mode = 'w'
if overwrite:
mode = 'a'
try:
overWriteFirst = args[3]
except:
overWriteFirst = 0
isOverWriteFirst = 0
if overWriteFirst and os.path.exists(var_path):
toRead = str(open(var_path, 'r').read(os.path.getsize(var_path)))
list1 = toRead.split('\n')
list2 = []
for element in list1:
if len(element) > 3:
list2.append(str(element))
list3 = []
list3.append(str(list2[1]))
list3.append(str(list2[2]))
list3.append(str(list2[3]))
list3.append(str(list2[4]))
list3.append(str(value))
txt = ''
for element in list3:
txt += str(element) + '\n'
txt = txt[:-2]
isOverWriteFirst = 1
value = txt
mode = 'w'
f = open(var_path, mode)
f.write(value)
f.close()