forked from oe-mirrors/PlanerFS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
425 lines (384 loc) · 13.4 KB
/
plugin.py
File metadata and controls
425 lines (384 loc) · 13.4 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
######################################
# PlanerFS (beginn 24.10.2010) #
# #
# Enigma2 Plugin #
# #
# Author: shadowrider (fs-plugins) #
# Py3-Version: Mr.Servo (openA.TV) #
######################################
# PYTHON IMPORTS
from configparser import ConfigParser
from datetime import datetime, timedelta
from os import listdir, system, makedirs
from os.path import exists, join
from pickle import dump
from time import localtime, time, strftime
# ENIGMA IMPORTS
from enigma import eTimer
from Components.config import config
from Plugins.Plugin import PluginDescriptor
from Screens.MessageBox import MessageBox
from Screens.Standby import inStandby
from Screens import Standby
from Tools.Directories import copyfile, fileExists
from Tools.Notifications import AddNotification, AddNotificationWithCallback
# PLUGIN IMPORTS
from . import CONFIGPATH, CONFIGFILE, PLUGINPATH, ICSFILE, VCFFILE, ONLINETEXT, VERSION, _ # for localized messages
from .timer import Timer_dats
from .routines import schicht
from .termin import TerminList
from .PFSanzeige import startscreen8
from .PFSCards import PFS_show_card_List7
from .PFSimport import online_import
from .PFSpaint import mspFS_paint
from .PFSwe import PFS_show_we
from .PlanerFS import PlanerFS7
txt = "VERSION: %s\n" % VERSION
try:
from Plugins.Extensions.LCD4linux.module import L4Lelement
L4L = True
except Exception:
L4L = None
txt += "No L4L\n"
if not exists(CONFIGPATH):
makedirs(CONFIGPATH)
if not fileExists(ICSFILE):
copyfile(join(PLUGINPATH, "sample.ics"), ICSFILE)
if not fileExists(VCFFILE):
copyfile(join(PLUGINPATH, "sample.vcf"), VCFFILE)
conf = {
"ext_menu": "True",
"startscreen_plus": "True",
"version": "",
"plfs_list": "",
"timer_on": "On",
"akt_intv": "24",
"startanzeige2": "systemstart",
"timestartstandby": "No",
"kalender_art": "Gregorian",
"vorschaum": "3",
"starttime": "None",
"autosync": "No",
"sec_file": "none",
"cal_menu": "1",
"adr_menu": "1",
"l4l_on": "Yes",
"l4l_lcd": "1",
"l4l_screen": "1",
"l4l_font": "40",
"l_ferien": "0",
"ferien": "0",
"schicht_send_url": "None",
"dat_dir": CONFIGPATH,
"cals_dir": "/tmp/",
"categories": "Keine,Geburtstag,Feiertag,Jahrestag,Hochzeitstag,Keine,Keine,Keine,Keine,Keine",
"cat_color_list": "#00008B,#D2691E,#006400,#696969,#FFD700,#000000,#B22222,#8B8878,#CD0000,#00868B,#f0f8ff,#ff4500,#20343c4f,#deb887,#228B22,#5F9EA0,#DC143C,#F0F8FF,#EEC900",
"z_liste": "0,1,0,1,1,0,0,0,0,0",
}
systemstart = 0
display_size = None
l4l_sets = [1, 1, 40]
plfstimer_list = []
plfs_list = []
configparser = ConfigParser()
if exists(CONFIGFILE):
configparser.read(CONFIGFILE)
if configparser.has_section("settings"):
l1 = configparser.items("settings")
for k, v in l1:
if k == "l4l_lcd":
l4l_sets[0] = int(v)
elif k == "l4l_screen":
l4l_sets[1] = int(v)
elif k == "l4l_font":
l4l_sets[2] = int(v)
elif k == "date_dir":
conf["dat_dir"] = v if v.endswith("/") else "%s/" % v
else:
conf[k] = v
if str(conf["version"]) != VERSION:
configparser.read(CONFIGFILE)
configparser.set("settings", "version", VERSION)
conf["version"] = VERSION
with open(CONFIGFILE, "w") as file1:
configparser.write(file1)
else:
datei = open(CONFIGFILE, "w")
configparser.add_section("settings")
for k, v in conf.items():
configparser.set("settings", k, v)
configparser.write(datei)
datei.close()
onl_lines = []
if exists(ONLINETEXT):
with open(ONLINETEXT, 'r') as fp:
onl_lines = fp.readlines()
else:
with open(ONLINETEXT, "w") as fp:
fp.write("# Internetadressen fuer online-Kalender\n# Aufbau:\n# name = url = calendarNr\n##sample (delete # / entferne #):\n")
fp.write("\nFeiertage_Germany = https://calendar.google.com/calendar/ical/de.german%23holiday%40group.v.calendar.google.com/public/basic.ics\n")
time_timer = Timer_dats(None, None, None)
global akt_intv
if int(conf["akt_intv"]):
akt_intv = int(conf["akt_intv"])
if akt_intv > 1440:
akt_intv = 1440
akt_intv = akt_intv * 60
else:
akt_intv = 0
cal_menu = conf["cal_menu"]
adr_menu = conf["adr_menu"]
startscreen_plus = conf["startscreen_plus"]
class einlesen():
def __init__(self, r=False):
if r:
global plfstimer_list
global plfs_list
fer = None
if str(conf["l_ferien"]) != "0":
fer = (conf["ferien"], conf["l_ferien"])
termine = []
timer = []
schichten = []
erg = 1
if conf["autosync"] == "Yes":
path = ONLINETEXT
if conf["dat_dir"] != CONFIGPATH and exists(conf["dat_dir"] + "PlanerFS_online.txt"):
path = conf["dat_dir"] + "PlanerFS_online.txt"
erg = online_import().run(path, fer, True)
if erg == 0 and not inStandby:
AddNotification(MessageBox, "PlanerFS\n" + _("Error: at least one external file could not be loaded!"), type=MessageBox.TYPE_ERROR, timeout=30)
files = []
if conf["kalender_art"] != "Off":
files.append("kalender")
if conf["sec_file"] != "" and conf["sec_file"] != _("none") and exists(conf["sec_file"]):
files.append(conf["sec_file"])
if exists(conf["dat_dir"]):
for cal_file in listdir(conf["dat_dir"]):
n1 = conf["dat_dir"] + cal_file
if cal_file.endswith(".ics") and n1 not in files:
files.append(n1)
if conf["cals_dir"] != conf["dat_dir"] and exists(conf["cals_dir"]):
for cal_file in listdir(conf["cals_dir"]):
if cal_file.endswith(".ics"):
if (not cal_file.startswith("1ferien") or not cal_file.startswith("2ferien")) or conf["l_ferien"]:
files.append(conf["cals_dir"] + cal_file)
fileliste = []
if len(files):
for file1 in files:
if file1 not in fileliste and exists(file1):
fileliste.append(file1)
TL = TerminList()
l2 = TL.getlists(file1, 0)
termine.extend(l2[0])
timer.extend(l2[1])
if len(l2) == 4:
schichten.extend(l2[3])
if erg and str(conf["schicht_send_url"]) and len(schichten):
schicht1 = schicht().parseSchicht(schichten, "export1")
nl2 = ""
if schicht1 and len(schicht1):
anz = len(schicht1)
for i2 in range(anz):
sh1 = schicht1[i2]
nt = sh1[1].replace(" ", "%20")
if nt == None or nt == "":
nt = "frei"
nl2 += sh1[3].strftime('%d.%m.%Y') + "," + nt + ";"
opt = ' -O /dev/null'
ur = str(conf["schicht_send_url"]) + nl2
com = 'wget "' + ur + '"' + opt
f = open("/tmp/schicht", "w")
f.write(strftime("%d.%m.%y %H:%M:%S", localtime()) + " send schichtdaten\n")
f.close()
system(com)
if L4L is not None and len(schichten):
mspFS_paint(schichten)
if len(termine):
termine.sort(key=lambda x: x[9])
plfstimer_list = timer
plfs_list = termine
class Termin_Timer():
def __init__(self):
self.session = None
self.erstmal = 0
self.aktual_timer = eTimer()
self.startzeit_timer = None
self.display_timer = None
self.MyElements = None
self.pfsstandby = False
def saveSession(self, session):
self.session = session
def standby_on(self):
if inStandby:
self.pfsstandby = False
Standby.inStandby.onHide.append(self.Days)
else:
if not self.pfsstandby:
self.pfsstandby = True
config.misc.standbyCounter.addNotifier(self.standby_start, initial_call=False)
def standby_start(self, configElement):
self.pfsstandby = False
if self.standby_check_timer1:
self.standby_check_timer1.startLongTimer(60)
def Starter(self):
if time() < 1383701983:
self.sttimer = eTimer()
self.sttimer.timeout.get().append(self.datecheck)
self.sttimer.startLongTimer(2)
else:
self.Starter2()
def datecheck(self):
if time() < 1383701983:
self.sttimer = eTimer()
self.sttimer.timeout.get().append(self.datecheck)
self.sttimer.startLongTimer(2)
else:
self.Starter2()
def Starter2(self):
start_s = conf["startanzeige2"].replace("(idle)", "")
global systemstart
self.standby_check_timer1 = None
if self.startzeit_timer:
self.startzeit_timer.stop()
self.startzeit_timer = None
self.run_timer = None
if not exists(ICSFILE):
with open(ICSFILE, "w") as f:
f.write("BEGIN:VCALENDAR\nMETHOD:PUBLISH\nPRODID: -EnigmaII-Plugin / PlanerFS " + conf["version"] + "\nVERSION:2.0")
f.write("\nEND:VCALENDAR")
einlesen(True)
if akt_intv > 0:
self.aktual_timer.timeout.get().append(self.aktual)
self.aktual_timer.startLongTimer(akt_intv)
if conf["timer_on"] == "On" and len(plfstimer_list):
global time_timer
time_timer = Timer_dats(None, None, None)
time_timer.startTimer(self.session, plfstimer_list, None)
if start_s != "None" and "time" in start_s:
st = conf["starttime"].strip().split(':')
sek = ((int(st[0]) * 60) + int(st[1])) # stunde
now = [x for x in localtime()]
sek2 = ((now[3] * 60) + now[4])
start = (sek - sek2) * 60
self.startzeit_timer = eTimer()
self.startzeit_timer.timeout.get().append(self.Days1)
if start < 0:
start = start + 86400
elif start < 20:
start = 86400 - start
self.startzeit_timer.startLongTimer(start)
if "systemstart" in start_s and systemstart == 0:
self.Days()
systemstart = 1
if "standby" in start_s:
self.standby_check_timer1 = eTimer()
self.standby_check_timer1.timeout.get().append(self.standby_on)
self.standby_check_timer1.startLongTimer(60)
self.standby_on()
if L4L is not None and conf["l4l_on"] == "Yes":
self.l4l()
def Days1(self):
if inStandby:
if conf["timestartstandby"] == "Yes" and conf["startanzeige2"] != "standby and time":
Standby.inStandby.onHide.append(self.Days)
else:
self.Days()
def Days(self):
if self.standby_check_timer1:
self.standby_check_timer1.startLongTimer(60)
if len(plfs_list):
AddNotificationWithCallback(check_re, startscreen8, plfs_list, conf["version"])
def aktual(self):
einlesen(True)
if str(conf["timer_on"]) == "On":
time_timer.restart(self.session, plfstimer_list, None)
if L4L and conf["l4l_on"] == "Yes":
self.l4l()
z = datetime.today()
end = datetime(z.year, z.month, z.day, 0, 0, 2) + timedelta(1)
diff = end - z
next2 = diff.seconds
if next2 > akt_intv and akt_intv > 0:
next2 = akt_intv
self.aktual_timer.startLongTimer(next2)
def l4l(self):
global L4L
global display_size
if self.MyElements is None and L4L is not None:
self.display_timer = eTimer()
self.display_timer.timeout.get().append(self.l4l)
if self.MyElements is None:
from Plugins.Extensions.LCD4linux.module import L4Lelement
self.MyElements = L4Lelement()
if display_size is not None and display_size > 0:
if self.display_timer:
self.display_timer.stop()
self.display_timer = None
if len(plfs_list) > 0:
from .PFSl4l import PFS_l4l
PFS_l4l(plfs_list, l4l_sets, conf["vorschaum"], display_size)
else:
display_size = self.MyElements.getResolution(l4l_sets[0])[1]
self.display_timer.startLongTimer(2)
if len(txt):
with open("/tmp/PlanerFS-Errors.txt", "w") as f:
f.write(txt)
txt = ""
t_timer = Termin_Timer()
def uebersicht(session, **kwargs):
einlesen(True)
session.openWithCallback(check_re, startscreen8, plfs_list, VERSION)
def main(session, **kwargs):
session.openWithCallback(check_re, PlanerFS7)
def check_re(session=None, *args):
if session and args:
main(session)
def adress(session, **kwargs):
session.open(PFS_show_card_List7, None, VERSION)
def adress_menu(menuid, **kwargs):
if menuid == "mainmenu":
return [(_("PlanerFS address book"), adress, "PlanerFS address book", 58)]
return []
def pfs_wecker(session, **kwargs):
session.open(PFS_show_we)
def pfs_wecker2(**kwargs):
begin = -1
if len(plfstimer_list) and exists(ICSFILE):
TL = TerminList()
l2 = TL.getlists(ICSFILE, 1)
tim_list = l2[1]
tim_list.sort(key=lambda x: x[10])
for x in tim_list:
if x[10] + (config.recording.margin_before.value * 60) > time():
dump(x, open("/media/hdd/plfs_dstart", "wb"), 1)
begin = x[10] + (config.recording.margin_before.value * 60) + (x[11] * 60)
break
return begin
def calen_menu(menuid, **kwargs):
if menuid == "mainmenu":
return [(_("PlanerFS"), main, "PlanerFS", 57)]
return []
def autostart(**kwargs):
if "session" in kwargs:
session = kwargs["session"]
t_timer.saveSession(session)
t_timer.Starter()
def Plugins(**kwargs):
pfc_list = [PluginDescriptor.WHERE_PLUGINMENU]
pfa_list = [PluginDescriptor.WHERE_PLUGINMENU]
if cal_menu == 2 or cal_menu == 4:
pfc_list.append(PluginDescriptor.WHERE_EXTENSIONSMENU)
if adr_menu == 2 or adr_menu == 4:
pfa_list.append(PluginDescriptor.WHERE_EXTENSIONSMENU)
liste = [PluginDescriptor(where=[PluginDescriptor.WHERE_SESSIONSTART], fnc=autostart, wakeupfnc=pfs_wecker2),
PluginDescriptor(name="PlanerFS", where=pfc_list, icon="PlanerFS.png", description=_("Schedule appointments, view events"), fnc=main),
PluginDescriptor(name=_("PlanerFS address book"), description=_("addresses and phone numbers search, find, manage, and more"), where=pfa_list, icon="PlanerFS_adr.png", fnc=adress), ]
if startscreen_plus == "True":
liste.append(PluginDescriptor(name=_("PlanerFS overview"), where=pfc_list, icon="PlanerFS.png", description=_("Show start screen with overview"), fnc=uebersicht))
if cal_menu == 3 or cal_menu == 4:
liste.append(PluginDescriptor(name="PlanerFS", where=PluginDescriptor.WHERE_MENU, fnc=calen_menu))
if adr_menu == 3 or adr_menu == 4:
liste.append(PluginDescriptor(name="PlanerFS address book", where=PluginDescriptor.WHERE_MENU, fnc=adress_menu))
liste.append(PluginDescriptor(name="PlanerFS alarm clock", where=PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=pfs_wecker))
return liste