SeriesPlugin 1.0: First public version
[enigma2-plugins.git] / seriesplugin / src / Logger.py
1 #######################################################################
2 #
3 #    Series Plugin for Enigma-2
4 #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=TBD
6 #
7 #    This program is free software; you can redistribute it and/or
8 #    modify it under the terms of the GNU General Public License
9 #    as published by the Free Software Foundation; either version 2
10 #    of the License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #######################################################################
18
19 from . import _
20
21 import os, sys, traceback
22
23 from Components.config import config
24
25 from Screens.MessageBox import MessageBox
26
27 #import requests
28
29
30 def splog(*args):
31         strargs = ""
32         for arg in args:
33                 if strargs: strargs += " "
34                 strargs += str(arg)
35         print strargs
36         
37         if config.plugins.seriesplugin.write_log.value:
38                 strargs += "\n"
39                 
40                 # Append to file
41                 f = None
42                 try:
43                         f = open(config.plugins.seriesplugin.log_file.value, 'a')
44                         f.write(strargs)
45                         if sys.exc_info()[0]:
46                                 print "Unexpected error:", sys.exc_info()[0]
47                                 traceback.print_exc(file=f)
48                 except Exception as e:
49                         print "SeriesPlugin splog exception " + str(e)
50                 finally:
51                         if f:
52                                 f.close()
53         
54         if sys.exc_info()[0]:
55                 print "Unexpected error:", sys.exc_info()[0]
56                 traceback.print_exc(file=sys.stdout)
57         
58         sys.exc_clear()
59
60
61 class Logger(object):
62         def sendLog(self):
63                 print "[SP sendLog]"
64                 
65                 return
66                 
67                 #TODO MAYBE LATER
68                 ######################################################
69                 
70                 
71                 # Check preconditions
72                 if not config.plugins.seriesplugin.write_log.value:
73                         self.session.open(
74                                 MessageBox,
75                                 _("Enable Logging"),
76                                 type = MessageBox.TYPE_ERROR
77                         )
78                         return
79                 if not config.plugins.seriesplugin.log_file.value:
80                         self.session.open(
81                                 MessageBox,
82                                 _("Specify log file"),
83                                 type = MessageBox.TYPE_ERROR
84                         )
85                         return
86                 
87                 # Avoid "Dreambox User" and "myemail@home.com"
88                 if not(
89                                 ( str(config.plugins.seriesplugin.log_reply_user.value) != str(config.plugins.seriesplugin.log_reply_user.default) ) or
90                                 ( str(config.plugins.seriesplugin.log_reply_mail.value) != str(config.plugins.seriesplugin.log_reply_mail.default) )
91                         ):
92                         self.session.open(
93                                 MessageBox,
94                                 _("Enter user name or user mail"),
95                                 type = MessageBox.TYPE_ERROR
96                         )
97                         return
98                 
99                 if not os.path.exists(config.plugins.seriesplugin.log_file.value):
100                         self.session.open(
101                                 MessageBox,
102                                 _("No log file found"),
103                                 type = MessageBox.TYPE_ERROR
104                         )
105                         return
106                 
107                 MSG_TEXT = "Please consider:\n" \
108                                         + _("I've to spend my free time for this support!\n\n") \
109                                         + _("Have You already checked the problem list:\n") \
110                                         + _("Is the information available at Wunschliste.de / Fernsehserien.de? \n") \
111                                         + _("Does the start time match? \n")
112                 
113                 self.session.openWithCallback(
114                                 self.confirmSend,
115                                 MessageBox,
116                                 MSG_TEXT,
117                                 type = MessageBox.TYPE_YESNO,
118                                 timeout = 60,
119                                 default = False
120                         )
121
122         def confirmSend(self, confirmed):
123                 if not confirmed:
124                         return
125                 
126                 #TODO SEND IT HERE