PushService: Controller Updated
[enigma2-plugins.git] / pushservice / src / Controller / OPKGUpdateNotification.py
1 #######################################################################
2 #
3 #    Push Service 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=167779
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 # Config
20 from Components.config import ConfigYesNo, ConfigText, ConfigNumber, NoSave
21
22 # Plugin internal
23 from Plugins.Extensions.PushService.__init__ import _
24 from Plugins.Extensions.PushService.ControllerBase import ControllerBase
25
26 # Plugin specific
27 import os
28 from time import time
29 from Tools.BoundFunction import boundFunction
30 from enigma import eConsoleAppContainer
31
32
33 # Constants
34 SUBJECT = _("OPKG Update Notification")
35 BODY    = _("There are updates available:\n%s")
36
37
38 class OPKGUpdateNotification(ControllerBase):
39         
40         ForceSingleInstance = True
41         
42         def __init__(self):
43                 # Is called on instance creation
44                 ControllerBase.__init__(self)
45                 
46                 # Default configuration
47                 self.setOption( 'selfcheck', NoSave(ConfigYesNo( default = False )), _("Start update check if not done yet") )
48                 
49                 self.data = ""
50                 self.container = eConsoleAppContainer()
51                 try:
52                         self.container_dataAvail_conn = self.container.dataAvail.connect(self.dataAvail)
53                 except:
54                         self.container_dataAvail_conn = None
55                         self.container.dataAvail.append(self.dataAvail)
56                 try:
57                         self.container_appClosed_conn = self.container.appClosed.connect(self.opkgupgradableFinished)
58                 except:
59                         self.container_appClosed_conn = None
60                         self.container.appClosed.append(self.opkgupgradableFinished)
61
62         def run(self, callback, errback):
63                 self.data = ""
64                 self.opkgupgradable()
65                 callback()
66
67         def dataAvail(self, string):
68                 self.data += string
69
70         def opkgupgradable(self):
71                 if self.getValue('selfcheck'):
72                         self.container.execute("opkg update && opkg list-upgradable")
73                 else:
74                         self.container.execute("opkg list-upgradable")
75
76         def opkgupgradableFinished(self, retval=None):
77                 
78                 try:
79                         print "PushService retval: ",str(retval)
80                 except:
81                         pass
82                 try:
83                         print "PushService self.data: ",str(self.data)
84                 except:
85                         pass
86                 
87                 updates = ""
88                 
89                 if self.data:
90                         try:
91                                 for line in self.data.split("\n"):
92                                         print "PushService opkg upgradable data: ",line
93                                         if line.startswith("Inflating"):
94                                                 continue
95                                         if line.startswith("Updated"):
96                                                 continue
97                                         if line.startswith("Downloading"):
98                                                 continue
99                                         if line.startswith("Ign "):
100                                                 continue
101                                         if line.startswith("Get:"):
102                                                 continue
103                                         if line.startswith("Hit "):
104                                                 continue
105                                         if line.startswith("Fetched "):
106                                                 continue
107                                         if line.startswith("Reading "):
108                                                 continue
109                                         if line == '':
110                                                 continue
111                                         updates += line + "\r\n"
112                         except Exception, e:
113                                 updates += "\r\n\r\nException:\r\n" + str(e)
114                                 print "PushService except: ",str(e)
115
116                 if updates:
117                         #callback( SUBJECT, BODY % (updates) )
118                         
119                         #TODO Problem test run won't get the message
120                         # Push mail
121                         from Plugins.Extensions.PushService.plugin import gPushService
122                         if gPushService:
123                                 gPushService.push(self, SUBJECT, BODY % (updates))
124