PushService: Initial release
[enigma2-plugins.git] / pushservice / src / Plugins / CrashLog.py
1 # Config
2 from Components.config import ConfigYesNo, NoSave
3
4 # Plugin internal
5 from Plugins.Extensions.PushService.__init__ import _
6 from Plugins.Extensions.PushService.PluginBase import PluginBase
7
8 # Plugin specific
9 import os
10
11
12 CRASHLOG_DIR = '/media/hdd'
13
14 SUBJECT = _("Found CrashLog(s)")
15 BODY    = _("Crashlog(s) are attached")
16
17
18 class CrashLog(PluginBase):
19         
20         ForceSingleInstance = True
21         
22         def __init__(self):
23                 # Is called on instance creation
24                 PluginBase.__init__(self)
25                 self.crashlogs = []
26
27                 # Default configuration
28                 self.setOption( 'delete_logs', NoSave(ConfigYesNo( default = False )), _("Delete crashlog(s)") )
29
30         def run(self):
31                 # Return Header, Body, Attachment
32                 # If empty or none is returned, nothing will be sent
33                 # Search crashlog files
34                 self.crashlogs = []
35                 text = "Found crashlogs, see attachment(s)\n"
36                 for file in os.listdir( CRASHLOG_DIR ):
37                         if file.startswith("enigma2_crash_") and file.endswith(".log"):
38                                 crashlog = os.path.join( CRASHLOG_DIR, file )
39                                 self.crashlogs.append(crashlog)
40                 if self.crashlogs:
41                         return SUBJECT, BODY, self.crashlogs
42                 else:
43                         return None
44
45         # Callback functions
46         def success(self):
47                 # Called after successful sending the message
48                 if self.getValue('delete_logs'):
49                         # Delete crashlogs
50                         for crashlog in self.crashlogs[:]:
51                                 if os.path.exists( crashlog ):
52                                         os.remove( crashlog )
53                                 self.crashlogs.remove( crashlog )
54                 else:
55                         # Rename crashlogs to avoid resending it
56                         for crashlog in self.crashlogs[:]:
57                                 if os.path.exists( crashlog ):
58                                         # Adapted from autosubmit - instead of .sent we will use .pushed
59                                         currfilename = str(os.path.basename(crashlog))
60                                         newfilename = "/media/hdd/" + currfilename + ".pushed"
61                                         os.rename(crashlog,newfilename)
62                                 self.crashlogs.remove( crashlog )
63
64         def error(self):
65                 # Called after message sent has failed
66                 self.crashlogs = []