2 from Components.config import ConfigYesNo, NoSave
5 from Plugins.Extensions.PushService.__init__ import _
6 from Plugins.Extensions.PushService.PluginBase import PluginBase
12 CRASHLOG_DIR = '/media/hdd'
14 SUBJECT = _("Found CrashLog(s)")
15 BODY = _("Crashlog(s) are attached")
18 class CrashLog(PluginBase):
20 ForceSingleInstance = True
23 # Is called on instance creation
24 PluginBase.__init__(self)
27 # Default configuration
28 self.setOption( 'delete_logs', NoSave(ConfigYesNo( default = False )), _("Delete crashlog(s)") )
31 # Return Header, Body, Attachment
32 # If empty or none is returned, nothing will be sent
33 # Search crashlog files
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)
41 return SUBJECT, BODY, self.crashlogs
47 # Called after successful sending the message
48 if self.getValue('delete_logs'):
50 for crashlog in self.crashlogs[:]:
51 if os.path.exists( crashlog ):
53 self.crashlogs.remove( crashlog )
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 )
65 # Called after message sent has failed