-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud-backup-settings.py
214 lines (205 loc) · 6.95 KB
/
cloud-backup-settings.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
# Cloud Backup - Copyright (C) 2022, TRMSC - https://trmsc1.wordpress.com/
# GNU General Public Licence 3.0 - http://www.gnu.de/documents/gpl-3.0.en.html
import configparser
import numbers
import os
import datetime
import getpass
from pickle import TRUE
version = "v.1.2.1"
def initConfig():
val = readData()
encr = encryptPwd(val)
print ("\n- - - - - - - - - - - - - - - - -")
print ("Last modified: " + val[0] + "\n")
print (" 1 - GENERAL - Change backup directory (" + val[1] + ")")
print (" 2 - GENERAL - Number of stored backups (" + val[2] + ")")
print (" 3 - ACCESS - Set username (" + val[3] + ")")
print (" 4 - ACCESS - Set password (" + encr + ")")
print (" 5 - ADRESSBOOK - Activate adressbook backup (" + val[5] + ")")
print (" 6 - ADRESSBOOK - Adressbook url (" + val[6] + ")")
print (" 7 - CALENDAR - Activate calendar backup (" + val[7] + ")")
print (" 8 - CALENDAR - Calendar url (" + val[8] + ")")
print (" 9 - CALENDAR - Calendar list (" + val[9] + ")")
print ("10 - DATA - Activate data backup from desktop client (" + val[10] + ")")
print ("11 - DATA - Client path (" + val[11] + ")")
print ("")
check = 0
while check == 0:
item = input ("Press enter to start auto settings, type (x) to exit or type in the number you want to change. ")
if item == "x":
exit()
elif item == "":
startProgress(1, 1)
check = 1
else:
item = int(item)
if item > 0 and item <= 11:
startProgress(2, item)
check = 1
else:
check = 0
return
def readData():
data = os.path.dirname(__file__)
data = data + "/data.ini"
config.read (data)
val = []
x = 0
for key in config["GENERAL"]:
val.append(config["GENERAL"][key])
return (val)
def encryptPwd(val):
encr = ""
x = 0
while x < len(val[4]):
encr += "*"
x += 1
return encr
def startProgress(depart, item):
val = readData()
check = 0
print ("")
# Print items and values
if depart == 1 and item < 12:
percent = (item - 1) * 9
print ("- - - - - - - - - - - - - - -")
print ("### Setting progress: " + str(percent) + "% ###\n")
if item == 1:
place = "directory"
print ("Backup directory is: " + str(val[item]))
if item == 2:
place = "number"
print ("Number of stored backup days: " + str(val[item]))
if item == 3:
place = "user"
print ("Username is: " + str(val[item]))
if item == 4:
encr = encryptPwd(val)
place = "pwd"
print ("Password is: " + encr)
if item == 5:
place = "cardAct"
print ("Adressbook storage activated: " + str(val[item]))
if item == 6:
place = "card"
print ("Adressbook URL is: " + str(val[item]))
if item == 7:
place = "calAct"
print ("Calendar storage activated: " + str(val[item]))
if item == 8:
place = "cal"
print ("Calendar URL is: " + str(val[item]))
if item == 9:
place = "callist"
print ("Calendarlist is: " + str(val[item]))
if item == 10:
place = "clientAct"
print ("Client storage activated: " + str(val[item]))
if item == 11:
place = "client"
print ("Client path is: " + str(val[item]))
if item == 12 and depart == 1:
print ("- - - - - - - - - - - - - - -")
print ("### Setting progress: 100% ###\n")
input ("Congratulations! Setting ist complete! Press enter to return.")
initConfig()
return
# Input actions
if item == 5 or item == 7 or item == 10:
while check == 0:
change = input ("Type (0) for deactivate, (1) for activate or press enter to skip: ")
if change == "0":
change = "no"
check = 1
elif change == "1":
change = "yes"
check = 1
elif change == "":
check = 1
elif item == 4:
change = getpass.getpass ("Type in your password or press enter to skip. Input is hidden: ")
elif item == 9:
change = openCallist ()
else:
if depart == 1:
change = input ("Type in a new value, type (x) to abort or press enter to skip: ")
elif depart == 2:
change = input ("Type in a new value or press enter to abort: ")
change = str(change)
if change == "" and depart == 1:
item = int(item) + 1
startProgress(1, item)
return
elif change == "x" and depart == 1:
initConfig()
return
elif change == "" and depart == 2 and item != 9:
initConfig()
return
else:
config["GENERAL"][place] = change
config["GENERAL"]["date"] = datetime.datetime.now().strftime("%Y-%m-%d / %H-%M")
data = os.path.dirname(__file__)
data = data + "/data.ini"
with open(data, 'w') as configfile:
config.write(configfile)
if depart == 1:
item +=1
startProgress(depart, item)
elif depart == 2:
initConfig()
return
def openCallist ():
val = readData()
calendarlist = val[9].replace('\n', "").split(",")
listcontent = val[9]
choice = "x"
empty = 0
while choice != "":
items = len(calendarlist)
itemsDisp = items + 1
position = 0
print("")
if position == items:
print ("No calendarlists...")
empty = 1
else:
while position < items:
posDisp = position + 1
valDisp = calendarlist[position]
print (str(posDisp) + " - " + valDisp)
position += 1
choice = input("Type in a new calendar name, type an item number for deleting or press enter to skip/ finish. ")
isInt = True
try:
int(choice)
except ValueError:
isInt = False
if isInt and int(choice) < itemsDisp:
choice = int(choice) - 1
del calendarlist[choice]
listcontent = ",".join(calendarlist)
print(listcontent)
elif isInt and int(choice) >= itemsDisp:
print ("CALENDAR DOES NOT EXIST.")
elif choice != "":
if empty == 1:
listcontent = choice
empty = 0
else:
listcontent = listcontent + "," + choice
calendarlist = listcontent.replace('\n', "").split(",")
print (listcontent)
print ("\nOld version: " + val[9])
print ("New version: " + listcontent)
choice = input ("Press (x) to discard changes or press enter to save. ")
if choice == "x":
return val[9]
else:
return listcontent
config = configparser.ConfigParser()
print ("\nWelcome to cloud-backup configuration " + version)
print ("Feel free to visit trmsc1.wordpress.com")
initConfig()