1.0.1: Fix installation-bug (added postinst + prerm)
[enigma2-plugins.git] / epgbackup / src / EPGBackupTools.py
1 # -*- coding: utf-8 -*-
2
3 from Components.config import config
4 from time import localtime
5 from traceback import format_exc
6
7 # for localized messages
8 from . import _
9
10 PLUGIN_VERSION = "1.0.1"
11 def debugOut(outtxt, outfile=None, fmode="aw", forced=False, outPrefix="[EPGBackup]"):
12         try: # fails if called too early during Enigma startup
13                 if config.plugins.epgbackup.enable_debug.value or forced:
14                         ltim = localtime()
15                         headerstr = "%04d%02d%02d %02d:%02d:%02d " %(ltim[0],ltim[1],ltim[2],ltim[3],ltim[4],ltim[5])
16                         outtxt = headerstr + outtxt
17                         outfile = _getLogFilename(outfile)
18                         if outfile != None:
19                                 deb = open(outfile, fmode)
20                                 deb.write("%s %s\n" %(outPrefix, outtxt))
21                         print "%s %s" %(outPrefix, outtxt)
22         except:
23                 pass
24
25 def _getLogFilename(outfile):
26         if outfile == None:
27                 if config.plugins.epgbackup.plugin_debug_in_file.value:
28                         if config.plugins.epgbackup.enable_debug.value:
29                                 ltim = localtime()
30                                 outfile = config.plugins.epgbackup.backup_log_dir.getValue() \
31                                 + "/EPGBackup.log.%04d%02d%02d" %(ltim[0],ltim[1],ltim[2])
32                         else:
33                                 outfile = "/tmp/EPGBackup.log"
34         return outfile
35
36 # Notification-Domain
37 EPGBACKUP_NOTIFICATIONDOMAIN = "EPGBackup"
38 from Tools import Notifications
39 try:
40         Notifications.notificationQueue.registerDomain(EPGBACKUP_NOTIFICATIONDOMAIN, _("EPGBACKUP_NOTIFICATION_DOMAIN"), deferred_callable = True)
41 except:
42         debugOut("Register-Notification-Domain-Error:\n" + str(format_exc()), forced=True)
43
44
45