From 17ca1c2f2747daf97119e56f2cb4e70487e98456 Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:19 +0430 Subject: [PATCH 1/8] PEP8 double aggressive E401 --- src/ConfigScreen.py | 4 +++- src/Logger.py | 8 ++++++-- src/Modules.py | 7 +++++-- src/PushService.py | 3 ++- src/PushServiceBase.py | 4 +++- src/plugin.py | 4 +++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index 9c7da67..2352d3a 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -16,7 +16,9 @@ # ####################################################################### -import os, sys, traceback +import os +import sys +import traceback # Config from Components.config import * diff --git a/src/Logger.py b/src/Logger.py index 05ebc7e..2881225 100644 --- a/src/Logger.py +++ b/src/Logger.py @@ -21,7 +21,9 @@ import logging -import os, sys, traceback +import os +import sys +import traceback from Components.config import config @@ -147,7 +149,9 @@ def exception(self, *args): 'PS_PopUp_ID_Exception_'+strargs ) - import os, sys, traceback + import os + import sys + import traceback if sys.exc_info()[0]: #exc_type, exc_value, exc_traceback = sys.exc_info() #traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) diff --git a/src/Modules.py b/src/Modules.py index eec152c..e89d0e8 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -16,10 +16,13 @@ # ####################################################################### -import os, sys, traceback +import os +import sys +import traceback # Plugin framework -import imp, inspect +import imp +import inspect # Plugin internal from . import _ diff --git a/src/PushService.py b/src/PushService.py index 90ddd39..e5e2207 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -17,7 +17,8 @@ ####################################################################### import os -import sys, traceback +import sys +import traceback from time import localtime from Components.config import config diff --git a/src/PushServiceBase.py b/src/PushServiceBase.py index 25cb076..1e5ae08 100644 --- a/src/PushServiceBase.py +++ b/src/PushServiceBase.py @@ -16,7 +16,9 @@ # ####################################################################### -import os, sys, traceback +import os +import sys +import traceback from time import localtime, strftime # Config diff --git a/src/plugin.py b/src/plugin.py index 59d127a..2af70d1 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -16,7 +16,9 @@ # ####################################################################### -import os, sys, traceback +import os +import sys +import traceback # Plugin from Plugins.Plugin import PluginDescriptor From c1b9fd4cbe562abc1ea5aa09e32b21d1cd9e1272 Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:20 +0430 Subject: [PATCH 2/8] PEP8 double aggressive E701, E70 and E502 --- src/Controller/FreeSpace.py | 3 ++- src/Modules.py | 3 ++- src/PushService.py | 6 ++++-- src/Services/GNTP.py | 5 +++-- src/Services/SMTP.py | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index cdd53f4..a999413 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -39,7 +39,8 @@ #Adapted from: from Components.Harddisk import findMountPoint def mountpoint(path): path = os.path.realpath(path) - if os.path.ismount(path) or len(path)==0: return path + if os.path.ismount(path) or len(path)==0: + return path return mountpoint(os.path.dirname(path)) def getDevicebyMountpoint(hdm, mountpoint): diff --git a/src/Modules.py b/src/Modules.py index e89d0e8..82546f3 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -74,7 +74,8 @@ def loadModules(self, path, base): log.exception( ("PushService Load exception: ") + str(e) ) finally: # Since we may exit via an exception, close fp explicitly. - if fp: fp.close() + if fp: + fp.close() if not module: log.debug( ("PushService No module available: ") + str(name) ) diff --git a/src/PushService.py b/src/PushService.py index e5e2207..df8be8d 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -77,7 +77,8 @@ def stop(self): self.state = PSFIRST def next(self, state = None): - if state: self.state = state + if state: + self.state = state log.debug( "PushService next", self.state ) if self.state == PSBOOT: @@ -103,7 +104,8 @@ def do(self): self.next() def startTimer(self, seconds, state=None): - if state: self.state = state + if state: + self.state = state self.timer.startLongTimer( seconds ) def stopTimer(self): diff --git a/src/Services/GNTP.py b/src/Services/GNTP.py index cd671ac..754322f 100644 --- a/src/Services/GNTP.py +++ b/src/Services/GNTP.py @@ -60,7 +60,8 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): nottype = NOTIFICATION_TYPE.format( **{'box': box, 'name': NAME} ) # Prepare message - if body == "": body = subject + if body == "": + body = subject subject = GROWL_SUBJECT_TEMPLATE.format( **{'box': box, 'subject': subject} ) body = GROWL_BODY_TEMPLATE.format( **{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE} ) @@ -101,4 +102,4 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): # # Cancel push # if self.sockets: # for socket in self.sockets: -# socket.close() \ No newline at end of file +# socket.close() diff --git a/src/Services/SMTP.py b/src/Services/SMTP.py index 7ea6525..bf9a8f1 100644 --- a/src/Services/SMTP.py +++ b/src/Services/SMTP.py @@ -77,7 +77,8 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): to_addrs = [self.getValue('mailto') or from_addr] # Prepare message - if body == "": body = subject + if body == "": + body = subject subject = MAIL_HEADER_TEMPLATE.format( **{'box': config.pushservice.boxname.value, 'name': NAME, 'plugin': pluginname, 'subject': subject} ) body = MAIL_BODY_TEMPLATE.format( **{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE} ) message = Message(from_addr, to_addrs, subject, body) #TODO change mime="text/plain", charset="utf-8") From 94fc387b7af4e25a4502f7af0a29eee897c5dd17 Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:21 +0430 Subject: [PATCH 3/8] PEP8 double aggressive E251 and E252 --- src/ConfigScreen.py | 2 +- src/Controller/APTUpdateNotification.py | 2 +- src/Controller/ActiveTimers.py | 2 +- src/Controller/CrashLog.py | 2 +- src/Controller/DeactivatedTimers.py | 4 +-- src/Controller/FreeSpace.py | 8 +++--- src/Controller/IPKGUpdateNotification.py | 4 +-- src/Controller/ListDir.py | 4 +-- src/Controller/OPKGUpdateNotification.py | 2 +- src/Controller/RecordNotification.py | 6 ++--- src/Controller/RecordSummary.py | 4 +-- src/Controller/SendLog.py | 12 ++++----- src/Controller/StandbyNotification.py | 10 ++++---- src/ModuleBase.py | 2 +- src/PushService.py | 2 +- src/PushServiceBase.py | 4 +-- src/Services/GNTP.py | 32 ++++++++++++------------ src/Services/PopUp.py | 2 +- src/Services/SMTP.py | 16 ++++++------ src/__init__.py | 28 ++++++++++----------- src/plugin.py | 4 +-- 21 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index 2352d3a..893a55b 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -127,7 +127,7 @@ def __init__(self, session): self.list = [] self.state = MAIN self.build() - ConfigListScreen.__init__(self, self.list, session = session, on_change = self.change) + ConfigListScreen.__init__(self, self.list, session=session, on_change=self.change) # Override selectionChanged because our config tuples are bigger self.onChangedEntry = [ ] diff --git a/src/Controller/APTUpdateNotification.py b/src/Controller/APTUpdateNotification.py index adb5eb0..0288791 100644 --- a/src/Controller/APTUpdateNotification.py +++ b/src/Controller/APTUpdateNotification.py @@ -45,7 +45,7 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'selfcheck', NoSave(ConfigYesNo( default = False )), _("Start update check if not done yet") ) + self.setOption( 'selfcheck', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) self.data = "" self.container = eConsoleAppContainer() diff --git a/src/Controller/ActiveTimers.py b/src/Controller/ActiveTimers.py index 840e5f7..e5cc63e 100644 --- a/src/Controller/ActiveTimers.py +++ b/src/Controller/ActiveTimers.py @@ -45,7 +45,7 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption( 'add_tag', NoSave(ConfigYesNo( default = False )), _("Start update check if not done yet") ) + self.setOption( 'add_tag', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/CrashLog.py b/src/Controller/CrashLog.py index 8add322..2eeba2c 100644 --- a/src/Controller/CrashLog.py +++ b/src/Controller/CrashLog.py @@ -44,7 +44,7 @@ def __init__(self): self.crashlogs = [] # Default configuration - self.setOption( 'delete_logs', NoSave(ConfigYesNo( default = False )), _("Delete crashlog(s)") ) + self.setOption( 'delete_logs', NoSave(ConfigYesNo( default=False )), _("Delete crashlog(s)") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/DeactivatedTimers.py b/src/Controller/DeactivatedTimers.py index 986930d..6b33f6f 100644 --- a/src/Controller/DeactivatedTimers.py +++ b/src/Controller/DeactivatedTimers.py @@ -43,8 +43,8 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption( 'remove_timer', NoSave(ConfigYesNo( default = False )), _("Remove deactivated timer(s)") ) - self.setOption( 'list_similar', NoSave(ConfigYesNo( default = False )), _("List similar timer(s)") ) + self.setOption( 'remove_timer', NoSave(ConfigYesNo( default=False )), _("Remove deactivated timer(s)") ) + self.setOption( 'list_similar', NoSave(ConfigYesNo( default=False )), _("List similar timer(s)") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index a999413..c125cc8 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -72,10 +72,10 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'wakehdd', NoSave(ConfigYesNo( default = False )), _("Allow HDD wake up") ) - self.setOption( 'path', NoSave(ConfigText( default = "/media/hdd/movie", fixed_size = False )), _("Where to check free space") ) - self.setOption( 'limit', NoSave(ConfigNumber( default = 100 )), _("Free space limit in GB") ) - self.setOption( 'listtimer',NoSave(ConfigYesNo( default = False )), _("List upcoming timer") ) + self.setOption( 'wakehdd', NoSave(ConfigYesNo( default=False )), _("Allow HDD wake up") ) + self.setOption( 'path', NoSave(ConfigText( default="/media/hdd/movie", fixed_size=False )), _("Where to check free space") ) + self.setOption( 'limit', NoSave(ConfigNumber( default=100 )), _("Free space limit in GB") ) + self.setOption( 'listtimer',NoSave(ConfigYesNo( default=False )), _("List upcoming timer") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/IPKGUpdateNotification.py b/src/Controller/IPKGUpdateNotification.py index 882b9f6..28a8a8f 100644 --- a/src/Controller/IPKGUpdateNotification.py +++ b/src/Controller/IPKGUpdateNotification.py @@ -45,7 +45,7 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'selfcheck', NoSave(ConfigYesNo( default = False )), _("Start update check if not done yet") ) + self.setOption( 'selfcheck', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -62,7 +62,7 @@ def run(self, callback, errback): return callback() - def getUpdateInfosCB(self, callback, errback, retval = None): + def getUpdateInfosCB(self, callback, errback, retval=None): if retval is not None: if retval is True: if iSoftwareTools.available_updates is not 0: diff --git a/src/Controller/ListDir.py b/src/Controller/ListDir.py index 382a9aa..7ba817b 100644 --- a/src/Controller/ListDir.py +++ b/src/Controller/ListDir.py @@ -44,8 +44,8 @@ def __init__(self): self.movielist= [] # Default configuration - self.setOption( 'path', NoSave(ConfigText( default = "/media/hdd/movie/", fixed_size = False )), _("Where to check") ) - self.setOption( 'ext', NoSave(ConfigText( default = ".ts", fixed_size = False )), _("file extension") ) + self.setOption( 'path', NoSave(ConfigText( default="/media/hdd/movie/", fixed_size=False )), _("Where to check") ) + self.setOption( 'ext', NoSave(ConfigText( default=".ts", fixed_size=False )), _("file extension") ) def run(self, callback, errback): diff --git a/src/Controller/OPKGUpdateNotification.py b/src/Controller/OPKGUpdateNotification.py index d922e08..9dd1954 100644 --- a/src/Controller/OPKGUpdateNotification.py +++ b/src/Controller/OPKGUpdateNotification.py @@ -45,7 +45,7 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'selfcheck', NoSave(ConfigYesNo( default = False )), _("Start update check if not done yet") ) + self.setOption( 'selfcheck', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) self.data = "" self.container = eConsoleAppContainer() diff --git a/src/Controller/RecordNotification.py b/src/Controller/RecordNotification.py index a6ff169..3e5dcd7 100644 --- a/src/Controller/RecordNotification.py +++ b/src/Controller/RecordNotification.py @@ -48,9 +48,9 @@ def __init__(self): self.forceBindRecordTimer.callback.append(self.begin) # Default configuration - self.setOption( 'send_on_start', NoSave(ConfigYesNo( default = False )), _("Send notification on record start") ) - self.setOption( 'send_on_end', NoSave(ConfigYesNo( default = True )), _("Send notification on record end") ) - self.setOption( 'include_description', NoSave(ConfigYesNo( default = False )), _("Include timer description") ) + self.setOption( 'send_on_start', NoSave(ConfigYesNo( default=False )), _("Send notification on record start") ) + self.setOption( 'send_on_end', NoSave(ConfigYesNo( default=True )), _("Send notification on record end") ) + self.setOption( 'include_description', NoSave(ConfigYesNo( default=False )), _("Include timer description") ) #TODO option to send free space def begin(self): diff --git a/src/Controller/RecordSummary.py b/src/Controller/RecordSummary.py index 47636f5..f8c5d7f 100644 --- a/src/Controller/RecordSummary.py +++ b/src/Controller/RecordSummary.py @@ -44,8 +44,8 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption( 'remove_timer', NoSave(ConfigYesNo( default = False )), _("Remove finished timer(s)") ) - self.setOption( 'include_description', NoSave(ConfigYesNo( default = False )), _("Include timer description") ) + self.setOption( 'remove_timer', NoSave(ConfigYesNo( default=False )), _("Remove finished timer(s)") ) + self.setOption( 'include_description', NoSave(ConfigYesNo( default=False )), _("Include timer description") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/SendLog.py b/src/Controller/SendLog.py index 119cfe7..790e069 100644 --- a/src/Controller/SendLog.py +++ b/src/Controller/SendLog.py @@ -43,12 +43,12 @@ def __init__(self): self.logfiles = [] # Default configuration - self.setOption( 'path', NoSave(ConfigText( default = "/media/hdd/", fixed_size = False )), _("Path to check") ) - self.setOption( 'file_pattern', NoSave(ConfigText( default = "*.log", fixed_size = False )), _("Filename pattern (No RegExp)") ) - self.setOption( 'content_pattern', NoSave(ConfigText( default = ".*", fixed_size = False )), _("Content pattern (RegExp)") ) - self.setOption( 'scan_subs', NoSave(ConfigYesNo( default = False )), _("Scan subfolders") ) - self.setOption( 'rename_logs', NoSave(ConfigYesNo( default = False )), _("Rename log(s)") ) - self.setOption( 'delete_logs', NoSave(ConfigYesNo( default = False )), _("Delete log(s)") ) + self.setOption( 'path', NoSave(ConfigText( default="/media/hdd/", fixed_size=False )), _("Path to check") ) + self.setOption( 'file_pattern', NoSave(ConfigText( default="*.log", fixed_size=False )), _("Filename pattern (No RegExp)") ) + self.setOption( 'content_pattern', NoSave(ConfigText( default=".*", fixed_size=False )), _("Content pattern (RegExp)") ) + self.setOption( 'scan_subs', NoSave(ConfigYesNo( default=False )), _("Scan subfolders") ) + self.setOption( 'rename_logs', NoSave(ConfigYesNo( default=False )), _("Rename log(s)") ) + self.setOption( 'delete_logs', NoSave(ConfigYesNo( default=False )), _("Delete log(s)") ) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/StandbyNotification.py b/src/Controller/StandbyNotification.py index 4f4ab1c..5afc163 100644 --- a/src/Controller/StandbyNotification.py +++ b/src/Controller/StandbyNotification.py @@ -39,10 +39,10 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'send_after_bootup', NoSave(ConfigYesNo( default = False )), _("Send notification after bootup") ) - self.setOption( 'send_before_shutdown', NoSave(ConfigYesNo( default = False )), _("Send notification before shutdown") ) - self.setOption( 'send_before_standby', NoSave(ConfigYesNo( default = True )), _("Send notification before standby") ) - self.setOption( 'send_after_standby', NoSave(ConfigYesNo( default = True )), _("Send notification after standby") ) + self.setOption( 'send_after_bootup', NoSave(ConfigYesNo( default=False )), _("Send notification after bootup") ) + self.setOption( 'send_before_shutdown', NoSave(ConfigYesNo( default=False )), _("Send notification before shutdown") ) + self.setOption( 'send_before_standby', NoSave(ConfigYesNo( default=True )), _("Send notification before standby") ) + self.setOption( 'send_after_standby', NoSave(ConfigYesNo( default=True )), _("Send notification after standby") ) def leaveStandby(self, dummy=None): #log.debug( "leave standby" ) @@ -80,7 +80,7 @@ def begin(self): gPushService.push(self, SUBJECT, text) from Components.config import config - config.misc.standbyCounter.addNotifier(self.standbyCountChanged, initial_call = False) + config.misc.standbyCounter.addNotifier(self.standbyCountChanged, initial_call=False) def end(self): # Is called after stopping PushSerive diff --git a/src/ModuleBase.py b/src/ModuleBase.py index 385f1cf..649bc31 100644 --- a/src/ModuleBase.py +++ b/src/ModuleBase.py @@ -35,7 +35,7 @@ def __init__(self): # Is called on instance creation # Default configuration - self.enable = NoSave(ConfigYesNo( default = False )) + self.enable = NoSave(ConfigYesNo( default=False )) self.options = OrderedDict() diff --git a/src/PushService.py b/src/PushService.py index df8be8d..8a5c227 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -76,7 +76,7 @@ def stop(self): self.end() self.state = PSFIRST - def next(self, state = None): + def next(self, state=None): if state: self.state = state log.debug( "PushService next", self.state ) diff --git a/src/PushServiceBase.py b/src/PushServiceBase.py index 1e5ae08..debaf6a 100644 --- a/src/PushServiceBase.py +++ b/src/PushServiceBase.py @@ -226,12 +226,12 @@ def save(self): def build(root, instances, typ): for instance in instances: # Add module - element = SubElement( root, typ, name = stringToXML(instance.getName()), enable = stringToXML(instance.getStringEnable()) ) + element = SubElement( root, typ, name=stringToXML(instance.getName()), enable=stringToXML(instance.getStringEnable()) ) # Add options options = instance.getStringOptions() if options: for key, value, description in options: - SubElement( element, OPTION, key = stringToXML(key) ).text = stringToXML(value) + SubElement( element, OPTION, key=stringToXML(key) ).text = stringToXML(value) return root if services: diff --git a/src/Services/GNTP.py b/src/Services/GNTP.py index 754322f..b7e0b59 100644 --- a/src/Services/GNTP.py +++ b/src/Services/GNTP.py @@ -45,12 +45,12 @@ def __init__(self): #self.sockets = [] # Default configuration - self.setOption( 'growlhost', NoSave(ConfigText(default="host", fixed_size = False)), _("Growl Host name") ) - self.setOption( 'growlport', NoSave(ConfigNumber(default = 23053)), _("Growl Port") ) - self.setOption( 'timeout', NoSave(ConfigNumber(default = 3)), _("Timeout") ) + self.setOption( 'growlhost', NoSave(ConfigText(default="host", fixed_size=False)), _("Growl Host name") ) + self.setOption( 'growlport', NoSave(ConfigNumber(default=23053)), _("Growl Port") ) + self.setOption( 'timeout', NoSave(ConfigNumber(default=3)), _("Timeout") ) self.setOption( 'password', NoSave(ConfigPassword()), _("Password") ) - self.setOption( 'sticky', NoSave(ConfigYesNo(default = True)), _("Send as sticky") ) - self.setOption( 'priority', NoSave(ConfigNumber(default = 1)), _("Send with priority") ) + self.setOption( 'sticky', NoSave(ConfigYesNo(default=True)), _("Send as sticky") ) + self.setOption( 'priority', NoSave(ConfigNumber(default=1)), _("Send with priority") ) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE @@ -67,12 +67,12 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): # Registrate growl = gntp.notifier.GrowlNotifier( - applicationName = app, - notifications = [nottype], - defaultNotifications = [nottype], - hostname = self.getValue('growlhost'), - port = self.getValue('growlport'), - password = self.getValue('password') + applicationName=app, + notifications=[nottype], + defaultNotifications=[nottype], + hostname=self.getValue('growlhost'), + port=self.getValue('growlport'), + password=self.getValue('password') ) growl.socketTimeout = self.getValue('timeout') growl.register() @@ -80,12 +80,12 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): # Send a message #socket = sent = growl.notify( - noteType = nottype, - title = subject, - description = body, + noteType=nottype, + title=subject, + description=body, #Maybelater icon = "http://example.com/icon.png", - sticky = self.getValue('sticky'), - priority = self.getValue('priority') + sticky=self.getValue('sticky'), + priority=self.getValue('priority') ) #self.sockets.append(socket) diff --git a/src/Services/PopUp.py b/src/Services/PopUp.py index 3d9dba8..2a3d501 100644 --- a/src/Services/PopUp.py +++ b/src/Services/PopUp.py @@ -40,7 +40,7 @@ def __init__(self): # Is called on instance creation ServiceBase.__init__(self) # Default configuration - self.setOption( 'timeout', NoSave(ConfigNumber(default = 30)), _("Timeout") ) + self.setOption( 'timeout', NoSave(ConfigNumber(default=30)), _("Timeout") ) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME diff --git a/src/Services/SMTP.py b/src/Services/SMTP.py index bf9a8f1..06adaec 100644 --- a/src/Services/SMTP.py +++ b/src/Services/SMTP.py @@ -47,17 +47,17 @@ def __init__(self): self.connectors = [] # Default configuration - self.setOption( 'smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size = False)), _("SMTP Server") ) - self.setOption( 'smtpport', NoSave(ConfigNumber(default = 587)), _("SMTP Port") ) - self.setOption( 'smtpssl', NoSave(ConfigYesNo(default = True)), _("SMTP SSL") ) - self.setOption( 'smtptls', NoSave(ConfigYesNo(default = True)), _("SMTP TLS") ) - self.setOption( 'timeout', NoSave(ConfigNumber(default = 30)), _("Timeout") ) + self.setOption( 'smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size=False)), _("SMTP Server") ) + self.setOption( 'smtpport', NoSave(ConfigNumber(default=587)), _("SMTP Port") ) + self.setOption( 'smtpssl', NoSave(ConfigYesNo(default=True)), _("SMTP SSL") ) + self.setOption( 'smtptls', NoSave(ConfigYesNo(default=True)), _("SMTP TLS") ) + self.setOption( 'timeout', NoSave(ConfigNumber(default=30)), _("Timeout") ) - self.setOption( 'username', NoSave(ConfigText(default="user", fixed_size = False)), _("User name") ) + self.setOption( 'username', NoSave(ConfigText(default="user", fixed_size=False)), _("User name") ) self.setOption( 'password', NoSave(ConfigPassword(default="password")), _("Password") ) - self.setOption( 'mailfrom', NoSave(ConfigText(default = "abc@provider.com", fixed_size = False)), _("Mail from") ) - self.setOption( 'mailto', NoSave(ConfigText(fixed_size = False)), _("Mail to or leave empty (From will be used)") ) + self.setOption( 'mailfrom', NoSave(ConfigText(default="abc@provider.com", fixed_size=False)), _("Mail from") ) + self.setOption( 'mailto', NoSave(ConfigText(fixed_size=False)), _("Mail to or leave empty (From will be used)") ) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE diff --git a/src/__init__.py b/src/__init__.py index 08c4815..68f674e 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -11,25 +11,25 @@ config.pushservice.about = ConfigNothing() -config.pushservice.enable = ConfigEnableDisable(default = True) +config.pushservice.enable = ConfigEnableDisable(default=True) -config.pushservice.boxname = ConfigText(default = "Enigma2", fixed_size = False) -config.pushservice.xmlpath = ConfigText(default = "/etc/enigma2/pushservice.xml", fixed_size = False) +config.pushservice.boxname = ConfigText(default="Enigma2", fixed_size=False) +config.pushservice.xmlpath = ConfigText(default="/etc/enigma2/pushservice.xml", fixed_size=False) -config.pushservice.time = ConfigClock(default = 0) -config.pushservice.period = ConfigSelectionNumber(0, 1000, 1, default = 24) -config.pushservice.runonboot = ConfigEnableDisable(default = True) -config.pushservice.bootdelay = ConfigSelectionNumber(5, 1000, 5, default = 10) +config.pushservice.time = ConfigClock(default=0) +config.pushservice.period = ConfigSelectionNumber(0, 1000, 1, default=24) +config.pushservice.runonboot = ConfigEnableDisable(default=True) +config.pushservice.bootdelay = ConfigSelectionNumber(5, 1000, 5, default=10) -config.pushservice.push_errors = ConfigEnableDisable(default = False) +config.pushservice.push_errors = ConfigEnableDisable(default=False) -config.pushservice.popups_success_timeout = ConfigSelectionNumber(-1, 20, 1, default = 3) -config.pushservice.popups_warning_timeout = ConfigSelectionNumber(-1, 20, 1, default = -1) -config.pushservice.popups_error_timeout = ConfigSelectionNumber(-1, 20, 1, default = -1) +config.pushservice.popups_success_timeout = ConfigSelectionNumber(-1, 20, 1, default=3) +config.pushservice.popups_warning_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) +config.pushservice.popups_error_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) -config.pushservice.log_shell = ConfigEnableDisable(default = False) -config.pushservice.log_write = ConfigEnableDisable(default = False) -config.pushservice.log_file = ConfigText(default = "/tmp/pushservice.log", fixed_size = False) +config.pushservice.log_shell = ConfigEnableDisable(default=False) +config.pushservice.log_write = ConfigEnableDisable(default=False) +config.pushservice.log_file = ConfigText(default="/tmp/pushservice.log", fixed_size=False) def localeInit(): diff --git a/src/plugin.py b/src/plugin.py index 2af70d1..951c482 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -84,9 +84,9 @@ def Plugins(**kwargs): if config.pushservice.enable.value: # AutoStart - descriptors.append( PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart, needsRestart = False) ) + descriptors.append( PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart, needsRestart=False) ) #TODO icon - descriptors.append( PluginDescriptor(name = NAME, description = NAME + " " +_("configuration"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = setup, needsRestart = False) ) #icon = "/icon.png" + descriptors.append( PluginDescriptor(name=NAME, description=NAME + " " +_("configuration"), where=PluginDescriptor.WHERE_PLUGINMENU, fnc=setup, needsRestart=False) ) #icon = "/icon.png" return descriptors From b5fc10c07f4d5fda3a339200346be0db0edded1a Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:22 +0430 Subject: [PATCH 4/8] PEP8 double aggressive E20 and E211 --- src/ConfigFile.py | 8 +-- src/ConfigScreen.py | 42 ++++++------ src/Controller/APTUpdateNotification.py | 10 +-- src/Controller/ActiveTimers.py | 16 ++--- src/Controller/BrokenRecords.py | 2 +- src/Controller/CrashLog.py | 18 ++--- src/Controller/DeactivatedTimers.py | 10 +-- src/Controller/FreeSpace.py | 22 +++--- src/Controller/IPKGUpdateNotification.py | 24 +++---- src/Controller/ListDir.py | 10 +-- src/Controller/MissingTimers.py | 4 +- src/Controller/OPKGUpdateNotification.py | 10 +-- src/Controller/RecordNotification.py | 8 +-- src/Controller/RecordSummary.py | 8 +-- src/Controller/SendLog.py | 42 ++++++------ src/Controller/StandbyNotification.py | 8 +-- src/ControllerBase.py | 2 +- src/Logger.py | 18 ++--- src/ModuleBase.py | 12 ++-- src/Modules.py | 22 +++--- src/PushService.py | 14 ++-- src/PushServiceBase.py | 86 ++++++++++++------------ src/ServiceBase.py | 2 +- src/Services/GNTP.py | 20 +++--- src/Services/PopUp.py | 4 +- src/Services/SMTP.py | 24 +++---- src/Services/gntp/cli.py | 2 +- src/plugin.py | 8 +-- 28 files changed, 228 insertions(+), 228 deletions(-) diff --git a/src/ConfigFile.py b/src/ConfigFile.py index e1e1970..67f6d51 100644 --- a/src/ConfigFile.py +++ b/src/ConfigFile.py @@ -55,7 +55,7 @@ def readXML(self): # Abort if no config found if not os.path.exists(path): - log.debug( "PushService No configuration file present" ) + log.debug("PushService No configuration file present") return None # Parse if mtime differs from whats saved @@ -68,7 +68,7 @@ def readXML(self): try: etree = parse(path).getroot() except Exception, e: - log.exception( ("PushService Exception in readXML: ") + str(e) ) + log.exception(("PushService Exception in readXML: ") + str(e)) etree = None mtime = -1 @@ -89,12 +89,12 @@ def writeXML(self, etree): if data: f.writelines(data) except Exception, e: - log.exception( ("PushService Exception in writeXML: ") + str(e) ) + log.exception(("PushService Exception in writeXML: ") + str(e)) finally: if f is not None: f.close() # Save time and cache file content - self.mtime = os.path.getmtime( path ) + self.mtime = os.path.getmtime(path) self.cache = etree diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index 893a55b..a2496ab 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -57,7 +57,7 @@ # Configuration screen class ConfigScreen(Screen, ConfigListScreen, HelpableScreen, PushServiceBase): - skinfile = os.path.join( resolveFilename(SCOPE_PLUGINS), "Extensions/PushService/skin.xml" ) + skinfile = os.path.join(resolveFilename(SCOPE_PLUGINS), "Extensions/PushService/skin.xml") skin = open(skinfile).read() def __init__(self, session): @@ -130,7 +130,7 @@ def __init__(self, session): ConfigListScreen.__init__(self, self.list, session=session, on_change=self.change) # Override selectionChanged because our config tuples are bigger - self.onChangedEntry = [ ] + self.onChangedEntry = [] def selectionChanged(): current = self["config"].getCurrent() if self["config"].current != current: @@ -147,7 +147,7 @@ def selectionChanged(): def change(self, uniqueid=None): select = self.build(uniqueid) - self["config"].setList( self.list ) + self["config"].setList(self.list) if select is not None: self["config"].instance.moveSelectionTo(select) @@ -160,13 +160,13 @@ def buildEntries(entries): select = None if entries: for idx, entry in enumerate(entries): - self.list.append( getConfigListEntry( entry.getNameId(), entry.getConfigEnable(), idx ) ) + self.list.append(getConfigListEntry(entry.getNameId(), entry.getConfigEnable(), idx)) if entry.getUniqueID() == uniqueid: # Select the added entry select = len(self.list)-1 if entry.getEnable(): for key, element, description in entry.getConfigOptions(): - self.list.append( getConfigListEntry( " " + str(description), element, idx ) ) + self.list.append(getConfigListEntry(" " + str(description), element, idx)) return select if self.state == MAIN: @@ -184,24 +184,24 @@ def buildEntries(entries): self["key_blue"].setText("") self["main_actions_enabled"].setEnabled(False) - self.list.append( getConfigListEntry( _("Enable PushService"), config.pushservice.enable, 0 ) ) + self.list.append(getConfigListEntry(_("Enable PushService"), config.pushservice.enable, 0)) if config.pushservice.enable.value: - self.list.append( getConfigListEntry( _("Dreambox name"), config.pushservice.boxname, 0 ) ) - self.list.append( getConfigListEntry( _("Config file"), config.pushservice.xmlpath, 0 ) ) + self.list.append(getConfigListEntry(_("Dreambox name"), config.pushservice.boxname, 0)) + self.list.append(getConfigListEntry(_("Config file"), config.pushservice.xmlpath, 0)) - self.list.append( getConfigListEntry( _("Start time (HH:MM)"), config.pushservice.time, 0 ) ) - self.list.append( getConfigListEntry( _("Period in hours (0=disabled)"), config.pushservice.period, 0 ) ) - self.list.append( getConfigListEntry( _("Run on boot"), config.pushservice.runonboot, 0 ) ) + self.list.append(getConfigListEntry(_("Start time (HH:MM)"), config.pushservice.time, 0)) + self.list.append(getConfigListEntry(_("Period in hours (0=disabled)"), config.pushservice.period, 0)) + self.list.append(getConfigListEntry(_("Run on boot"), config.pushservice.runonboot, 0)) if config.pushservice.runonboot.value: - self.list.append( getConfigListEntry( _("Boot delay"), config.pushservice.bootdelay, 0 ) ) + self.list.append(getConfigListEntry(_("Boot delay"), config.pushservice.bootdelay, 0)) - self.list.append( getConfigListEntry( _("Push errors"), config.pushservice.push_errors, 0 ) ) + self.list.append(getConfigListEntry(_("Push errors"), config.pushservice.push_errors, 0)) - self.list.append( getConfigListEntry( _("Log to shell"), config.pushservice.log_shell, 0 ) ) - self.list.append( getConfigListEntry( _("Log to file"), config.pushservice.log_write, 0 ) ) + self.list.append(getConfigListEntry(_("Log to shell"), config.pushservice.log_shell, 0)) + self.list.append(getConfigListEntry(_("Log to file"), config.pushservice.log_write, 0)) if config.pushservice.log_write.value: - self.list.append( getConfigListEntry( _("Log file path and name"), config.pushservice.log_file, 0 ) ) + self.list.append(getConfigListEntry(_("Log file path and name"), config.pushservice.log_file, 0)) elif self.state == SERVICES: self["key_red"].setText(_("Main")) @@ -265,7 +265,7 @@ def addServicesCB(self, result): module = result and result[1] if module: id = self.addService(module) - self.change( id ) + self.change(id) def removeServices(self): self.hideHelpWindow() @@ -296,7 +296,7 @@ def addControllersCB(self, result): module = result and result[1] if module: id = self.addController(module) - self.change( id ) + self.change(id) def removeControllers(self): self.hideHelpWindow() @@ -435,15 +435,15 @@ def __init__(self, session, test): # Starting test try: if isinstance(test, ServiceBase): - test.push( self.callback, self.errback, _("PushService Config"), _("Push test"), _("If You can see this, Your configuration is correct.") ) + test.push(self.callback, self.errback, _("PushService Config"), _("Push test"), _("If You can see this, Your configuration is correct.")) elif isinstance(test, ControllerBase): - test.run( self.callback, self.errback ) + test.run(self.callback, self.errback) except Exception, e: text = _("PushService Test exception:") + str(e) + "\n\n" exc_type, exc_value, exc_traceback = sys.exc_info() for line in traceback.format_exception(exc_type, exc_value, exc_traceback): text += line - log.exception( text ) + log.exception(text) self.setText(text) def callback(self, *args): diff --git a/src/Controller/APTUpdateNotification.py b/src/Controller/APTUpdateNotification.py index 0288791..7f1c4d6 100644 --- a/src/Controller/APTUpdateNotification.py +++ b/src/Controller/APTUpdateNotification.py @@ -45,7 +45,7 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'selfcheck', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) + self.setOption('selfcheck', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) self.data = "" self.container = eConsoleAppContainer() @@ -77,11 +77,11 @@ def opkgupgradable(self): def aptupgradableFinished(self, retval=None): try: - log.debug( "PushService retval: ",str(retval) ) + log.debug("PushService retval: ",str(retval)) except: pass try: - log.debug( "PushService self.data: ",str(self.data) ) + log.debug("PushService self.data: ",str(self.data)) except: pass @@ -91,7 +91,7 @@ def aptupgradableFinished(self, retval=None): if self.data: try: for line in self.data.split("\n"): - log.debug( "PushService opkg upgradable data: ",line ) + log.debug("PushService opkg upgradable data: ",line) if line.startswith("Inst"): updates += line[5:] + "\r\n" continue @@ -99,7 +99,7 @@ def aptupgradableFinished(self, retval=None): excepts += "\r\n\r\nException:\r\n" + str(e) if excepts: - log.exception( excepts ) + log.exception(excepts) if updates: #callback( SUBJECT, BODY % (updates) ) diff --git a/src/Controller/ActiveTimers.py b/src/Controller/ActiveTimers.py index e5cc63e..7bb3dac 100644 --- a/src/Controller/ActiveTimers.py +++ b/src/Controller/ActiveTimers.py @@ -45,7 +45,7 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption( 'add_tag', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) + self.setOption('add_tag', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -56,23 +56,23 @@ def run(self, callback, errback): now = time() for timer in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers: if timer.justplay: - log.debug( _("ActiveTimers: Skip justplay") + str(timer.name) ) + log.debug(_("ActiveTimers: Skip justplay") + str(timer.name)) pass elif str(timer.service_ref)[0]=="-": - log.debug( _("ActiveTimers: Skip serviceref") + str(timer.name) ) + log.debug(_("ActiveTimers: Skip serviceref") + str(timer.name)) pass elif self.getValue('add_tag') and TAG in timer.tags: - log.debug( _("ActiveTimers: Skip tag") + str(timer.name) ) + log.debug(_("ActiveTimers: Skip tag") + str(timer.name)) pass elif timer.disabled: - log.debug( _("ActiveTimers: Skip disabled") + str(timer.name) ) + log.debug(_("ActiveTimers: Skip disabled") + str(timer.name)) pass elif timer.begin < now: - log.debug( _("ActiveTimers: Skip begin < now") + str(timer.name) ) + log.debug(_("ActiveTimers: Skip begin < now") + str(timer.name)) pass else: @@ -81,9 +81,9 @@ def run(self, callback, errback): + strftime(_("%H:%M"), localtime(timer.end)) + " " \ + str(timer.service_ref and timer.service_ref.getServiceName() or "") \ + "\n" - self.timers.append( timer ) + self.timers.append(timer) if self.timers and text: - callback( SUBJECT, BODY % text ) + callback(SUBJECT, BODY % text) else: callback() diff --git a/src/Controller/BrokenRecords.py b/src/Controller/BrokenRecords.py index b606da5..adf5b1c 100644 --- a/src/Controller/BrokenRecords.py +++ b/src/Controller/BrokenRecords.py @@ -58,7 +58,7 @@ def run(self, callback, errback): broken_records.append(record_path) if broken_records: - callback( SUBJECT, BODY % "\n\n" + "\n".join( broken_records ) ) + callback(SUBJECT, BODY % "\n\n" + "\n".join(broken_records)) else: callback() diff --git a/src/Controller/CrashLog.py b/src/Controller/CrashLog.py index 2eeba2c..7bc6d3c 100644 --- a/src/Controller/CrashLog.py +++ b/src/Controller/CrashLog.py @@ -44,7 +44,7 @@ def __init__(self): self.crashlogs = [] # Default configuration - self.setOption( 'delete_logs', NoSave(ConfigYesNo( default=False )), _("Delete crashlog(s)") ) + self.setOption('delete_logs', NoSave(ConfigYesNo(default=False)), _("Delete crashlog(s)")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -52,12 +52,12 @@ def run(self, callback, errback): # If empty or none is returned, nothing will be sent self.crashlogs = [] text = "Found crashlogs, see attachment(s)\n" - for file in os.listdir( CRASHLOG_DIR ): + for file in os.listdir(CRASHLOG_DIR): if file.startswith("enigma2_crash_") and file.endswith(".log"): - crashlog = os.path.join( CRASHLOG_DIR, file ) + crashlog = os.path.join(CRASHLOG_DIR, file) self.crashlogs.append(crashlog) if self.crashlogs: - callback( SUBJECT, BODY, self.crashlogs ) + callback(SUBJECT, BODY, self.crashlogs) else: callback() @@ -67,18 +67,18 @@ def callback(self): if self.getValue('delete_logs'): # Delete crashlogs for crashlog in self.crashlogs[:]: - if os.path.exists( crashlog ): - os.remove( crashlog ) - self.crashlogs.remove( crashlog ) + if os.path.exists(crashlog): + os.remove(crashlog) + self.crashlogs.remove(crashlog) else: # Rename crashlogs to avoid resending it for crashlog in self.crashlogs[:]: - if os.path.exists( crashlog ): + if os.path.exists(crashlog): # Adapted from autosubmit - instead of .sent we will use .pushed currfilename = str(os.path.basename(crashlog)) newfilename = "/media/hdd/" + currfilename + ".pushed" os.rename(crashlog,newfilename) - self.crashlogs.remove( crashlog ) + self.crashlogs.remove(crashlog) def errback(self): # Called after all services has returned, but at least one has failed diff --git a/src/Controller/DeactivatedTimers.py b/src/Controller/DeactivatedTimers.py index 6b33f6f..00bd7c0 100644 --- a/src/Controller/DeactivatedTimers.py +++ b/src/Controller/DeactivatedTimers.py @@ -43,8 +43,8 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption( 'remove_timer', NoSave(ConfigYesNo( default=False )), _("Remove deactivated timer(s)") ) - self.setOption( 'list_similar', NoSave(ConfigYesNo( default=False )), _("List similar timer(s)") ) + self.setOption('remove_timer', NoSave(ConfigYesNo(default=False)), _("Remove deactivated timer(s)")) + self.setOption('list_similar', NoSave(ConfigYesNo(default=False)), _("List similar timer(s)")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -92,10 +92,10 @@ def timerToString(timer): text += "\r\n" - self.timers.append( timer ) + self.timers.append(timer) if self.timers and text: - callback( SUBJECT, BODY % text ) + callback(SUBJECT, BODY % text) else: callback() @@ -116,7 +116,7 @@ def callback(self): # Set tag to avoid resending it for timer in self.timers: if TAG not in timer.tags: - log.debug( "[PS] timer append tag" ) + log.debug("[PS] timer append tag") timer.tags.append(TAG) NavigationInstance.instance.RecordTimer.saveTimer() self.timers = [] diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index c125cc8..18dc286 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -72,10 +72,10 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'wakehdd', NoSave(ConfigYesNo( default=False )), _("Allow HDD wake up") ) - self.setOption( 'path', NoSave(ConfigText( default="/media/hdd/movie", fixed_size=False )), _("Where to check free space") ) - self.setOption( 'limit', NoSave(ConfigNumber( default=100 )), _("Free space limit in GB") ) - self.setOption( 'listtimer',NoSave(ConfigYesNo( default=False )), _("List upcoming timer") ) + self.setOption('wakehdd', NoSave(ConfigYesNo(default=False)), _("Allow HDD wake up")) + self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie", fixed_size=False)), _("Where to check free space")) + self.setOption('limit', NoSave(ConfigNumber(default=100)), _("Free space limit in GB")) + self.setOption('listtimer',NoSave(ConfigYesNo(default=False)), _("List upcoming timer")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -88,19 +88,19 @@ def run(self, callback, errback): # User specified to avoid HDD wakeup if it is sleeping from Components.Harddisk import harddiskmanager - dev = getDevicebyMountpoint( harddiskmanager, mountpoint(path) ) + dev = getDevicebyMountpoint(harddiskmanager, mountpoint(path)) if dev is not None: - hdd = getHDD( harddiskmanager, dev ) + hdd = getHDD(harddiskmanager, dev) if hdd is not None: if hdd.isSleeping(): # Don't wake up HDD - log.debug( _("[FreeSpace] HDD is idle: ") + str(path) ) + log.debug(_("[FreeSpace] HDD is idle: ") + str(path)) callback() # Check free space on path - if os.path.exists( path ): - stat = os.statvfs( path ) - free = ( stat.f_bavail if stat.f_bavail!=0 else stat.f_bfree ) * stat.f_bsize / 1024 / 1024 # MB + if os.path.exists(path): + stat = os.statvfs(path) + free = (stat.f_bavail if stat.f_bavail!=0 else stat.f_bfree) * stat.f_bsize / 1024 / 1024 # MB if limit > (free/1024): #GB if free >= 10*1024: #MB free = "%d GB" %(free/1024) @@ -119,7 +119,7 @@ def run(self, callback, errback): if not t.disabled and not t.justplay and now < t.begin and t.end < next_day: text += "\t" + timerToString(t) + "\r\n" - callback( SUBJECT, BODY % (path, limit, free) + text ) + callback(SUBJECT, BODY % (path, limit, free) + text) else: # There is enough free space callback() diff --git a/src/Controller/IPKGUpdateNotification.py b/src/Controller/IPKGUpdateNotification.py index 28a8a8f..3c71622 100644 --- a/src/Controller/IPKGUpdateNotification.py +++ b/src/Controller/IPKGUpdateNotification.py @@ -45,20 +45,20 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'selfcheck', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) + self.setOption('selfcheck', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent - if iSoftwareTools.lastDownloadDate is not None and iSoftwareTools.lastDownloadDate > ( time() - (24*60*60) ): + if iSoftwareTools.lastDownloadDate is not None and iSoftwareTools.lastDownloadDate > (time() - (24*60*60)): # Last refresh was within one day return self.buildList(callback, errback) else: - log.debug( "IPKGUpdateNotification run else" ) + log.debug("IPKGUpdateNotification run else") if self.getValue('selfcheck'): # Refresh package list - iSoftwareTools.startSoftwareTools( boundFunction(self.getUpdateInfosCB, callback, errback) ) + iSoftwareTools.startSoftwareTools(boundFunction(self.getUpdateInfosCB, callback, errback)) return callback() @@ -67,28 +67,28 @@ def getUpdateInfosCB(self, callback, errback, retval=None): if retval is True: if iSoftwareTools.available_updates is not 0: # _("There are at least ") + str(iSoftwareTools.available_updates) + _(" updates available.") - log.debug( "Updates available." ) + log.debug("Updates available.") return self.buildList(callback, errback) else: # _("There are no updates available.") - log.debug( "There are no updates available." ) + log.debug("There are no updates available.") return callback() elif retval is False: if iSoftwareTools.lastDownloadDate is None: if iSoftwareTools.NetworkConnectionAvailable: # _("Updatefeed not available.") - log.debug( "Updatefeed not available." ) + log.debug("Updatefeed not available.") return errback(_("Updatefeed not available.")) else: # _("No network connection available.") - log.debug( "No network connection available." ) + log.debug("No network connection available.") return errback(_("No network connection available.")) else: - log.debug( "IPKGUpdateNotification getUpdates" ) + log.debug("IPKGUpdateNotification getUpdates") # Call update iSoftwareTools.lastDownloadDate = time() iSoftwareTools.list_updating = True - iSoftwareTools.getUpdates( boundFunction(self.getUpdateInfosCB, callback, errback) ) + iSoftwareTools.getUpdates(boundFunction(self.getUpdateInfosCB, callback, errback)) return callback() @@ -104,11 +104,11 @@ def buildList(self, callback, errback): if p == packagename: updversion = v break - log.debug( "PushService: " + packagename + " :\t" + instversion + " :\t" + updversion ) + log.debug("PushService: " + packagename + " :\t" + instversion + " :\t" + updversion) if instversion != updversion: updates += packagename + " :\t" + instversion + " :\t" + updversion + "\n" if updates: - callback( SUBJECT, BODY % (updates) ) + callback(SUBJECT, BODY % (updates)) else: callback() diff --git a/src/Controller/ListDir.py b/src/Controller/ListDir.py index 7ba817b..8f0278c 100644 --- a/src/Controller/ListDir.py +++ b/src/Controller/ListDir.py @@ -44,8 +44,8 @@ def __init__(self): self.movielist= [] # Default configuration - self.setOption( 'path', NoSave(ConfigText( default="/media/hdd/movie/", fixed_size=False )), _("Where to check") ) - self.setOption( 'ext', NoSave(ConfigText( default=".ts", fixed_size=False )), _("file extension") ) + self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie/", fixed_size=False)), _("Where to check")) + self.setOption('ext', NoSave(ConfigText(default=".ts", fixed_size=False)), _("file extension")) def run(self, callback, errback): @@ -55,12 +55,12 @@ def run(self, callback, errback): path = self.getValue('path') ext = self.getValue('ext') movielist = [] - for file in os.listdir( path ): - if file.endswith( ext ): + for file in os.listdir(path): + if file.endswith(ext): movielist.append(file) body = "The following files were found: \n" + "\n".join(movielist) if movielist: - callback( SUBJECT, body ) + callback(SUBJECT, body) else: callback() diff --git a/src/Controller/MissingTimers.py b/src/Controller/MissingTimers.py index cbcf32f..759ea51 100644 --- a/src/Controller/MissingTimers.py +++ b/src/Controller/MissingTimers.py @@ -46,7 +46,7 @@ def run(self, callback, errback): # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent timers = 0 - tomorrow_begin = mktime( ( date.today() + timedelta(days=1) ).timetuple() ) + tomorrow_begin = mktime((date.today() + timedelta(days=1)).timetuple()) tomorrow_end = tomorrow_begin + 24*60*60 for timer in NavigationInstance.instance.RecordTimer.timer_list: @@ -57,7 +57,7 @@ def run(self, callback, errback): break if timers == 0: - callback( SUBJECT, BODY % strftime(_("%Y.%m.%d"), localtime(tomorrow_begin))) + callback(SUBJECT, BODY % strftime(_("%Y.%m.%d"), localtime(tomorrow_begin))) else: callback() diff --git a/src/Controller/OPKGUpdateNotification.py b/src/Controller/OPKGUpdateNotification.py index 9dd1954..c953367 100644 --- a/src/Controller/OPKGUpdateNotification.py +++ b/src/Controller/OPKGUpdateNotification.py @@ -45,7 +45,7 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'selfcheck', NoSave(ConfigYesNo( default=False )), _("Start update check if not done yet") ) + self.setOption('selfcheck', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) self.data = "" self.container = eConsoleAppContainer() @@ -77,11 +77,11 @@ def opkgupgradable(self): def opkgupgradableFinished(self, retval=None): try: - log.debug( "PushService retval: ",str(retval) ) + log.debug("PushService retval: ",str(retval)) except: pass try: - log.debug( "PushService self.data: ",str(self.data) ) + log.debug("PushService self.data: ",str(self.data)) except: pass @@ -91,7 +91,7 @@ def opkgupgradableFinished(self, retval=None): if self.data: try: for line in self.data.split("\n"): - log.debug( "PushService opkg upgradable data: ",line ) + log.debug("PushService opkg upgradable data: ",line) if line.startswith("Inflating"): continue if line.startswith("Updated"): @@ -123,7 +123,7 @@ def opkgupgradableFinished(self, retval=None): excepts += "\r\n\r\nException:\r\n" + str(e) if excepts: - log.exception( excepts ) + log.exception(excepts) if updates: #callback( SUBJECT, BODY % (updates) ) diff --git a/src/Controller/RecordNotification.py b/src/Controller/RecordNotification.py index 3e5dcd7..09400fe 100644 --- a/src/Controller/RecordNotification.py +++ b/src/Controller/RecordNotification.py @@ -48,9 +48,9 @@ def __init__(self): self.forceBindRecordTimer.callback.append(self.begin) # Default configuration - self.setOption( 'send_on_start', NoSave(ConfigYesNo( default=False )), _("Send notification on record start") ) - self.setOption( 'send_on_end', NoSave(ConfigYesNo( default=True )), _("Send notification on record end") ) - self.setOption( 'include_description', NoSave(ConfigYesNo( default=False )), _("Include timer description") ) + self.setOption('send_on_start', NoSave(ConfigYesNo(default=False)), _("Send notification on record start")) + self.setOption('send_on_end', NoSave(ConfigYesNo(default=True)), _("Send notification on record end")) + self.setOption('include_description', NoSave(ConfigYesNo(default=False)), _("Include timer description")) #TODO option to send free space def begin(self): @@ -59,7 +59,7 @@ def begin(self): if self.getValue('send_on_start') or self.getValue('send_on_end'): if NavigationInstance.instance: if self.onRecordEvent not in NavigationInstance.instance.RecordTimer.on_state_change: - log.debug( "append" ) + log.debug("append") # Append callback function NavigationInstance.instance.RecordTimer.on_state_change.append(self.onRecordEvent) else: diff --git a/src/Controller/RecordSummary.py b/src/Controller/RecordSummary.py index f8c5d7f..56c4bf5 100644 --- a/src/Controller/RecordSummary.py +++ b/src/Controller/RecordSummary.py @@ -44,8 +44,8 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption( 'remove_timer', NoSave(ConfigYesNo( default=False )), _("Remove finished timer(s)") ) - self.setOption( 'include_description', NoSave(ConfigYesNo( default=False )), _("Include timer description") ) + self.setOption('remove_timer', NoSave(ConfigYesNo(default=False)), _("Remove finished timer(s)")) + self.setOption('include_description', NoSave(ConfigYesNo(default=False)), _("Include timer description")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -74,9 +74,9 @@ def run(self, callback, errback): + "\n" if self.getValue('include_description'): text += str(timer.description) + "\n\n" - self.timers.append( timer ) + self.timers.append(timer) if self.timers and text: - callback( SUBJECT, BODY % text ) + callback(SUBJECT, BODY % text) else: callback() diff --git a/src/Controller/SendLog.py b/src/Controller/SendLog.py index 790e069..0c8e8d4 100644 --- a/src/Controller/SendLog.py +++ b/src/Controller/SendLog.py @@ -43,12 +43,12 @@ def __init__(self): self.logfiles = [] # Default configuration - self.setOption( 'path', NoSave(ConfigText( default="/media/hdd/", fixed_size=False )), _("Path to check") ) - self.setOption( 'file_pattern', NoSave(ConfigText( default="*.log", fixed_size=False )), _("Filename pattern (No RegExp)") ) - self.setOption( 'content_pattern', NoSave(ConfigText( default=".*", fixed_size=False )), _("Content pattern (RegExp)") ) - self.setOption( 'scan_subs', NoSave(ConfigYesNo( default=False )), _("Scan subfolders") ) - self.setOption( 'rename_logs', NoSave(ConfigYesNo( default=False )), _("Rename log(s)") ) - self.setOption( 'delete_logs', NoSave(ConfigYesNo( default=False )), _("Delete log(s)") ) + self.setOption('path', NoSave(ConfigText(default="/media/hdd/", fixed_size=False)), _("Path to check")) + self.setOption('file_pattern', NoSave(ConfigText(default="*.log", fixed_size=False)), _("Filename pattern (No RegExp)")) + self.setOption('content_pattern', NoSave(ConfigText(default=".*", fixed_size=False)), _("Content pattern (RegExp)")) + self.setOption('scan_subs', NoSave(ConfigYesNo(default=False)), _("Scan subfolders")) + self.setOption('rename_logs', NoSave(ConfigYesNo(default=False)), _("Rename log(s)")) + self.setOption('delete_logs', NoSave(ConfigYesNo(default=False)), _("Delete log(s)")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -63,32 +63,32 @@ def run(self, callback, errback): if self.getValue('scan_subs'): for root, dirnames, filenames in os.walk(path): for filename in fnmatch.filter(filenames, file_pattern): - logfile = os.path.join( root, filename ) - if( content_pattern == ".*" ): - self.logfiles.append( logfile ) + logfile = os.path.join(root, filename) + if(content_pattern == ".*"): + self.logfiles.append(logfile) else: infile = open(logfile,"r") for line in infile: if prog.match(line): - self.logfiles.append( logfile ) + self.logfiles.append(logfile) break infile.close() else: - filenames = os.listdir( path ) + filenames = os.listdir(path) for filename in fnmatch.filter(filenames, file_pattern): - logfile = os.path.join( path, filename ) - if( content_pattern == ".*" ): - self.logfiles.append( logfile ) + logfile = os.path.join(path, filename) + if(content_pattern == ".*"): + self.logfiles.append(logfile) else: infile = open(logfile,"r") for line in infile: if prog.match(line): - self.logfiles.append( logfile ) + self.logfiles.append(logfile) break infile.close() if self.logfiles: - callback( SUBJECT, BODY, self.logfiles ) + callback(SUBJECT, BODY, self.logfiles) else: callback() @@ -98,18 +98,18 @@ def callback(self): if self.getValue('delete_logs'): # Delete logfiles for logfile in self.logfiles[:]: - if os.path.exists( logfile ): - os.remove( logfile ) - self.logfiles.remove( logfile ) + if os.path.exists(logfile): + os.remove(logfile) + self.logfiles.remove(logfile) elif self.getValue('rename_logs'): # Rename logfiles to avoid resending it for logfile in self.logfiles[:]: - if os.path.exists( logfile ): + if os.path.exists(logfile): # Adapted from autosubmit - instead of .sent we will use .pushed currfilename = str(os.path.basename(logfile)) newfilename = "/media/hdd/" + currfilename + ".pushed" os.rename(logfile,newfilename) - self.logfiles.remove( logfile ) + self.logfiles.remove(logfile) def errback(self): # Called after all services has returned, but at least one has failed diff --git a/src/Controller/StandbyNotification.py b/src/Controller/StandbyNotification.py index 5afc163..39c685f 100644 --- a/src/Controller/StandbyNotification.py +++ b/src/Controller/StandbyNotification.py @@ -39,10 +39,10 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption( 'send_after_bootup', NoSave(ConfigYesNo( default=False )), _("Send notification after bootup") ) - self.setOption( 'send_before_shutdown', NoSave(ConfigYesNo( default=False )), _("Send notification before shutdown") ) - self.setOption( 'send_before_standby', NoSave(ConfigYesNo( default=True )), _("Send notification before standby") ) - self.setOption( 'send_after_standby', NoSave(ConfigYesNo( default=True )), _("Send notification after standby") ) + self.setOption('send_after_bootup', NoSave(ConfigYesNo(default=False)), _("Send notification after bootup")) + self.setOption('send_before_shutdown', NoSave(ConfigYesNo(default=False)), _("Send notification before shutdown")) + self.setOption('send_before_standby', NoSave(ConfigYesNo(default=True)), _("Send notification before standby")) + self.setOption('send_after_standby', NoSave(ConfigYesNo(default=True)), _("Send notification after standby")) def leaveStandby(self, dummy=None): #log.debug( "leave standby" ) diff --git a/src/ControllerBase.py b/src/ControllerBase.py index fb9f9fb..f121d04 100644 --- a/src/ControllerBase.py +++ b/src/ControllerBase.py @@ -53,7 +53,7 @@ def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent - errback( "Not implemented: " + self.getName() + ".run()") + errback("Not implemented: " + self.getName() + ".run()") # Callback functions def callback(self): diff --git a/src/Logger.py b/src/Logger.py index 2881225..6b12aba 100644 --- a/src/Logger.py +++ b/src/Logger.py @@ -73,7 +73,7 @@ def shutdown(self): self.instance.shutdown() def info(self, *args): - strargs = " ".join( [ str(arg) for arg in args ] ) + strargs = " ".join([str(arg) for arg in args]) if self.instance: self.instance.info(strargs) @@ -82,7 +82,7 @@ def info(self, *args): print strargs def debug(self, *args): - strargs = " ".join( [ str(arg) for arg in args ] ) + strargs = " ".join([str(arg) for arg in args]) if self.instance: self.instance.debug(strargs) @@ -91,12 +91,12 @@ def debug(self, *args): print strargs if sys.exc_info()[0]: - self.instance.debug( str(sys.exc_info()[0]) ) - self.instance.debug( str(traceback.format_exc()) ) + self.instance.debug(str(sys.exc_info()[0])) + self.instance.debug(str(traceback.format_exc())) sys.exc_clear() def warning(self, *args): - strargs = " ".join( [ str(arg) for arg in args ] ) + strargs = " ".join([str(arg) for arg in args]) if self.instance: self.instance.warning(strargs) @@ -114,7 +114,7 @@ def warning(self, *args): ) def error(self, *args): - strargs = " ".join( [ str(arg) for arg in args ] ) + strargs = " ".join([str(arg) for arg in args]) if self.instance: self.instance.error(strargs) @@ -132,7 +132,7 @@ def error(self, *args): ) def exception(self, *args): - strargs = " ".join( [ str(arg) for arg in args ] ) + strargs = " ".join([str(arg) for arg in args]) if self.instance: self.instance.exception(strargs) @@ -155,8 +155,8 @@ def exception(self, *args): if sys.exc_info()[0]: #exc_type, exc_value, exc_traceback = sys.exc_info() #traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout) - self.debug( str(sys.exc_info()[0]) ) - self.debug( str(traceback.format_exc()) ) + self.debug(str(sys.exc_info()[0])) + self.debug(str(traceback.format_exc())) sys.exc_clear() diff --git a/src/ModuleBase.py b/src/ModuleBase.py index 649bc31..db83caa 100644 --- a/src/ModuleBase.py +++ b/src/ModuleBase.py @@ -35,7 +35,7 @@ def __init__(self): # Is called on instance creation # Default configuration - self.enable = NoSave(ConfigYesNo( default=False )) + self.enable = NoSave(ConfigYesNo(default=False)) self.options = OrderedDict() @@ -77,7 +77,7 @@ def getOption(self, key): return None def setOption(self, key, option, description): - self.options[key] = ( option, description ) + self.options[key] = (option, description) def setOptions(self, options): # Parse a list of key-value string tuples @@ -93,8 +93,8 @@ def setOptions(self, options): elif type(default) is int: self.setValue(key, int(value)) except: - log.debug( ("PushService Module %s:\n") % ( self.getName() ) ) - log.debug( ("Skipping config option:") + str(key) + " " + str(value) ) + log.debug(("PushService Module %s:\n") % (self.getName())) + log.debug(("Skipping config option:") + str(key) + " " + str(value)) continue def getUniqueID(self): @@ -113,10 +113,10 @@ def getStringEnable(self): return str(self.enable.value) def getStringOptions(self): - return [ ( str(key), str(option.value), str(description) ) for ( key, ( option, description ) ) in self.options.items() ] + return [(str(key), str(option.value), str(description)) for (key, (option, description)) in self.options.items()] def getConfigOptions(self): - return [ ( key, option, description) for ( key, ( option, description ) ) in self.options.items() ] + return [(key, option, description) for (key, (option, description)) in self.options.items()] ################################################ diff --git a/src/Modules.py b/src/Modules.py index 82546f3..375bc3b 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -61,40 +61,40 @@ def loadModules(self, path, base): try: fp, pathname, description = imp.find_module(name, [path]) except Exception, e: - log.exception( ("PushService Find module exception: ") + str(e) ) + log.exception(("PushService Find module exception: ") + str(e)) fp = None if not fp: - log.debug( ("PushService No module found: ") + str(name) ) + log.debug(("PushService No module found: ") + str(name)) continue try: - module = imp.load_module( name, fp, pathname, description) + module = imp.load_module(name, fp, pathname, description) except Exception, e: - log.exception( ("PushService Load exception: ") + str(e) ) + log.exception(("PushService Load exception: ") + str(e)) finally: # Since we may exit via an exception, close fp explicitly. if fp: fp.close() if not module: - log.debug( ("PushService No module available: ") + str(name) ) + log.debug(("PushService No module available: ") + str(name)) continue # Continue only if the attribute is available if not hasattr(module, name): - log.debug( ("PushService Warning attribute not available: ") + str(name) ) + log.debug(("PushService Warning attribute not available: ") + str(name)) continue # Continue only if attr is a class attr = getattr(module, name) if not inspect.isclass(attr): - log.debug( ("PushService Warning no class definition: ") + str(name) ) + log.debug(("PushService Warning no class definition: ") + str(name)) continue # Continue only if the class is a subclass of the corresponding base class - if not issubclass( attr, base): - log.debug( ("PushService Warning no subclass of base: ") + str(name) ) + if not issubclass(attr, base): + log.debug(("PushService Warning no subclass of base: ") + str(name)) continue # Add module to the module list @@ -107,7 +107,7 @@ def instantiateModule(self, module): try: return module() except Exception, e: - log.exception( ("PushService Instantiate exception: ") + str(module) + "\n" + str(e) ) + log.exception(("PushService Instantiate exception: ") + str(module) + "\n" + str(e)) else: - log.debug( ("PushService Module is not callable") ) + log.debug(("PushService Module is not callable")) return None diff --git a/src/PushService.py b/src/PushService.py index 8a5c227..97d9fdf 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -63,14 +63,14 @@ def __init__(self): def start(self): log.reinit() - log.info( "PushService start" ) + log.info("PushService start") self.stopTimer() self.begin() self.next() def stop(self): - log.debug( "PushService stop" ) + log.debug("PushService stop") self.stopTimer() self.end() @@ -79,10 +79,10 @@ def stop(self): def next(self, state=None): if state: self.state = state - log.debug( "PushService next", self.state ) + log.debug("PushService next", self.state) if self.state == PSBOOT: - self.startTimer( int(config.pushservice.bootdelay.value), PSBOOTRUN ) + self.startTimer(int(config.pushservice.bootdelay.value), PSBOOTRUN) elif self.state == PSBOOTRUN \ or self.state == PSFIRST: @@ -91,13 +91,13 @@ def next(self, state=None): ltime = lotime[3]*60 + lotime[4] ctime = cltime[0]*60 + cltime[1] seconds = 60 * abs(ctime - ltime) - self.startTimer( seconds, PSFIRSTRUN ) + self.startTimer(seconds, PSFIRSTRUN) elif self.state == PSFIRSTRUN \ or self.state == PSCYCLE: period = int(config.pushservice.period.value) if period > 0: - self.startTimer( period*60*60, PSCYCLE ) + self.startTimer(period*60*60, PSCYCLE) def do(self): self.run() @@ -106,7 +106,7 @@ def do(self): def startTimer(self, seconds, state=None): if state: self.state = state - self.timer.startLongTimer( seconds ) + self.timer.startLongTimer(seconds) def stopTimer(self): if self.timer.isActive(): diff --git a/src/PushServiceBase.py b/src/PushServiceBase.py index debaf6a..952a0f1 100644 --- a/src/PushServiceBase.py +++ b/src/PushServiceBase.py @@ -46,8 +46,8 @@ CONTROLLER = "Controller" OPTION = "Option" -SERVICE_PATH = os.path.join( resolveFilename(SCOPE_PLUGINS), "Extensions/PushService/Services/" ) -CONTROLLER_PATH = os.path.join( resolveFilename(SCOPE_PLUGINS), "Extensions/PushService/Controller/" ) +SERVICE_PATH = os.path.join(resolveFilename(SCOPE_PLUGINS), "Extensions/PushService/Services/") +CONTROLLER_PATH = os.path.join(resolveFilename(SCOPE_PLUGINS), "Extensions/PushService/Controller/") class PushServiceBase(Modules, ConfigFile): @@ -81,33 +81,33 @@ def getService(self, idx): def getAvlServices(self): slist = [] if self.servicemodules: - serviceclasses = [ service.getClass() for service in self.services] if self.services else [] + serviceclasses = [service.getClass() for service in self.services] if self.services else [] for name, module in self.servicemodules.iteritems(): if module.forceSingle(): # We have to check if there is already a plugin instance if name in serviceclasses: # A service instance already exists continue - slist.append( (name, module) ) + slist.append((name, module)) slist.sort() return slist def getServiceInstances(self): - return [( service.getNameId(), service ) for service in self.getServices() ] + return [(service.getNameId(), service) for service in self.getServices()] def addService(self, module): id = None - service = module and self.instantiateModule( module ) + service = module and self.instantiateModule(module) if service: service.setEnable(True) - self.services.append( service ) - self.services.sort( key=lambda x: ( x.getUniqueID() ) ) + self.services.append(service) + self.services.sort(key=lambda x: (x.getUniqueID())) id = service.getUniqueID() return id def removeService(self, service): if service in self.services: - self.services.remove( service ) + self.services.remove(service) def getControllers(self): return self.controllers or [] @@ -121,33 +121,33 @@ def getController(self, idx): def getAvlControllers(self): plist = [] if self.controllermodules: - controllerclasses = [ controller.getClass() for controller in self.controllers] if self.controllers else [] + controllerclasses = [controller.getClass() for controller in self.controllers] if self.controllers else [] for name, module in self.controllermodules.iteritems(): if module.forceSingle(): # We have to check if there is already a controller instance if name in controllerclasses: # A controller instance already exists continue - plist.append( (name, module) ) + plist.append((name, module)) plist.sort() return plist def getControllerInstances(self): - return [( controller.getNameId(), controller ) for controller in self.getControllers() ] + return [(controller.getNameId(), controller) for controller in self.getControllers()] def addController(self, module): id = None - controller = module and self.instantiateModule( module ) + controller = module and self.instantiateModule(module) if controller: controller.setEnable(True) - self.controllers.append( controller ) - self.controllers.sort( key=lambda x: ( x.getUniqueID() ) ) + self.controllers.append(controller) + self.controllers.sort(key=lambda x: (x.getUniqueID())) id = controller.getUniqueID() return id def removeController(self, controller): if controller in self.controllers: - self.controllers.remove( controller ) + self.controllers.remove(controller) ###################################### @@ -201,8 +201,8 @@ def parse(root, typ, modules): # Append to active controller list instances.append(instance) return instances - services = parse( root, SERVICE, self.servicemodules ) - controllers = parse( root, CONTROLLER, self.controllermodules ) + services = parse(root, SERVICE, self.servicemodules) + controllers = parse(root, CONTROLLER, self.controllermodules) self.services = services self.controllers = controllers @@ -226,20 +226,20 @@ def save(self): def build(root, instances, typ): for instance in instances: # Add module - element = SubElement( root, typ, name=stringToXML(instance.getName()), enable=stringToXML(instance.getStringEnable()) ) + element = SubElement(root, typ, name=stringToXML(instance.getName()), enable=stringToXML(instance.getStringEnable())) # Add options options = instance.getStringOptions() if options: for key, value, description in options: - SubElement( element, OPTION, key=stringToXML(key) ).text = stringToXML(value) + SubElement(element, OPTION, key=stringToXML(key)).text = stringToXML(value) return root if services: - root = build( root, services, SERVICE) + root = build(root, services, SERVICE) if controllers: - root = build( root, controllers, CONTROLLER) + root = build(root, controllers, CONTROLLER) - self.writeXML( root ) + self.writeXML(root) ###################################### @@ -265,7 +265,7 @@ def end(self): controller.end() def run(self): - log.debug( ("PushService started: ") + strftime( _("%d.%m.%Y %H:%M"), localtime() ) ) + log.debug(("PushService started: ") + strftime(_("%d.%m.%Y %H:%M"), localtime())) controllers = self.controllers self.pushcallbacks = {} @@ -275,15 +275,15 @@ def run(self): if controllers: for controller in controllers: if controller.getEnable(): - log.debug( ("PushService running: ") + str( controller.getName() ) ) + log.debug(("PushService running: ") + str(controller.getName())) try: # Run controller ret = controller.run( boundFunction(self.runcallback, controller), - boundFunction(self.runerrback, controller) ) + boundFunction(self.runerrback, controller)) except Exception, e: - log.exception( "PushService controller run() exception" , str(e) ) + log.exception("PushService controller run() exception", str(e)) exc_type, exc_value, exc_traceback = sys.exc_info() self.runerrback(controller, exc_type, exc_value, exc_traceback) @@ -307,7 +307,7 @@ def runcallback(self, controller, *args): self.push(controller, subject, body, attachments) def runerrback(self, controller, *args): - log.debug( ("controller %s returned error(s)") % controller.getName() ) + log.debug(("controller %s returned error(s)") % controller.getName()) text = "" for arg in args: if isinstance(arg, Exception): @@ -317,12 +317,12 @@ def runerrback(self, controller, *args): text += str(arg) + "\n" elif arg: text += str(arg) + "\n" - log.debug( text ) + log.debug(text) if config.pushservice.push_errors.value: self.push(controller, _("PushService controller run() exception"), text, []) def push(self, controller, subject, text="", attachments=[]): - log.debug( "[PS] push" ) + log.debug("[PS] push") services = self.services if not services: # Fallback to PopUp @@ -338,14 +338,14 @@ def push(self, controller, subject, text="", attachments=[]): boundFunction(self.pushcallback, service, controller), boundFunction(self.pusherrback, service, controller), controller.getName(), - subject, text, attachments ) + subject, text, attachments) except Exception, e: - log.debug( "PushService Service push() exception") + log.debug("PushService Service push() exception") exc_type, exc_value, exc_traceback = sys.exc_info() self.pusherrback(service, controller, exc_type, exc_value, exc_traceback) def pushcallback(self, service, controller, *args): - log.debug( "[PS] pushcallback" ) + log.debug("[PS] pushcallback") key = (service, controller) if key not in self.pushcallbacks: self.pushcallbacks[key] = list(args) @@ -354,13 +354,13 @@ def pushcallback(self, service, controller, *args): self.pushcheckbacks(key) def pusherrback(self, service, controller, *args): - log.debug( "[PS] pusherrback" ) - log.debug( ("Service %s returned error(s)") % service.getName() ) + log.debug("[PS] pusherrback") + log.debug(("Service %s returned error(s)") % service.getName()) for arg in args: if isinstance(arg, Exception): - log.debug( str(arg.type), str(arg.value) ) + log.debug(str(arg.type), str(arg.value)) elif arg: - log.debug( str(arg) ) + log.debug(str(arg)) key = (service, controller) if key not in self.pusherrbacks: self.pusherrbacks[key] = list(args) @@ -369,21 +369,21 @@ def pusherrback(self, service, controller, *args): self.pushcheckbacks(key) def pushcheckbacks(self, key): - log.debug( "[PS] pushcheckbacks" ) + log.debug("[PS] pushcheckbacks") callparam = self.pushcallbacks.get(key, []) cntcall = len(callparam) errparam = self.pusherrbacks.get(key, []) cnterr = len(errparam) - cntservices = len( [ service for service in self.services if service.getEnable() ] ) + cntservices = len([service for service in self.services if service.getEnable()]) # Check if all services already called and returned - if ( cntservices == (cntcall + cnterr) ): + if (cntservices == (cntcall + cnterr)): service, controller = key if controller: # Check if no error is logged - if ( cnterr == 0 ): - log.debug( "[PS] controller.callback()" ) + if (cnterr == 0): + log.debug("[PS] controller.callback()") controller.callback() else: controller.errback() - log.debug( "[PS] controller.errback()" ) + log.debug("[PS] controller.errback()") diff --git a/src/ServiceBase.py b/src/ServiceBase.py index b440371..a65cb7a 100644 --- a/src/ServiceBase.py +++ b/src/ServiceBase.py @@ -51,7 +51,7 @@ def resetUniqueID(): def push(self, callback, errback, pluginname, subject, body="", attachments=[]): # Will be called, if a plugin wants to send a notification # At the end a service has to call one of the functions: callback or errback - errback( "Not implemented: " + self.getName() + ".push()") + errback("Not implemented: " + self.getName() + ".push()") # def test(self, plugin, subject, body="", attachments=[], callback=None, errback=None): # # Normally you don't have to overwrite this function diff --git a/src/Services/GNTP.py b/src/Services/GNTP.py index b7e0b59..2610fa4 100644 --- a/src/Services/GNTP.py +++ b/src/Services/GNTP.py @@ -45,25 +45,25 @@ def __init__(self): #self.sockets = [] # Default configuration - self.setOption( 'growlhost', NoSave(ConfigText(default="host", fixed_size=False)), _("Growl Host name") ) - self.setOption( 'growlport', NoSave(ConfigNumber(default=23053)), _("Growl Port") ) - self.setOption( 'timeout', NoSave(ConfigNumber(default=3)), _("Timeout") ) - self.setOption( 'password', NoSave(ConfigPassword()), _("Password") ) - self.setOption( 'sticky', NoSave(ConfigYesNo(default=True)), _("Send as sticky") ) - self.setOption( 'priority', NoSave(ConfigNumber(default=1)), _("Send with priority") ) + self.setOption('growlhost', NoSave(ConfigText(default="host", fixed_size=False)), _("Growl Host name")) + self.setOption('growlport', NoSave(ConfigNumber(default=23053)), _("Growl Port")) + self.setOption('timeout', NoSave(ConfigNumber(default=3)), _("Timeout")) + self.setOption('password', NoSave(ConfigPassword()), _("Password")) + self.setOption('sticky', NoSave(ConfigYesNo(default=True)), _("Send as sticky")) + self.setOption('priority', NoSave(ConfigNumber(default=1)), _("Send with priority")) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE box = config.pushservice.boxname.value - app = APP_NAME.format( **{'box': box, 'name': NAME} ) - nottype = NOTIFICATION_TYPE.format( **{'box': box, 'name': NAME} ) + app = APP_NAME.format(**{'box': box, 'name': NAME}) + nottype = NOTIFICATION_TYPE.format(**{'box': box, 'name': NAME}) # Prepare message if body == "": body = subject - subject = GROWL_SUBJECT_TEMPLATE.format( **{'box': box, 'subject': subject} ) - body = GROWL_BODY_TEMPLATE.format( **{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE} ) + subject = GROWL_SUBJECT_TEMPLATE.format(**{'box': box, 'subject': subject}) + body = GROWL_BODY_TEMPLATE.format(**{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE}) # Registrate growl = gntp.notifier.GrowlNotifier( diff --git a/src/Services/PopUp.py b/src/Services/PopUp.py index 2a3d501..ad837ee 100644 --- a/src/Services/PopUp.py +++ b/src/Services/PopUp.py @@ -40,13 +40,13 @@ def __init__(self): # Is called on instance creation ServiceBase.__init__(self) # Default configuration - self.setOption( 'timeout', NoSave(ConfigNumber(default=30)), _("Timeout") ) + self.setOption('timeout', NoSave(ConfigNumber(default=30)), _("Timeout")) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME # Fire and forget AddPopup( - POPUP_TEMPLATE.format( **{'name': NAME, 'plugin': pluginname, 'subject': subject, 'body': body} ), + POPUP_TEMPLATE.format(**{'name': NAME, 'plugin': pluginname, 'subject': subject, 'body': body}), MessageBox.TYPE_INFO, self.getValue('timeout'), 'PS_PopUp_ID_' + subject diff --git a/src/Services/SMTP.py b/src/Services/SMTP.py index 06adaec..8dd0dea 100644 --- a/src/Services/SMTP.py +++ b/src/Services/SMTP.py @@ -47,17 +47,17 @@ def __init__(self): self.connectors = [] # Default configuration - self.setOption( 'smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size=False)), _("SMTP Server") ) - self.setOption( 'smtpport', NoSave(ConfigNumber(default=587)), _("SMTP Port") ) - self.setOption( 'smtpssl', NoSave(ConfigYesNo(default=True)), _("SMTP SSL") ) - self.setOption( 'smtptls', NoSave(ConfigYesNo(default=True)), _("SMTP TLS") ) - self.setOption( 'timeout', NoSave(ConfigNumber(default=30)), _("Timeout") ) + self.setOption('smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size=False)), _("SMTP Server")) + self.setOption('smtpport', NoSave(ConfigNumber(default=587)), _("SMTP Port")) + self.setOption('smtpssl', NoSave(ConfigYesNo(default=True)), _("SMTP SSL")) + self.setOption('smtptls', NoSave(ConfigYesNo(default=True)), _("SMTP TLS")) + self.setOption('timeout', NoSave(ConfigNumber(default=30)), _("Timeout")) - self.setOption( 'username', NoSave(ConfigText(default="user", fixed_size=False)), _("User name") ) - self.setOption( 'password', NoSave(ConfigPassword(default="password")), _("Password") ) + self.setOption('username', NoSave(ConfigText(default="user", fixed_size=False)), _("User name")) + self.setOption('password', NoSave(ConfigPassword(default="password")), _("Password")) - self.setOption( 'mailfrom', NoSave(ConfigText(default="abc@provider.com", fixed_size=False)), _("Mail from") ) - self.setOption( 'mailto', NoSave(ConfigText(fixed_size=False)), _("Mail to or leave empty (From will be used)") ) + self.setOption('mailfrom', NoSave(ConfigText(default="abc@provider.com", fixed_size=False)), _("Mail from")) + self.setOption('mailto', NoSave(ConfigText(fixed_size=False)), _("Mail to or leave empty (From will be used)")) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE @@ -79,15 +79,15 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): # Prepare message if body == "": body = subject - subject = MAIL_HEADER_TEMPLATE.format( **{'box': config.pushservice.boxname.value, 'name': NAME, 'plugin': pluginname, 'subject': subject} ) - body = MAIL_BODY_TEMPLATE.format( **{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE} ) + subject = MAIL_HEADER_TEMPLATE.format(**{'box': config.pushservice.boxname.value, 'name': NAME, 'plugin': pluginname, 'subject': subject}) + body = MAIL_BODY_TEMPLATE.format(**{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE}) message = Message(from_addr, to_addrs, subject, body) #TODO change mime="text/plain", charset="utf-8") if attachments: for attachment in attachments: message.attach(attachment) #TODO change mime=None, charset=None, content=None): # Send message - log.debug( ("PushService PushMail: Sending message: %s") % subject ) + log.debug(("PushService PushMail: Sending message: %s") % subject) deferred, connector = sendmail(mailconf, message) # Add callbacks diff --git a/src/Services/gntp/cli.py b/src/Services/gntp/cli.py index a5801fa..0090935 100644 --- a/src/Services/gntp/cli.py +++ b/src/Services/gntp/cli.py @@ -45,7 +45,7 @@ def parse_args(self, args=None, values=None): values, args = OptionParser.parse_args(self, args, values) if values.message is None: - log.debug( 'Enter a message followed by Ctrl-D' ) + log.debug('Enter a message followed by Ctrl-D') try: message = sys.stdin.read() except KeyboardInterrupt: diff --git a/src/plugin.py b/src/plugin.py index 951c482..ad57fa4 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -60,7 +60,7 @@ def setup(session, **kwargs): ### session.open(ConfigScreen.ConfigScreen) except Exception, e: - log.exception( ("PushService setup exception ") + str(e) ) + log.exception(("PushService setup exception ") + str(e)) ####################################################### @@ -73,7 +73,7 @@ def autostart(reason, **kwargs): gPushService = PushService() gPushService.start() except Exception, e: - log.exception( ("PushService autostart exception ") + str(e) ) + log.exception(("PushService autostart exception ") + str(e)) ####################################################### @@ -84,9 +84,9 @@ def Plugins(**kwargs): if config.pushservice.enable.value: # AutoStart - descriptors.append( PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart, needsRestart=False) ) + descriptors.append(PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart, needsRestart=False)) #TODO icon - descriptors.append( PluginDescriptor(name=NAME, description=NAME + " " +_("configuration"), where=PluginDescriptor.WHERE_PLUGINMENU, fnc=setup, needsRestart=False) ) #icon = "/icon.png" + descriptors.append(PluginDescriptor(name=NAME, description=NAME + " " +_("configuration"), where=PluginDescriptor.WHERE_PLUGINMENU, fnc=setup, needsRestart=False)) #icon = "/icon.png" return descriptors From 8ec16fda5ce5a2fcc277000a21abeea70d329ce3 Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:23 +0430 Subject: [PATCH 5/8] PEP8 double aggressive E22, E224, E241, E242 and E27 --- src/ConfigFile.py | 4 +-- src/ConfigScreen.py | 44 ++++++++++++------------ src/Controller/APTUpdateNotification.py | 2 +- src/Controller/ActiveTimers.py | 6 ++-- src/Controller/BrokenRecords.py | 4 +-- src/Controller/CrashLog.py | 2 +- src/Controller/DeactivatedTimers.py | 8 ++--- src/Controller/FreeSpace.py | 24 ++++++------- src/Controller/IPKGUpdateNotification.py | 4 +-- src/Controller/ListDir.py | 6 ++-- src/Controller/MissingTimers.py | 6 ++-- src/Controller/OPKGUpdateNotification.py | 2 +- src/Controller/RecordNotification.py | 8 ++--- src/Controller/RecordSummary.py | 8 ++--- src/Controller/SendLog.py | 12 +++---- src/Controller/StandbyNotification.py | 6 ++-- src/Logger.py | 6 ++-- src/OrderedDict.py | 2 +- src/PushService.py | 6 ++-- src/Services/GNTP.py | 14 ++++---- src/Services/SMTP.py | 32 ++++++++--------- src/__init__.py | 32 ++++++++--------- src/plugin.py | 2 +- 23 files changed, 120 insertions(+), 120 deletions(-) diff --git a/src/ConfigFile.py b/src/ConfigFile.py index 67f6d51..57f772c 100644 --- a/src/ConfigFile.py +++ b/src/ConfigFile.py @@ -29,14 +29,14 @@ from Logger import log def indent(elem, level=0): - i = "\n" + level*" " + i = "\n" + level * " " if len(elem): if not elem.text or not elem.text.strip(): elem.text = i + " " if not elem.tail or not elem.tail.strip(): elem.tail = i for elem in elem: - indent(elem, level+1) + indent(elem, level + 1) if not elem.tail or not elem.tail.strip(): elem.tail = i else: diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index a2496ab..510ec5c 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -76,9 +76,9 @@ def __init__(self, session): self.load() # Buttons - self["key_red"] = StaticText("") - self["key_green"] = StaticText("") - self["key_blue"] = StaticText("") + self["key_red"] = StaticText("") + self["key_green"] = StaticText("") + self["key_blue"] = StaticText("") self["key_yellow"] = StaticText("") self.help_window = None @@ -87,39 +87,39 @@ def __init__(self, session): #E2 Bug self["custom_actions"] = HelpableActionMap(self, ["SetupActions", "ColorActions", "PushServiceConfigActions"], self["custom_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { - "pageUp": (self.pageUp, _("Page up")), - "pageDown": (self.pageDown, _("Page down")), + "pageUp": (self.pageUp, _("Page up")), + "pageDown": (self.pageDown, _("Page down")), }, -2) # higher priority self["main_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { - "red": (self.keyCancel, _("Exit without saving")), - "green": (self.keySave, _("Save and exit")), + "red": (self.keyCancel, _("Exit without saving")), + "green": (self.keySave, _("Save and exit")), }, -2) # higher priority self["main_actions"].setEnabled(False) self["main_actions_enabled"] = HelpableActionMap(self, "PushServiceConfigActions", { - "yellow": (self.showServices, _("Show Services")), - "blue": (self.showControllers, _("Show Controllers")), + "yellow": (self.showServices, _("Show Services")), + "blue": (self.showControllers, _("Show Controllers")), }, -2) # higher priority self["main_actions_enabled"].setEnabled(False) self["service_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { - "red": (self.showMain, _("Back to main screen")), - "green": (self.testService, _("Test selected Service")), - "yellow": (self.addServices, _("Add Service")), - "blue": (self.removeServices, _("Remove Service")), + "red": (self.showMain, _("Back to main screen")), + "green": (self.testService, _("Test selected Service")), + "yellow": (self.addServices, _("Add Service")), + "blue": (self.removeServices, _("Remove Service")), }, -2) # higher priority self["service_actions"].setEnabled(False) self["controller_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { - "red": (self.showMain, _("Back to main screen")), - "green": (self.testController, _("Test selected Controller")), - "yellow": (self.addControllers, _("Add Controller")), - "blue": (self.removeControllers, _("Remove Controller")), + "red": (self.showMain, _("Back to main screen")), + "green": (self.testController, _("Test selected Controller")), + "yellow": (self.addControllers, _("Add Controller")), + "blue": (self.removeControllers, _("Remove Controller")), }, -2) # higher priority self["controller_actions"].setEnabled(False) @@ -163,7 +163,7 @@ def buildEntries(entries): self.list.append(getConfigListEntry(entry.getNameId(), entry.getConfigEnable(), idx)) if entry.getUniqueID() == uniqueid: # Select the added entry - select = len(self.list)-1 + select = len(self.list) - 1 if entry.getEnable(): for key, element, description in entry.getConfigOptions(): self.list.append(getConfigListEntry(" " + str(description), element, idx)) @@ -411,10 +411,10 @@ def __init__(self, session, test): self["text"] = ScrollLabel("") self["actions"] = ActionMap(["WizardActions", "DirectionActions"], { - "ok": self.cancel, - "back": self.cancel, - "up": self["text"].pageUp, - "down": self["text"].pageDown + "ok": self.cancel, + "back": self.cancel, + "up": self["text"].pageUp, + "down": self["text"].pageDown }, -1) # Set title and text diff --git a/src/Controller/APTUpdateNotification.py b/src/Controller/APTUpdateNotification.py index 7f1c4d6..91d0f1f 100644 --- a/src/Controller/APTUpdateNotification.py +++ b/src/Controller/APTUpdateNotification.py @@ -33,7 +33,7 @@ # Constants SUBJECT = _("APT Update Notification") -BODY = _("There are updates available:\n%s") +BODY = _("There are updates available:\n%s") class APTUpdateNotification(ControllerBase): diff --git a/src/Controller/ActiveTimers.py b/src/Controller/ActiveTimers.py index 7bb3dac..fb18100 100644 --- a/src/Controller/ActiveTimers.py +++ b/src/Controller/ActiveTimers.py @@ -31,8 +31,8 @@ # Constants SUBJECT = _("Found active timer(s)") -BODY = _("Active timer list:\n%s") -TAG = _("ActiveTimerPushed") +BODY = _("Active timer list:\n%s") +TAG = _("ActiveTimerPushed") class ActiveTimers(ControllerBase): @@ -59,7 +59,7 @@ def run(self, callback, errback): log.debug(_("ActiveTimers: Skip justplay") + str(timer.name)) pass - elif str(timer.service_ref)[0]=="-": + elif str(timer.service_ref)[0] == "-": log.debug(_("ActiveTimers: Skip serviceref") + str(timer.name)) pass diff --git a/src/Controller/BrokenRecords.py b/src/Controller/BrokenRecords.py index adf5b1c..6bf1df8 100644 --- a/src/Controller/BrokenRecords.py +++ b/src/Controller/BrokenRecords.py @@ -30,7 +30,7 @@ # Constants SUBJECT = _("Broken records") -BODY = _("There are broken records - %s") +BODY = _("There are broken records - %s") class BrokenRecords(ControllerBase): @@ -46,7 +46,7 @@ def run(self, callback, errback): # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent yesterday_end = time() - yesterday_begin = yesterday_end - 24*60*60 + yesterday_begin = yesterday_end - 24 * 60 * 60 broken_records = [] for root, dirnames, filenames in os.walk(config.usage.default_path.value): diff --git a/src/Controller/CrashLog.py b/src/Controller/CrashLog.py index 7bc6d3c..549f442 100644 --- a/src/Controller/CrashLog.py +++ b/src/Controller/CrashLog.py @@ -31,7 +31,7 @@ CRASHLOG_DIR = '/media/hdd' SUBJECT = _("Found CrashLog(s)") -BODY = _("Crashlog(s) are attached") +BODY = _("Crashlog(s) are attached") class CrashLog(ControllerBase): diff --git a/src/Controller/DeactivatedTimers.py b/src/Controller/DeactivatedTimers.py index 00bd7c0..2a5b79c 100644 --- a/src/Controller/DeactivatedTimers.py +++ b/src/Controller/DeactivatedTimers.py @@ -29,8 +29,8 @@ # Constants SUBJECT = _("Found deactivated timer(s)") -BODY = _("Deactivated timer list:\n%s") -TAG = _("DeactivatedTimerPushed") +BODY = _("Deactivated timer list:\n%s") +TAG = _("DeactivatedTimerPushed") class DeactivatedTimers(ControllerBase): @@ -67,7 +67,7 @@ def timerToString(timer): if timer.justplay: pass - elif str(timer.service_ref)[0]=="-": + elif str(timer.service_ref)[0] == "-": pass elif TAG in timer.tags: @@ -88,7 +88,7 @@ def timerToString(timer): for t in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers: if not t.disabled and not t.justplay and t.name == timer.name and t.eit != timer.eit: - text += "\t" + timerToString(t) + "\r\n" + text += "\t" + timerToString(t) + "\r\n" text += "\r\n" diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index 18dc286..c422ea9 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -31,7 +31,7 @@ # Constants SUBJECT = _("Free space warning") -BODY = _("Free disk space limit has been reached:\n") \ +BODY = _("Free disk space limit has been reached:\n") \ + _("Path: %s\n") \ + _("Limit: %d GB\n") \ + _("Left: %s") @@ -39,7 +39,7 @@ #Adapted from: from Components.Harddisk import findMountPoint def mountpoint(path): path = os.path.realpath(path) - if os.path.ismount(path) or len(path)==0: + if os.path.ismount(path) or len(path) == 0: return path return mountpoint(os.path.dirname(path)) @@ -72,10 +72,10 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption('wakehdd', NoSave(ConfigYesNo(default=False)), _("Allow HDD wake up")) - self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie", fixed_size=False)), _("Where to check free space")) - self.setOption('limit', NoSave(ConfigNumber(default=100)), _("Free space limit in GB")) - self.setOption('listtimer',NoSave(ConfigYesNo(default=False)), _("List upcoming timer")) + self.setOption('wakehdd', NoSave(ConfigYesNo(default=False)), _("Allow HDD wake up")) + self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie", fixed_size=False)), _("Where to check free space")) + self.setOption('limit', NoSave(ConfigNumber(default=100)), _("Free space limit in GB")) + self.setOption('listtimer',NoSave(ConfigYesNo(default=False)), _("List upcoming timer")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback @@ -100,12 +100,12 @@ def run(self, callback, errback): # Check free space on path if os.path.exists(path): stat = os.statvfs(path) - free = (stat.f_bavail if stat.f_bavail!=0 else stat.f_bfree) * stat.f_bsize / 1024 / 1024 # MB - if limit > (free/1024): #GB - if free >= 10*1024: #MB - free = "%d GB" %(free/1024) + free = (stat.f_bavail if stat.f_bavail != 0 else stat.f_bfree) * stat.f_bsize / 1024 / 1024 # MB + if limit > (free / 1024): #GB + if free >= 10 * 1024: #MB + free = "%d GB" % (free / 1024) else: - free = "%d MB" %(free) + free = "%d MB" % (free) # Not enough free space text = "" if self.getValue('listtimer'): @@ -117,7 +117,7 @@ def run(self, callback, errback): next_day = now + 86400 # Add one day for t in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers: if not t.disabled and not t.justplay and now < t.begin and t.end < next_day: - text += "\t" + timerToString(t) + "\r\n" + text += "\t" + timerToString(t) + "\r\n" callback(SUBJECT, BODY % (path, limit, free) + text) else: diff --git a/src/Controller/IPKGUpdateNotification.py b/src/Controller/IPKGUpdateNotification.py index 3c71622..3cc2acc 100644 --- a/src/Controller/IPKGUpdateNotification.py +++ b/src/Controller/IPKGUpdateNotification.py @@ -33,7 +33,7 @@ # Constants SUBJECT = _("IPKG Update Notification") -BODY = _("There are updates available:\n%s") +BODY = _("There are updates available:\n%s") class IPKGUpdateNotification(ControllerBase): @@ -51,7 +51,7 @@ def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent - if iSoftwareTools.lastDownloadDate is not None and iSoftwareTools.lastDownloadDate > (time() - (24*60*60)): + if iSoftwareTools.lastDownloadDate is not None and iSoftwareTools.lastDownloadDate > (time() - (24 * 60 * 60)): # Last refresh was within one day return self.buildList(callback, errback) else: diff --git a/src/Controller/ListDir.py b/src/Controller/ListDir.py index 8f0278c..17744c8 100644 --- a/src/Controller/ListDir.py +++ b/src/Controller/ListDir.py @@ -41,11 +41,11 @@ class ListDir(ControllerBase): def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - self.movielist= [] + self.movielist = [] # Default configuration - self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie/", fixed_size=False)), _("Where to check")) - self.setOption('ext', NoSave(ConfigText(default=".ts", fixed_size=False)), _("file extension")) + self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie/", fixed_size=False)), _("Where to check")) + self.setOption('ext', NoSave(ConfigText(default=".ts", fixed_size=False)), _("file extension")) def run(self, callback, errback): diff --git a/src/Controller/MissingTimers.py b/src/Controller/MissingTimers.py index 759ea51..445b01c 100644 --- a/src/Controller/MissingTimers.py +++ b/src/Controller/MissingTimers.py @@ -30,7 +30,7 @@ # Constants SUBJECT = _("Missing timer") -BODY = _("There are no timer for tomorrow - %s") +BODY = _("There are no timer for tomorrow - %s") class MissingTimers(ControllerBase): @@ -47,10 +47,10 @@ def run(self, callback, errback): # If empty or none is returned, nothing will be sent timers = 0 tomorrow_begin = mktime((date.today() + timedelta(days=1)).timetuple()) - tomorrow_end = tomorrow_begin + 24*60*60 + tomorrow_end = tomorrow_begin + 24 * 60 * 60 for timer in NavigationInstance.instance.RecordTimer.timer_list: - if not timer.disabled and str(timer.service_ref)[0]!="-": + if not timer.disabled and str(timer.service_ref)[0] != "-": timer_begin = timer.begin if tomorrow_begin <= timer_begin <= tomorrow_end: timers += 1 diff --git a/src/Controller/OPKGUpdateNotification.py b/src/Controller/OPKGUpdateNotification.py index c953367..d59a2a9 100644 --- a/src/Controller/OPKGUpdateNotification.py +++ b/src/Controller/OPKGUpdateNotification.py @@ -33,7 +33,7 @@ # Constants SUBJECT = _("OPKG Update Notification") -BODY = _("There are updates available:\n%s") +BODY = _("There are updates available:\n%s") class OPKGUpdateNotification(ControllerBase): diff --git a/src/Controller/RecordNotification.py b/src/Controller/RecordNotification.py index 09400fe..df9e53f 100644 --- a/src/Controller/RecordNotification.py +++ b/src/Controller/RecordNotification.py @@ -48,9 +48,9 @@ def __init__(self): self.forceBindRecordTimer.callback.append(self.begin) # Default configuration - self.setOption('send_on_start', NoSave(ConfigYesNo(default=False)), _("Send notification on record start")) - self.setOption('send_on_end', NoSave(ConfigYesNo(default=True)), _("Send notification on record end")) - self.setOption('include_description', NoSave(ConfigYesNo(default=False)), _("Include timer description")) + self.setOption('send_on_start', NoSave(ConfigYesNo(default=False)), _("Send notification on record start")) + self.setOption('send_on_end', NoSave(ConfigYesNo(default=True)), _("Send notification on record end")) + self.setOption('include_description', NoSave(ConfigYesNo(default=False)), _("Include timer description")) #TODO option to send free space def begin(self): @@ -89,7 +89,7 @@ def onRecordEvent(self, timer): if timer.justplay: pass - elif str(timer.service_ref)[0]=="-": + elif str(timer.service_ref)[0] == "-": pass elif timer.state == timer.StatePrepared: diff --git a/src/Controller/RecordSummary.py b/src/Controller/RecordSummary.py index 56c4bf5..c620917 100644 --- a/src/Controller/RecordSummary.py +++ b/src/Controller/RecordSummary.py @@ -30,8 +30,8 @@ # Constants SUBJECT = _("Record Summary") -BODY = _("Finished record list:\n%s") -TAG = _("FinishedTimerPushed") +BODY = _("Finished record list:\n%s") +TAG = _("FinishedTimerPushed") class RecordSummary(ControllerBase): @@ -44,7 +44,7 @@ def __init__(self): self.timers = [] # Default configuration - self.setOption('remove_timer', NoSave(ConfigYesNo(default=False)), _("Remove finished timer(s)")) + self.setOption('remove_timer', NoSave(ConfigYesNo(default=False)), _("Remove finished timer(s)")) self.setOption('include_description', NoSave(ConfigYesNo(default=False)), _("Include timer description")) def run(self, callback, errback): @@ -57,7 +57,7 @@ def run(self, callback, errback): if timer.justplay: pass - elif str(timer.service_ref)[0]=="-": + elif str(timer.service_ref)[0] == "-": pass elif TAG in timer.tags: diff --git a/src/Controller/SendLog.py b/src/Controller/SendLog.py index 0c8e8d4..ea36178 100644 --- a/src/Controller/SendLog.py +++ b/src/Controller/SendLog.py @@ -30,7 +30,7 @@ # Constants SUBJECT = _("Found Log(s)") -BODY = _("Log(s) are attached") +BODY = _("Log(s) are attached") class SendLog(ControllerBase): @@ -43,12 +43,12 @@ def __init__(self): self.logfiles = [] # Default configuration - self.setOption('path', NoSave(ConfigText(default="/media/hdd/", fixed_size=False)), _("Path to check")) - self.setOption('file_pattern', NoSave(ConfigText(default="*.log", fixed_size=False)), _("Filename pattern (No RegExp)")) + self.setOption('path', NoSave(ConfigText(default="/media/hdd/", fixed_size=False)), _("Path to check")) + self.setOption('file_pattern', NoSave(ConfigText(default="*.log", fixed_size=False)), _("Filename pattern (No RegExp)")) self.setOption('content_pattern', NoSave(ConfigText(default=".*", fixed_size=False)), _("Content pattern (RegExp)")) - self.setOption('scan_subs', NoSave(ConfigYesNo(default=False)), _("Scan subfolders")) - self.setOption('rename_logs', NoSave(ConfigYesNo(default=False)), _("Rename log(s)")) - self.setOption('delete_logs', NoSave(ConfigYesNo(default=False)), _("Delete log(s)")) + self.setOption('scan_subs', NoSave(ConfigYesNo(default=False)), _("Scan subfolders")) + self.setOption('rename_logs', NoSave(ConfigYesNo(default=False)), _("Rename log(s)")) + self.setOption('delete_logs', NoSave(ConfigYesNo(default=False)), _("Delete log(s)")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/StandbyNotification.py b/src/Controller/StandbyNotification.py index 39c685f..2c102d9 100644 --- a/src/Controller/StandbyNotification.py +++ b/src/Controller/StandbyNotification.py @@ -39,10 +39,10 @@ def __init__(self): ControllerBase.__init__(self) # Default configuration - self.setOption('send_after_bootup', NoSave(ConfigYesNo(default=False)), _("Send notification after bootup")) + self.setOption('send_after_bootup', NoSave(ConfigYesNo(default=False)), _("Send notification after bootup")) self.setOption('send_before_shutdown', NoSave(ConfigYesNo(default=False)), _("Send notification before shutdown")) - self.setOption('send_before_standby', NoSave(ConfigYesNo(default=True)), _("Send notification before standby")) - self.setOption('send_after_standby', NoSave(ConfigYesNo(default=True)), _("Send notification after standby")) + self.setOption('send_before_standby', NoSave(ConfigYesNo(default=True)), _("Send notification before standby")) + self.setOption('send_after_standby', NoSave(ConfigYesNo(default=True)), _("Send notification after standby")) def leaveStandby(self, dummy=None): #log.debug( "leave standby" ) diff --git a/src/Logger.py b/src/Logger.py index 6b12aba..f909f28 100644 --- a/src/Logger.py +++ b/src/Logger.py @@ -110,7 +110,7 @@ def warning(self, *args): strargs, MessageBox.TYPE_WARNING, int(config.pushservice.popups_warning_timeout.value), - 'PS_PopUp_ID_Warning_'+strargs + 'PS_PopUp_ID_Warning_' + strargs ) def error(self, *args): @@ -128,7 +128,7 @@ def error(self, *args): strargs, MessageBox.TYPE_ERROR, int(config.pushservice.popups_error_timeout.value), - 'PS_PopUp_ID_Error_'+strargs + 'PS_PopUp_ID_Error_' + strargs ) def exception(self, *args): @@ -146,7 +146,7 @@ def exception(self, *args): strargs, MessageBox.TYPE_ERROR, int(config.pushservice.popups_error_timeout.value), - 'PS_PopUp_ID_Exception_'+strargs + 'PS_PopUp_ID_Exception_' + strargs ) import os diff --git a/src/OrderedDict.py b/src/OrderedDict.py index d817797..bf49eb4 100644 --- a/src/OrderedDict.py +++ b/src/OrderedDict.py @@ -237,7 +237,7 @@ def __eq__(self, other): ''' if isinstance(other, OrderedDict): - return len(self)==len(other) and self.items() == other.items() + return len(self) == len(other) and self.items() == other.items() return dict.__eq__(self, other) def __ne__(self, other): diff --git a/src/PushService.py b/src/PushService.py index 97d9fdf..1129c94 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -88,8 +88,8 @@ def next(self, state=None): or self.state == PSFIRST: cltime = config.pushservice.time.value lotime = localtime() - ltime = lotime[3]*60 + lotime[4] - ctime = cltime[0]*60 + cltime[1] + ltime = lotime[3] * 60 + lotime[4] + ctime = cltime[0] * 60 + cltime[1] seconds = 60 * abs(ctime - ltime) self.startTimer(seconds, PSFIRSTRUN) @@ -97,7 +97,7 @@ def next(self, state=None): or self.state == PSCYCLE: period = int(config.pushservice.period.value) if period > 0: - self.startTimer(period*60*60, PSCYCLE) + self.startTimer(period * 60 * 60, PSCYCLE) def do(self): self.run() diff --git a/src/Services/GNTP.py b/src/Services/GNTP.py index 2610fa4..4d1c9dd 100644 --- a/src/Services/GNTP.py +++ b/src/Services/GNTP.py @@ -31,7 +31,7 @@ APP_NAME = _("{box:s} {name:s}") NOTIFICATION_TYPE = _("{name:s}") GROWL_SUBJECT_TEMPLATE = _("{box:s}: {subject:s}") -GROWL_BODY_TEMPLATE = _("{body:s}\n\n") \ +GROWL_BODY_TEMPLATE = _("{body:s}\n\n") \ + _("Donate {donate:s}") @@ -45,12 +45,12 @@ def __init__(self): #self.sockets = [] # Default configuration - self.setOption('growlhost', NoSave(ConfigText(default="host", fixed_size=False)), _("Growl Host name")) - self.setOption('growlport', NoSave(ConfigNumber(default=23053)), _("Growl Port")) - self.setOption('timeout', NoSave(ConfigNumber(default=3)), _("Timeout")) - self.setOption('password', NoSave(ConfigPassword()), _("Password")) - self.setOption('sticky', NoSave(ConfigYesNo(default=True)), _("Send as sticky")) - self.setOption('priority', NoSave(ConfigNumber(default=1)), _("Send with priority")) + self.setOption('growlhost', NoSave(ConfigText(default="host", fixed_size=False)), _("Growl Host name")) + self.setOption('growlport', NoSave(ConfigNumber(default=23053)), _("Growl Port")) + self.setOption('timeout', NoSave(ConfigNumber(default=3)), _("Timeout")) + self.setOption('password', NoSave(ConfigPassword()), _("Password")) + self.setOption('sticky', NoSave(ConfigYesNo(default=True)), _("Send as sticky")) + self.setOption('priority', NoSave(ConfigNumber(default=1)), _("Send with priority")) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE diff --git a/src/Services/SMTP.py b/src/Services/SMTP.py index 8dd0dea..f4a7aae 100644 --- a/src/Services/SMTP.py +++ b/src/Services/SMTP.py @@ -30,7 +30,7 @@ # Constants MAIL_HEADER_TEMPLATE = _("{box:s} {name:s}: {plugin:s}: {subject:s}") -MAIL_BODY_TEMPLATE = _("{body:s}\n\n") \ +MAIL_BODY_TEMPLATE = _("{body:s}\n\n") \ + _("Provided by Dreambox Plugin {name:s} {version:s} - {plugin:s}\n") \ + _("C 2012 by betonme @ IHAD\n") \ + _("Support {support:s}\n") \ @@ -47,30 +47,30 @@ def __init__(self): self.connectors = [] # Default configuration - self.setOption('smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size=False)), _("SMTP Server")) - self.setOption('smtpport', NoSave(ConfigNumber(default=587)), _("SMTP Port")) - self.setOption('smtpssl', NoSave(ConfigYesNo(default=True)), _("SMTP SSL")) - self.setOption('smtptls', NoSave(ConfigYesNo(default=True)), _("SMTP TLS")) - self.setOption('timeout', NoSave(ConfigNumber(default=30)), _("Timeout")) + self.setOption('smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size=False)), _("SMTP Server")) + self.setOption('smtpport', NoSave(ConfigNumber(default=587)), _("SMTP Port")) + self.setOption('smtpssl', NoSave(ConfigYesNo(default=True)), _("SMTP SSL")) + self.setOption('smtptls', NoSave(ConfigYesNo(default=True)), _("SMTP TLS")) + self.setOption('timeout', NoSave(ConfigNumber(default=30)), _("Timeout")) - self.setOption('username', NoSave(ConfigText(default="user", fixed_size=False)), _("User name")) - self.setOption('password', NoSave(ConfigPassword(default="password")), _("Password")) + self.setOption('username', NoSave(ConfigText(default="user", fixed_size=False)), _("User name")) + self.setOption('password', NoSave(ConfigPassword(default="password")), _("Password")) - self.setOption('mailfrom', NoSave(ConfigText(default="abc@provider.com", fixed_size=False)), _("Mail from")) - self.setOption('mailto', NoSave(ConfigText(fixed_size=False)), _("Mail to or leave empty (From will be used)")) + self.setOption('mailfrom', NoSave(ConfigText(default="abc@provider.com", fixed_size=False)), _("Mail from")) + self.setOption('mailto', NoSave(ConfigText(fixed_size=False)), _("Mail to or leave empty (From will be used)")) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE # Set SMTP parameters mailconf = {} - mailconf["host"] = self.getValue('smtpserver') - mailconf["port"] = self.getValue('smtpport') + mailconf["host"] = self.getValue('smtpserver') + mailconf["port"] = self.getValue('smtpport') mailconf["username"] = self.getValue('username') mailconf["password"] = self.getValue('password') - mailconf["ssl"] = self.getValue('smtpssl') - mailconf["tls"] = self.getValue('smtptls') - mailconf["timeout"] = self.getValue('timeout') + mailconf["ssl"] = self.getValue('smtpssl') + mailconf["tls"] = self.getValue('smtptls') + mailconf["timeout"] = self.getValue('timeout') # Create message object from_addr = self.getValue('mailfrom') @@ -80,7 +80,7 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): if body == "": body = subject subject = MAIL_HEADER_TEMPLATE.format(**{'box': config.pushservice.boxname.value, 'name': NAME, 'plugin': pluginname, 'subject': subject}) - body = MAIL_BODY_TEMPLATE.format(**{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE}) + body = MAIL_BODY_TEMPLATE.format(**{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE}) message = Message(from_addr, to_addrs, subject, body) #TODO change mime="text/plain", charset="utf-8") if attachments: for attachment in attachments: diff --git a/src/__init__.py b/src/__init__.py index 68f674e..a73264f 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -7,29 +7,29 @@ # Config options -config.pushservice = ConfigSubsection() +config.pushservice = ConfigSubsection() -config.pushservice.about = ConfigNothing() +config.pushservice.about = ConfigNothing() -config.pushservice.enable = ConfigEnableDisable(default=True) +config.pushservice.enable = ConfigEnableDisable(default=True) -config.pushservice.boxname = ConfigText(default="Enigma2", fixed_size=False) -config.pushservice.xmlpath = ConfigText(default="/etc/enigma2/pushservice.xml", fixed_size=False) +config.pushservice.boxname = ConfigText(default="Enigma2", fixed_size=False) +config.pushservice.xmlpath = ConfigText(default="/etc/enigma2/pushservice.xml", fixed_size=False) -config.pushservice.time = ConfigClock(default=0) -config.pushservice.period = ConfigSelectionNumber(0, 1000, 1, default=24) -config.pushservice.runonboot = ConfigEnableDisable(default=True) -config.pushservice.bootdelay = ConfigSelectionNumber(5, 1000, 5, default=10) +config.pushservice.time = ConfigClock(default=0) +config.pushservice.period = ConfigSelectionNumber(0, 1000, 1, default=24) +config.pushservice.runonboot = ConfigEnableDisable(default=True) +config.pushservice.bootdelay = ConfigSelectionNumber(5, 1000, 5, default=10) -config.pushservice.push_errors = ConfigEnableDisable(default=False) +config.pushservice.push_errors = ConfigEnableDisable(default=False) -config.pushservice.popups_success_timeout = ConfigSelectionNumber(-1, 20, 1, default=3) -config.pushservice.popups_warning_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) -config.pushservice.popups_error_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) +config.pushservice.popups_success_timeout = ConfigSelectionNumber(-1, 20, 1, default=3) +config.pushservice.popups_warning_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) +config.pushservice.popups_error_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) -config.pushservice.log_shell = ConfigEnableDisable(default=False) -config.pushservice.log_write = ConfigEnableDisable(default=False) -config.pushservice.log_file = ConfigText(default="/tmp/pushservice.log", fixed_size=False) +config.pushservice.log_shell = ConfigEnableDisable(default=False) +config.pushservice.log_write = ConfigEnableDisable(default=False) +config.pushservice.log_file = ConfigText(default="/tmp/pushservice.log", fixed_size=False) def localeInit(): diff --git a/src/plugin.py b/src/plugin.py index ad57fa4..a38b69d 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -87,6 +87,6 @@ def Plugins(**kwargs): descriptors.append(PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart, needsRestart=False)) #TODO icon - descriptors.append(PluginDescriptor(name=NAME, description=NAME + " " +_("configuration"), where=PluginDescriptor.WHERE_PLUGINMENU, fnc=setup, needsRestart=False)) #icon = "/icon.png" + descriptors.append(PluginDescriptor(name=NAME, description=NAME + " " + _("configuration"), where=PluginDescriptor.WHERE_PLUGINMENU, fnc=setup, needsRestart=False)) #icon = "/icon.png" return descriptors From 07870cce83e3f2a4baa06ce1940fd4854287587f Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:23 +0430 Subject: [PATCH 6/8] PEP8 double aggressive E225 ~ E228 and E231 --- src/ConfigScreen.py | 8 ++++---- src/Controller/APTUpdateNotification.py | 6 +++--- src/Controller/CrashLog.py | 2 +- src/Controller/FreeSpace.py | 2 +- src/Controller/OPKGUpdateNotification.py | 6 +++--- src/Controller/SendLog.py | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index 510ec5c..1372749 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -259,7 +259,7 @@ def showServices(self): def addServices(self): self.hideHelpWindow() - self.session.openWithCallback(self.addServicesCB, ChoiceBox,_("Add Service"), self.getAvlServices()) + self.session.openWithCallback(self.addServicesCB, ChoiceBox, _("Add Service"), self.getAvlServices()) def addServicesCB(self, result): module = result and result[1] @@ -275,7 +275,7 @@ def removeServices(self): select = current[2] slist = self.getServiceInstances() if slist: - self.session.openWithCallback(self.removeServicesCB, ChoiceBox,_("Remove controller"), list=slist, selection=select) + self.session.openWithCallback(self.removeServicesCB, ChoiceBox, _("Remove controller"), list=slist, selection=select) def removeServicesCB(self, result): service = result and result[1] @@ -290,7 +290,7 @@ def showControllers(self): def addControllers(self): self.hideHelpWindow() - self.session.openWithCallback(self.addControllersCB, ChoiceBox,_("Add Controller"), self.getAvlControllers()) + self.session.openWithCallback(self.addControllersCB, ChoiceBox, _("Add Controller"), self.getAvlControllers()) def addControllersCB(self, result): module = result and result[1] @@ -306,7 +306,7 @@ def removeControllers(self): select = current[2] plist = self.getControllerInstances() if plist: - self.session.openWithCallback(self.removeControllersCB, ChoiceBox,_("Remove controller"), list=plist, selection=select) + self.session.openWithCallback(self.removeControllersCB, ChoiceBox, _("Remove controller"), list=plist, selection=select) def removeControllersCB(self, result): controller = result and result[1] diff --git a/src/Controller/APTUpdateNotification.py b/src/Controller/APTUpdateNotification.py index 91d0f1f..573b862 100644 --- a/src/Controller/APTUpdateNotification.py +++ b/src/Controller/APTUpdateNotification.py @@ -77,11 +77,11 @@ def opkgupgradable(self): def aptupgradableFinished(self, retval=None): try: - log.debug("PushService retval: ",str(retval)) + log.debug("PushService retval: ", str(retval)) except: pass try: - log.debug("PushService self.data: ",str(self.data)) + log.debug("PushService self.data: ", str(self.data)) except: pass @@ -91,7 +91,7 @@ def aptupgradableFinished(self, retval=None): if self.data: try: for line in self.data.split("\n"): - log.debug("PushService opkg upgradable data: ",line) + log.debug("PushService opkg upgradable data: ", line) if line.startswith("Inst"): updates += line[5:] + "\r\n" continue diff --git a/src/Controller/CrashLog.py b/src/Controller/CrashLog.py index 549f442..9e6d005 100644 --- a/src/Controller/CrashLog.py +++ b/src/Controller/CrashLog.py @@ -77,7 +77,7 @@ def callback(self): # Adapted from autosubmit - instead of .sent we will use .pushed currfilename = str(os.path.basename(crashlog)) newfilename = "/media/hdd/" + currfilename + ".pushed" - os.rename(crashlog,newfilename) + os.rename(crashlog, newfilename) self.crashlogs.remove(crashlog) def errback(self): diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index c422ea9..802aef0 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -75,7 +75,7 @@ def __init__(self): self.setOption('wakehdd', NoSave(ConfigYesNo(default=False)), _("Allow HDD wake up")) self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie", fixed_size=False)), _("Where to check free space")) self.setOption('limit', NoSave(ConfigNumber(default=100)), _("Free space limit in GB")) - self.setOption('listtimer',NoSave(ConfigYesNo(default=False)), _("List upcoming timer")) + self.setOption('listtimer', NoSave(ConfigYesNo(default=False)), _("List upcoming timer")) def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback diff --git a/src/Controller/OPKGUpdateNotification.py b/src/Controller/OPKGUpdateNotification.py index d59a2a9..189476e 100644 --- a/src/Controller/OPKGUpdateNotification.py +++ b/src/Controller/OPKGUpdateNotification.py @@ -77,11 +77,11 @@ def opkgupgradable(self): def opkgupgradableFinished(self, retval=None): try: - log.debug("PushService retval: ",str(retval)) + log.debug("PushService retval: ", str(retval)) except: pass try: - log.debug("PushService self.data: ",str(self.data)) + log.debug("PushService self.data: ", str(self.data)) except: pass @@ -91,7 +91,7 @@ def opkgupgradableFinished(self, retval=None): if self.data: try: for line in self.data.split("\n"): - log.debug("PushService opkg upgradable data: ",line) + log.debug("PushService opkg upgradable data: ", line) if line.startswith("Inflating"): continue if line.startswith("Updated"): diff --git a/src/Controller/SendLog.py b/src/Controller/SendLog.py index ea36178..9d975c6 100644 --- a/src/Controller/SendLog.py +++ b/src/Controller/SendLog.py @@ -67,7 +67,7 @@ def run(self, callback, errback): if(content_pattern == ".*"): self.logfiles.append(logfile) else: - infile = open(logfile,"r") + infile = open(logfile, "r") for line in infile: if prog.match(line): self.logfiles.append(logfile) @@ -80,7 +80,7 @@ def run(self, callback, errback): if(content_pattern == ".*"): self.logfiles.append(logfile) else: - infile = open(logfile,"r") + infile = open(logfile, "r") for line in infile: if prog.match(line): self.logfiles.append(logfile) @@ -108,7 +108,7 @@ def callback(self): # Adapted from autosubmit - instead of .sent we will use .pushed currfilename = str(os.path.basename(logfile)) newfilename = "/media/hdd/" + currfilename + ".pushed" - os.rename(logfile,newfilename) + os.rename(logfile, newfilename) self.logfiles.remove(logfile) def errback(self): From d9bd914f3ee01d3f1a9eab156595179c79d6b784 Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:24 +0430 Subject: [PATCH 7/8] PEP8 double aggressive E301 ~ E306 --- src/ConfigFile.py | 1 + src/ConfigScreen.py | 1 + src/Controller/FreeSpace.py | 5 +++++ src/Controller/ListDir.py | 3 --- src/ControllerBase.py | 3 +-- src/ModuleBase.py | 5 ++--- src/PushService.py | 2 +- src/PushServiceBase.py | 7 ++++--- src/ServiceBase.py | 3 +-- src/Services/gntp/__init__.py | 2 ++ src/Services/gntp/cli.py | 2 ++ src/Services/gntp/config.py | 2 ++ src/Services/gntp/notifier.py | 1 + src/Services/mail/mail.py | 1 + src/__init__.py | 2 ++ 15 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ConfigFile.py b/src/ConfigFile.py index 57f772c..4262747 100644 --- a/src/ConfigFile.py +++ b/src/ConfigFile.py @@ -28,6 +28,7 @@ from . import _ from Logger import log + def indent(elem, level=0): i = "\n" + level * " " if len(elem): diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index 1372749..57bd068 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -131,6 +131,7 @@ def __init__(self, session): # Override selectionChanged because our config tuples are bigger self.onChangedEntry = [] + def selectionChanged(): current = self["config"].getCurrent() if self["config"].current != current: diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index 802aef0..7bea275 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -37,24 +37,29 @@ + _("Left: %s") #Adapted from: from Components.Harddisk import findMountPoint + + def mountpoint(path): path = os.path.realpath(path) if os.path.ismount(path) or len(path) == 0: return path return mountpoint(os.path.dirname(path)) + def getDevicebyMountpoint(hdm, mountpoint): for x in hdm.partitions[:]: if x.mountpoint == mountpoint: return x.device return None + def getHDD(hdm, part): for hdd in hdm.hdd: if hdd.device == part[:3]: return hdd return None + def timerToString(timer): return str(timer.name) + "\t" \ + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \ diff --git a/src/Controller/ListDir.py b/src/Controller/ListDir.py index 17744c8..607573d 100644 --- a/src/Controller/ListDir.py +++ b/src/Controller/ListDir.py @@ -32,8 +32,6 @@ SUBJECT = _("List of Files") - - class ListDir(ControllerBase): ForceSingleInstance = True @@ -47,7 +45,6 @@ def __init__(self): self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie/", fixed_size=False)), _("Where to check")) self.setOption('ext', NoSave(ConfigText(default=".ts", fixed_size=False)), _("file extension")) - def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, body (List of Files) diff --git a/src/ControllerBase.py b/src/ControllerBase.py index f121d04..c5927b3 100644 --- a/src/ControllerBase.py +++ b/src/ControllerBase.py @@ -35,7 +35,6 @@ def __init__(self): ControllerBase.UniqueCounter += 1 self.uniqueid = ControllerBase.UniqueCounter - ################################################ # Base class functions @classmethod @@ -46,9 +45,9 @@ def forceSingle(cls): def resetUniqueID(): ControllerBase.UniqueCounter = 0 - ################################################ # Functions to be implemented in the plugin + def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment diff --git a/src/ModuleBase.py b/src/ModuleBase.py index db83caa..bfd6eb3 100644 --- a/src/ModuleBase.py +++ b/src/ModuleBase.py @@ -43,7 +43,6 @@ def __init__(self): # [ (key, value, description, config element) , ] #self.options['enabled'] = ConfigYesNo( default = False ) - ################################################ # Base classmethod functions @classmethod @@ -51,9 +50,9 @@ def getClass(cls): # Return the Class return cls.__name__ - ################################################ # Base functions + def getName(self): # Return the Class Name return self.__class__.__name__ @@ -118,9 +117,9 @@ def getStringOptions(self): def getConfigOptions(self): return [(key, option, description) for (key, (option, description)) in self.options.items()] - ################################################ # Functions to be implemented in the plugin + def begin(self): # Is called after starting PushSerive pass diff --git a/src/PushService.py b/src/PushService.py index 1129c94..744d707 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -57,9 +57,9 @@ def __init__(self): #TODO Run in a new thread - ###################################### # Statemachine and timer + def start(self): log.reinit() diff --git a/src/PushServiceBase.py b/src/PushServiceBase.py index 952a0f1..991dbb4 100644 --- a/src/PushServiceBase.py +++ b/src/PushServiceBase.py @@ -66,9 +66,9 @@ def __init__(self, path=""): self.servicemodules = self.loadModules(SERVICE_PATH, ServiceBase) self.controllermodules = self.loadModules(CONTROLLER_PATH, ControllerBase) - ###################################### # Setter / Getter + def getServices(self): return self.services or [] @@ -149,9 +149,9 @@ def removeController(self, controller): if controller in self.controllers: self.controllers.remove(controller) - ###################################### # Config + def copyto(self, destination): destination.services = self.services destination.controllers = self.controllers @@ -175,6 +175,7 @@ def load(self): ServiceBase.resetUniqueID() ControllerBase.resetUniqueID() # Parse Config + def parse(root, typ, modules): instances = [] if root: @@ -241,9 +242,9 @@ def build(root, instances, typ): self.writeXML(root) - ###################################### # Controller handling + def begin(self): # Loop over all Services for service in self.getServices(): diff --git a/src/ServiceBase.py b/src/ServiceBase.py index a65cb7a..8caba7c 100644 --- a/src/ServiceBase.py +++ b/src/ServiceBase.py @@ -34,7 +34,6 @@ def __init__(self): ServiceBase.UniqueCounter += 1 self.uniqueid = ServiceBase.UniqueCounter - ################################################ # Base class functions @classmethod @@ -45,9 +44,9 @@ def forceSingle(cls): def resetUniqueID(): ServiceBase.UniqueCounter = 0 - ################################################ # Functions to be implemented in the plugin + def push(self, callback, errback, pluginname, subject, body="", attachments=[]): # Will be called, if a plugin wants to send a notification # At the end a service has to call one of the functions: callback or errback diff --git a/src/Services/gntp/__init__.py b/src/Services/gntp/__init__.py index d8aef7e..ca0cc37 100644 --- a/src/Services/gntp/__init__.py +++ b/src/Services/gntp/__init__.py @@ -46,6 +46,7 @@ class UnsupportedError(BaseError): class _GNTPBuffer(StringIO.StringIO): """GNTP Buffer class""" + def writefmt(self, str="", *args): """Shortcut function for writing GNTP Headers""" self.write((str % args).encode('utf8', 'replace')) @@ -59,6 +60,7 @@ class _GNTPBase(object): :param string version: GNTP Protocol version :param string encription: Encryption protocol """ + def __init__(self, messagetype=None, version='1.0', encryption=None): self.info = { 'version': version, diff --git a/src/Services/gntp/cli.py b/src/Services/gntp/cli.py index 0090935..a655169 100644 --- a/src/Services/gntp/cli.py +++ b/src/Services/gntp/cli.py @@ -8,6 +8,7 @@ # Plugin internal from Plugins.Extensions.PushService.Logger import log + class ClientParser(OptionParser): def __init__(self): OptionParser.__init__(self) @@ -102,5 +103,6 @@ def main(): if result is not True: exit(result) + if __name__ == "__main__": main() diff --git a/src/Services/gntp/config.py b/src/Services/gntp/config.py index 3a7d3bc..beacee1 100644 --- a/src/Services/gntp/config.py +++ b/src/Services/gntp/config.py @@ -69,6 +69,7 @@ class GrowlNotifier(gntp.notifier.GrowlNotifier): password = ? port = ? """ + def __init__(self, applicationName='Python GNTP', notifications=[], defaultNotifications=None, applicationIcon=None, hostname='localhost', password=None, port=23053): @@ -100,6 +101,7 @@ def __init__(self, applicationName='Python GNTP', notifications=[], self.hostname = config.get('gntp', 'hostname') self.port = config.getint('gntp', 'port') + if __name__ == '__main__': # If we're running this module directly we're likely running it as a test # so extra debugging is useful diff --git a/src/Services/gntp/notifier.py b/src/Services/gntp/notifier.py index 92af597..9431b14 100644 --- a/src/Services/gntp/notifier.py +++ b/src/Services/gntp/notifier.py @@ -230,6 +230,7 @@ def _send(self, type, packet): logger.error('Invalid response: %s', response.error()) return response.error() + if __name__ == '__main__': # If we're running this module directly we're likely running it as a test # so extra debugging is useful diff --git a/src/Services/mail/mail.py b/src/Services/mail/mail.py index bc63dbc..530acdd 100644 --- a/src/Services/mail/mail.py +++ b/src/Services/mail/mail.py @@ -41,6 +41,7 @@ from twisted.internet.ssl import ClientContextFactory from twisted.mail.smtp import ESMTPSenderFactory + class Message(object): def __init__(self, from_addr, to_addrs, subject, message, mime="text/plain", charset="utf-8"): self.subject = subject diff --git a/src/__init__.py b/src/__init__.py index a73264f..444cbf3 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -37,6 +37,7 @@ def localeInit(): os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it! gettext.bindtextdomain("PushService", resolveFilename(SCOPE_PLUGINS, "Extensions/PushService/locale")) + def _(txt): if txt: t = gettext.dgettext("PushService", txt) @@ -46,5 +47,6 @@ def _(txt): else: return "" + localeInit() language.addCallback(localeInit) From 04abb5c72a8c4adf446709e907890cafc2b2588b Mon Sep 17 00:00:00 2001 From: persianpros Date: Wed, 14 Apr 2021 15:09:25 +0430 Subject: [PATCH 8/8] PEP8 double aggressive W291 ~ W293 and W391 --- src/ConfigFile.py | 15 +++-- src/ConfigScreen.py | 80 ++++++++++++------------ src/Controller/APTUpdateNotification.py | 21 +++---- src/Controller/ActiveTimers.py | 16 ++--- src/Controller/BrokenRecords.py | 8 +-- src/Controller/CrashLog.py | 4 +- src/Controller/DeactivatedTimers.py | 36 +++++------ src/Controller/FreeSpace.py | 20 +++--- src/Controller/IPKGUpdateNotification.py | 7 +-- src/Controller/ListDir.py | 28 ++++----- src/Controller/MissingTimers.py | 8 +-- src/Controller/OPKGUpdateNotification.py | 21 +++---- src/Controller/RecordNotification.py | 23 ++++--- src/Controller/RecordSummary.py | 14 ++--- src/Controller/SendLog.py | 6 +- src/Controller/StandbyNotification.py | 32 +++++----- src/ControllerBase.py | 6 +- src/Logger.py | 43 +++++++------ src/ModuleBase.py | 6 +- src/Modules.py | 24 +++---- src/PushService.py | 20 +++--- src/PushServiceBase.py | 36 +++++------ src/ServiceBase.py | 6 +- src/Services/GNTP.py | 18 +++--- src/Services/PopUp.py | 4 +- src/Services/SMTP.py | 22 +++---- src/Services/mail/mail.py | 42 ++++++------- src/__init__.py | 8 +-- src/plugin.py | 6 +- 29 files changed, 287 insertions(+), 293 deletions(-) diff --git a/src/ConfigFile.py b/src/ConfigFile.py index 4262747..6b32068 100644 --- a/src/ConfigFile.py +++ b/src/ConfigFile.py @@ -53,18 +53,18 @@ def __init__(self): def readXML(self): path = config.pushservice.xmlpath.value - + # Abort if no config found if not os.path.exists(path): log.debug("PushService No configuration file present") return None - + # Parse if mtime differs from whats saved mtime = os.path.getmtime(path) if mtime == self.mtime: # No changes in configuration, won't read again return self.cache - + # Parse XML try: etree = parse(path).getroot() @@ -72,7 +72,7 @@ def readXML(self): log.exception(("PushService Exception in readXML: ") + str(e)) etree = None mtime = -1 - + # Save time and cache file content self.mtime = mtime self.cache = etree @@ -80,10 +80,10 @@ def readXML(self): def writeXML(self, etree): path = config.pushservice.xmlpath.value - + indent(etree) data = tostring(etree, 'utf-8') - + f = None try: f = open(path, 'w') @@ -94,8 +94,7 @@ def writeXML(self, etree): finally: if f is not None: f.close() - + # Save time and cache file content self.mtime = os.path.getmtime(path) self.cache = etree - diff --git a/src/ConfigScreen.py b/src/ConfigScreen.py index 57bd068..9494505 100644 --- a/src/ConfigScreen.py +++ b/src/ConfigScreen.py @@ -64,25 +64,25 @@ def __init__(self, session): Screen.__init__(self, session) HelpableScreen.__init__(self) self.skinName = ["ConfigScreen", "ConfigListScreen"] - + from plugin import NAME, VERSION, gPushService self.setup_title = NAME + " " + _("Configuration") + " " + VERSION - + PushServiceBase.__init__(self) if gPushService: gPushService.stop() - + # Load local moduls to work on self.load() - + # Buttons self["key_red"] = StaticText("") self["key_green"] = StaticText("") self["key_blue"] = StaticText("") self["key_yellow"] = StaticText("") - + self.help_window = None - + # Define Actions #E2 Bug self["custom_actions"] = HelpableActionMap(self, ["SetupActions", "ColorActions", "PushServiceConfigActions"], self["custom_actions"] = HelpableActionMap(self, "PushServiceConfigActions", @@ -90,21 +90,21 @@ def __init__(self, session): "pageUp": (self.pageUp, _("Page up")), "pageDown": (self.pageDown, _("Page down")), }, -2) # higher priority - + self["main_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { "red": (self.keyCancel, _("Exit without saving")), "green": (self.keySave, _("Save and exit")), }, -2) # higher priority self["main_actions"].setEnabled(False) - + self["main_actions_enabled"] = HelpableActionMap(self, "PushServiceConfigActions", { "yellow": (self.showServices, _("Show Services")), "blue": (self.showControllers, _("Show Controllers")), }, -2) # higher priority self["main_actions_enabled"].setEnabled(False) - + self["service_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { "red": (self.showMain, _("Back to main screen")), @@ -113,7 +113,7 @@ def __init__(self, session): "blue": (self.removeServices, _("Remove Service")), }, -2) # higher priority self["service_actions"].setEnabled(False) - + self["controller_actions"] = HelpableActionMap(self, "PushServiceConfigActions", { "red": (self.showMain, _("Back to main screen")), @@ -122,13 +122,13 @@ def __init__(self, session): "blue": (self.removeControllers, _("Remove Controller")), }, -2) # higher priority self["controller_actions"].setEnabled(False) - + # Initialize Configuration part self.list = [] self.state = MAIN self.build() ConfigListScreen.__init__(self, self.list, session=session, on_change=self.change) - + # Override selectionChanged because our config tuples are bigger self.onChangedEntry = [] @@ -143,20 +143,20 @@ def selectionChanged(): for x in self["config"].onSelectionChanged: x() self["config"].selectionChanged = selectionChanged - + self.setTitle(self.setup_title) def change(self, uniqueid=None): select = self.build(uniqueid) self["config"].setList(self.list) - + if select is not None: self["config"].instance.moveSelectionTo(select) def build(self, uniqueid=None): self.list = [] select = None - + def buildEntries(entries): select = None if entries: @@ -169,7 +169,7 @@ def buildEntries(entries): for key, element, description in entry.getConfigOptions(): self.list.append(getConfigListEntry(" " + str(description), element, idx)) return select - + if self.state == MAIN: self["key_red"].setText(_("Cancel")) self["key_green"].setText(_("OK")) @@ -184,26 +184,26 @@ def buildEntries(entries): self["key_yellow"].setText("") self["key_blue"].setText("") self["main_actions_enabled"].setEnabled(False) - + self.list.append(getConfigListEntry(_("Enable PushService"), config.pushservice.enable, 0)) - + if config.pushservice.enable.value: self.list.append(getConfigListEntry(_("Dreambox name"), config.pushservice.boxname, 0)) self.list.append(getConfigListEntry(_("Config file"), config.pushservice.xmlpath, 0)) - + self.list.append(getConfigListEntry(_("Start time (HH:MM)"), config.pushservice.time, 0)) self.list.append(getConfigListEntry(_("Period in hours (0=disabled)"), config.pushservice.period, 0)) self.list.append(getConfigListEntry(_("Run on boot"), config.pushservice.runonboot, 0)) if config.pushservice.runonboot.value: self.list.append(getConfigListEntry(_("Boot delay"), config.pushservice.bootdelay, 0)) - + self.list.append(getConfigListEntry(_("Push errors"), config.pushservice.push_errors, 0)) - + self.list.append(getConfigListEntry(_("Log to shell"), config.pushservice.log_shell, 0)) self.list.append(getConfigListEntry(_("Log to file"), config.pushservice.log_write, 0)) if config.pushservice.log_write.value: self.list.append(getConfigListEntry(_("Log file path and name"), config.pushservice.log_file, 0)) - + elif self.state == SERVICES: self["key_red"].setText(_("Main")) self["key_green"].setText(_("Test")) @@ -213,9 +213,9 @@ def buildEntries(entries): self["main_actions_enabled"].setEnabled(False) self["controller_actions"].setEnabled(False) self["service_actions"].setEnabled(True) - + select = buildEntries(self.getServices()) - + elif self.state == CONTROLLERS: self["key_red"].setText(_("Main")) self["key_green"].setText(_("Test")) @@ -225,9 +225,9 @@ def buildEntries(entries): self["main_actions_enabled"].setEnabled(False) self["service_actions"].setEnabled(False) self["controller_actions"].setEnabled(True) - + select = buildEntries(self.getControllers()) - + return select def getCurrentEntry(self): @@ -318,13 +318,13 @@ def removeControllersCB(self, result): # Overwrite ConfigListScreen keySave function def keySave(self): self.hideHelpWindow() - + # Save E2 PushService config self.saveAll() - + # Build xml config and write it self.save() - + # If we need assign / "write" access import the plugin # global won't work across module scope import plugin @@ -339,7 +339,7 @@ def keySave(self): else: #global gPushService plugin.gPushService = None - + self.close() # Overwrite ConfigListScreen keyCancel function @@ -355,7 +355,7 @@ def cancelConfirm(self, result): # Make sure the configuration is still consistent gPushService.load() gPushService.start() - + # Call baseclass function ConfigListScreen.cancelConfirm(self, result) @@ -373,11 +373,11 @@ def testService(self): # Allows testing the actually not saved configuration #if self.state != SERVICES: return self.hideHelpWindow() - + # Get the selected Service current = self["config"].getCurrent() service = current and self.getService(current[2]) - + if service and service.getEnable(): self.session.open(TestConsole, service) @@ -385,11 +385,11 @@ def testController(self): # Allows testing the actually not saved configuration #if self.state != CONTROLLERS: return self.hideHelpWindow() - + # Get the selected Controller current = self["config"].getCurrent() controller = current and self.getController(current[2]) - + if controller and controller.getEnable(): self.session.open(TestConsole, controller) @@ -408,16 +408,16 @@ def __init__(self, session, test): title = "" text = "" self.test = test - + self["text"] = ScrollLabel("") - self["actions"] = ActionMap(["WizardActions", "DirectionActions"], + self["actions"] = ActionMap(["WizardActions", "DirectionActions"], { "ok": self.cancel, "back": self.cancel, "up": self["text"].pageUp, "down": self["text"].pageDown }, -1) - + # Set title and text test.begin() if isinstance(test, ServiceBase): @@ -429,10 +429,10 @@ def __init__(self, session, test): else: title = _("Testing") text = _("Nothing to test") - + self.setTitle(title) self.setText(text) - + # Starting test try: if isinstance(test, ServiceBase): diff --git a/src/Controller/APTUpdateNotification.py b/src/Controller/APTUpdateNotification.py index 573b862..ad08607 100644 --- a/src/Controller/APTUpdateNotification.py +++ b/src/Controller/APTUpdateNotification.py @@ -37,16 +37,16 @@ class APTUpdateNotification(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - + # Default configuration self.setOption('selfcheck', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) - + self.data = "" self.container = eConsoleAppContainer() try: @@ -75,7 +75,7 @@ def opkgupgradable(self): self.container.execute("apt-get --just-print upgrade") def aptupgradableFinished(self, retval=None): - + try: log.debug("PushService retval: ", str(retval)) except: @@ -84,10 +84,10 @@ def aptupgradableFinished(self, retval=None): log.debug("PushService self.data: ", str(self.data)) except: pass - + updates = "" excepts = "" - + if self.data: try: for line in self.data.split("\n"): @@ -97,16 +97,15 @@ def aptupgradableFinished(self, retval=None): continue except Exception, e: excepts += "\r\n\r\nException:\r\n" + str(e) - + if excepts: log.exception(excepts) - + if updates: #callback( SUBJECT, BODY % (updates) ) - + #TODO Problem test run won't get the message # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, BODY % (updates)) - diff --git a/src/Controller/ActiveTimers.py b/src/Controller/ActiveTimers.py index fb18100..7ee8b45 100644 --- a/src/Controller/ActiveTimers.py +++ b/src/Controller/ActiveTimers.py @@ -36,14 +36,14 @@ class ActiveTimers(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) self.timers = [] - + # Default configuration self.setOption('add_tag', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) @@ -58,23 +58,23 @@ def run(self, callback, errback): if timer.justplay: log.debug(_("ActiveTimers: Skip justplay") + str(timer.name)) pass - + elif str(timer.service_ref)[0] == "-": log.debug(_("ActiveTimers: Skip serviceref") + str(timer.name)) pass - + elif self.getValue('add_tag') and TAG in timer.tags: log.debug(_("ActiveTimers: Skip tag") + str(timer.name)) pass - + elif timer.disabled: log.debug(_("ActiveTimers: Skip disabled") + str(timer.name)) pass - + elif timer.begin < now: log.debug(_("ActiveTimers: Skip begin < now") + str(timer.name)) pass - + else: text += str(timer.name) + " " \ + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \ diff --git a/src/Controller/BrokenRecords.py b/src/Controller/BrokenRecords.py index 6bf1df8..138a855 100644 --- a/src/Controller/BrokenRecords.py +++ b/src/Controller/BrokenRecords.py @@ -34,9 +34,9 @@ class BrokenRecords(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) @@ -47,7 +47,7 @@ def run(self, callback, errback): # If empty or none is returned, nothing will be sent yesterday_end = time() yesterday_begin = yesterday_end - 24 * 60 * 60 - + broken_records = [] for root, dirnames, filenames in os.walk(config.usage.default_path.value): for filename in fnmatch.filter(filenames, '*.ts'): @@ -56,7 +56,7 @@ def run(self, callback, errback): if yesterday_begin <= record_end <= yesterday_end: if os.path.getsize(record_path) < 10000000: # 10MB broken_records.append(record_path) - + if broken_records: callback(SUBJECT, BODY % "\n\n" + "\n".join(broken_records)) else: diff --git a/src/Controller/CrashLog.py b/src/Controller/CrashLog.py index 9e6d005..2778eb0 100644 --- a/src/Controller/CrashLog.py +++ b/src/Controller/CrashLog.py @@ -35,9 +35,9 @@ class CrashLog(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) diff --git a/src/Controller/DeactivatedTimers.py b/src/Controller/DeactivatedTimers.py index 2a5b79c..2b4612b 100644 --- a/src/Controller/DeactivatedTimers.py +++ b/src/Controller/DeactivatedTimers.py @@ -34,14 +34,14 @@ class DeactivatedTimers(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) self.timers = [] - + # Default configuration self.setOption('remove_timer', NoSave(ConfigYesNo(default=False)), _("Remove deactivated timer(s)")) self.setOption('list_similar', NoSave(ConfigYesNo(default=False)), _("List similar timer(s)")) @@ -50,50 +50,50 @@ def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent - + self.timers = [] text = "" list_similar = self.getValue('list_similar') - + def timerToString(timer): return str(timer.name) + "\t" \ + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \ + strftime(_("%H:%M"), localtime(timer.end)) + "\t" \ + str(timer.service_ref and timer.service_ref.getServiceName() or "") \ + "\t" + str(timer.tags) - + import NavigationInstance for timer in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers: if timer.justplay: pass - + elif str(timer.service_ref)[0] == "-": pass - + elif TAG in timer.tags: pass - + elif not timer.disabled: pass - + else: text += timerToString(timer) + "\r\n" - + if list_similar: if not timer.eit: text += "\r\n\r\n" + _("Timer has no EIT") + "\r\n\r\n" continue - + text += "\r\n\r\n" + _("Similar:") + "\r\n" - + for t in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers: if not t.disabled and not t.justplay and t.name == timer.name and t.eit != timer.eit: text += "\t" + timerToString(t) + "\r\n" - + text += "\r\n" - + self.timers.append(timer) - + if self.timers and text: callback(SUBJECT, BODY % text) else: @@ -104,7 +104,7 @@ def callback(self): import NavigationInstance # Called after all services succeded if self.getValue('remove_timer'): - + # Remove deactivated timers for timer in self.timers[:]: if timer in NavigationInstance.instance.RecordTimer.processed_timers: @@ -112,7 +112,7 @@ def callback(self): elif timer in NavigationInstance.instance.RecordTimer.timer_list: NavigationInstance.instance.RecordTimer.timer_list.remove(timer) self.timers.remove(timer) - + # Set tag to avoid resending it for timer in self.timers: if TAG not in timer.tags: diff --git a/src/Controller/FreeSpace.py b/src/Controller/FreeSpace.py index 7bea275..16258b2 100644 --- a/src/Controller/FreeSpace.py +++ b/src/Controller/FreeSpace.py @@ -44,7 +44,7 @@ def mountpoint(path): if os.path.ismount(path) or len(path) == 0: return path return mountpoint(os.path.dirname(path)) - + def getDevicebyMountpoint(hdm, mountpoint): for x in hdm.partitions[:]: @@ -69,26 +69,26 @@ def timerToString(timer): class FreeSpace(ControllerBase): - + ForceSingleInstance = False - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - + # Default configuration self.setOption('wakehdd', NoSave(ConfigYesNo(default=False)), _("Allow HDD wake up")) self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie", fixed_size=False)), _("Where to check free space")) self.setOption('limit', NoSave(ConfigNumber(default=100)), _("Free space limit in GB")) self.setOption('listtimer', NoSave(ConfigYesNo(default=False)), _("List upcoming timer")) - + def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment # If empty or none is returned, nothing will be sent path = self.getValue('path') limit = self.getValue('limit') - + if not self.getValue('wakehdd'): # User specified to avoid HDD wakeup if it is sleeping @@ -101,7 +101,7 @@ def run(self, callback, errback): # Don't wake up HDD log.debug(_("[FreeSpace] HDD is idle: ") + str(path)) callback() - + # Check free space on path if os.path.exists(path): stat = os.statvfs(path) @@ -114,8 +114,8 @@ def run(self, callback, errback): # Not enough free space text = "" if self.getValue('listtimer'): - text = "\r\n\r\n" - text += _("Next timer:") + text = "\r\n\r\n" + text += _("Next timer:") text += "\r\n" import NavigationInstance now = time() @@ -123,7 +123,7 @@ def run(self, callback, errback): for t in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers: if not t.disabled and not t.justplay and now < t.begin and t.end < next_day: text += "\t" + timerToString(t) + "\r\n" - + callback(SUBJECT, BODY % (path, limit, free) + text) else: # There is enough free space diff --git a/src/Controller/IPKGUpdateNotification.py b/src/Controller/IPKGUpdateNotification.py index 3cc2acc..7f21590 100644 --- a/src/Controller/IPKGUpdateNotification.py +++ b/src/Controller/IPKGUpdateNotification.py @@ -37,13 +37,13 @@ class IPKGUpdateNotification(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - + # Default configuration self.setOption('selfcheck', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) @@ -111,4 +111,3 @@ def buildList(self, callback, errback): callback(SUBJECT, BODY % (updates)) else: callback() - diff --git a/src/Controller/ListDir.py b/src/Controller/ListDir.py index 607573d..b85d72f 100644 --- a/src/Controller/ListDir.py +++ b/src/Controller/ListDir.py @@ -15,48 +15,48 @@ # GNU General Public License for more details. # ####################################################################### - + # Config from Components.config import ConfigYesNo, ConfigText, ConfigNumber, NoSave - + # Plugin internal from Plugins.Extensions.PushService.__init__ import _ from Plugins.Extensions.PushService.ControllerBase import ControllerBase - + # Plugin specific import os - - + + # Constants - + SUBJECT = _("List of Files") - - + + class ListDir(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) self.movielist = [] - + # Default configuration self.setOption('path', NoSave(ConfigText(default="/media/hdd/movie/", fixed_size=False)), _("Where to check")) self.setOption('ext', NoSave(ConfigText(default=".ts", fixed_size=False)), _("file extension")) - + def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, body (List of Files) # If empty or none is returned, nothing will be sent path = self.getValue('path') - ext = self.getValue('ext') + ext = self.getValue('ext') movielist = [] for file in os.listdir(path): if file.endswith(ext): movielist.append(file) body = "The following files were found: \n" + "\n".join(movielist) - + if movielist: callback(SUBJECT, body) else: diff --git a/src/Controller/MissingTimers.py b/src/Controller/MissingTimers.py index 445b01c..3d60773 100644 --- a/src/Controller/MissingTimers.py +++ b/src/Controller/MissingTimers.py @@ -34,9 +34,9 @@ class MissingTimers(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) @@ -48,14 +48,14 @@ def run(self, callback, errback): timers = 0 tomorrow_begin = mktime((date.today() + timedelta(days=1)).timetuple()) tomorrow_end = tomorrow_begin + 24 * 60 * 60 - + for timer in NavigationInstance.instance.RecordTimer.timer_list: if not timer.disabled and str(timer.service_ref)[0] != "-": timer_begin = timer.begin if tomorrow_begin <= timer_begin <= tomorrow_end: timers += 1 break - + if timers == 0: callback(SUBJECT, BODY % strftime(_("%Y.%m.%d"), localtime(tomorrow_begin))) else: diff --git a/src/Controller/OPKGUpdateNotification.py b/src/Controller/OPKGUpdateNotification.py index 189476e..cebb45d 100644 --- a/src/Controller/OPKGUpdateNotification.py +++ b/src/Controller/OPKGUpdateNotification.py @@ -37,16 +37,16 @@ class OPKGUpdateNotification(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - + # Default configuration self.setOption('selfcheck', NoSave(ConfigYesNo(default=False)), _("Start update check if not done yet")) - + self.data = "" self.container = eConsoleAppContainer() try: @@ -75,7 +75,7 @@ def opkgupgradable(self): self.container.execute("opkg list-upgradable") def opkgupgradableFinished(self, retval=None): - + try: log.debug("PushService retval: ", str(retval)) except: @@ -84,10 +84,10 @@ def opkgupgradableFinished(self, retval=None): log.debug("PushService self.data: ", str(self.data)) except: pass - + updates = "" excepts = "" - + if self.data: try: for line in self.data.split("\n"): @@ -121,16 +121,15 @@ def opkgupgradableFinished(self, retval=None): updates += line + "\r\n" except Exception, e: excepts += "\r\n\r\nException:\r\n" + str(e) - + if excepts: log.exception(excepts) - + if updates: #callback( SUBJECT, BODY % (updates) ) - + #TODO Problem test run won't get the message # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, BODY % (updates)) - diff --git a/src/Controller/RecordNotification.py b/src/Controller/RecordNotification.py index df9e53f..575e567 100644 --- a/src/Controller/RecordNotification.py +++ b/src/Controller/RecordNotification.py @@ -34,19 +34,19 @@ class RecordNotification(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - + self.forceBindRecordTimer = eTimer() try: self.forceBindRecordTimer_conn = self.forceBindRecordTimer.timeout.connect(self.begin) except: self.forceBindRecordTimer.callback.append(self.begin) - + # Default configuration self.setOption('send_on_start', NoSave(ConfigYesNo(default=False)), _("Send notification on record start")) self.setOption('send_on_end', NoSave(ConfigYesNo(default=True)), _("Send notification on record end")) @@ -55,7 +55,7 @@ def __init__(self): def begin(self): # Is called after starting PushService - + if self.getValue('send_on_start') or self.getValue('send_on_end'): if NavigationInstance.instance: if self.onRecordEvent not in NavigationInstance.instance.RecordTimer.on_state_change: @@ -85,16 +85,16 @@ def run(self, callback, errback): def onRecordEvent(self, timer): text = "" include_description = self.getValue('include_description') - + if timer.justplay: pass - + elif str(timer.service_ref)[0] == "-": pass - + elif timer.state == timer.StatePrepared: pass - + elif timer.state == timer.StateRunning: timer.ps_running = True if self.getValue('send_on_start'): @@ -106,7 +106,7 @@ def onRecordEvent(self, timer): if include_description: text += "\n\n" + str(timer.description) del timer - + # Finished repeating timer will report the state StateEnded+1 or StateWaiting elif timer.state == timer.StateEnded or timer.repeated and timer.state == timer.StateWaiting: if hasattr(timer, "ps_running") and timer.ps_running: @@ -120,11 +120,10 @@ def onRecordEvent(self, timer): if include_description: text += "\n\n" + str(timer.description) del timer - + if text: #TODO Problem test run won't get the message # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, text) - diff --git a/src/Controller/RecordSummary.py b/src/Controller/RecordSummary.py index c620917..55ba5e6 100644 --- a/src/Controller/RecordSummary.py +++ b/src/Controller/RecordSummary.py @@ -35,14 +35,14 @@ class RecordSummary(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) self.timers = [] - + # Default configuration self.setOption('remove_timer', NoSave(ConfigYesNo(default=False)), _("Remove finished timer(s)")) self.setOption('include_description', NoSave(ConfigYesNo(default=False)), _("Include timer description")) @@ -56,16 +56,16 @@ def run(self, callback, errback): for timer in NavigationInstance.instance.RecordTimer.processed_timers: if timer.justplay: pass - + elif str(timer.service_ref)[0] == "-": pass - + elif TAG in timer.tags: pass - + elif timer.disabled: pass - + else: text += str(timer.name) + "\t" \ + strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \ diff --git a/src/Controller/SendLog.py b/src/Controller/SendLog.py index 9d975c6..eb2ad07 100644 --- a/src/Controller/SendLog.py +++ b/src/Controller/SendLog.py @@ -34,9 +34,9 @@ class SendLog(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) @@ -86,7 +86,7 @@ def run(self, callback, errback): self.logfiles.append(logfile) break infile.close() - + if self.logfiles: callback(SUBJECT, BODY, self.logfiles) else: diff --git a/src/Controller/StandbyNotification.py b/src/Controller/StandbyNotification.py index 2c102d9..95a419d 100644 --- a/src/Controller/StandbyNotification.py +++ b/src/Controller/StandbyNotification.py @@ -31,68 +31,68 @@ class StandbyNotification(ControllerBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ControllerBase.__init__(self) - + # Default configuration self.setOption('send_after_bootup', NoSave(ConfigYesNo(default=False)), _("Send notification after bootup")) self.setOption('send_before_shutdown', NoSave(ConfigYesNo(default=False)), _("Send notification before shutdown")) self.setOption('send_before_standby', NoSave(ConfigYesNo(default=True)), _("Send notification before standby")) self.setOption('send_after_standby', NoSave(ConfigYesNo(default=True)), _("Send notification after standby")) - + def leaveStandby(self, dummy=None): #log.debug( "leave standby" ) - + if self.getValue('send_after_standby'): text = _("Enigma2 wakeup after Standby") - + # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, text) - + def standbyCountChanged(self, configElement=None): #log.debug( "enter standby num", configElement.value ) from Screens.Standby import inStandby inStandby.onClose.append(self.leaveStandby) - + if self.getValue('send_before_standby'): text = _("Enigma2 going into Standby") - + # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, text) - + def begin(self): # Is called after starting PushService - + if self.getValue('send_after_bootup'): text = _("Enigma2 booted") - + # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, text) - + from Components.config import config config.misc.standbyCounter.addNotifier(self.standbyCountChanged, initial_call=False) def end(self): # Is called after stopping PushSerive - + if self.getValue('send_before_shutdown'): text = _("Enigma2 shutdown initiated") - + # Push mail from Plugins.Extensions.PushService.plugin import gPushService if gPushService: gPushService.push(self, SUBJECT, text) - + def run(self, callback, errback): # At the end a plugin has to call one of the functions: callback or errback # Callback should return with at least one of the parameter: Header, Body, Attachment diff --git a/src/ControllerBase.py b/src/ControllerBase.py index c5927b3..a1bf919 100644 --- a/src/ControllerBase.py +++ b/src/ControllerBase.py @@ -24,11 +24,11 @@ class ControllerBase(ModuleBase): # You only have to overwrite the functions You need # If You don't have to save something, You don't need getOptions / setOptions - + UniqueCounter = 0 - + ForceSingleInstance = True - + def __init__(self): ModuleBase.__init__(self) # Is called on instance creation diff --git a/src/Logger.py b/src/Logger.py index f909f28..b44ee83 100644 --- a/src/Logger.py +++ b/src/Logger.py @@ -39,15 +39,15 @@ class Logger(object): def __init__(self): self.instance = logging.getLogger("pushservice") self.instance.setLevel(logging.DEBUG) - + self.reinit() - + def reinit(self): - self.instance.handlers = [] - + self.instance.handlers = [] + if not hasattr(config, "pushservice"): return - + if config.pushservice.log_shell.value: shandler = logging.StreamHandler(sys.stdout) shandler.setLevel(logging.DEBUG) @@ -57,7 +57,7 @@ def reinit(self): self.instance.addHandler(shandler) self.instance.setLevel(logging.DEBUG) - + if config.pushservice.log_write.value: fhandler = logging.FileHandler(config.pushservice.log_file.value) fhandler.setLevel(logging.DEBUG) @@ -74,22 +74,22 @@ def shutdown(self): def info(self, *args): strargs = " ".join([str(arg) for arg in args]) - + if self.instance: self.instance.info(strargs) - + elif config.pushservice.log_shell.value: print strargs def debug(self, *args): strargs = " ".join([str(arg) for arg in args]) - + if self.instance: self.instance.debug(strargs) - + elif config.pushservice.log_shell.value: print strargs - + if sys.exc_info()[0]: self.instance.debug(str(sys.exc_info()[0])) self.instance.debug(str(traceback.format_exc())) @@ -97,13 +97,13 @@ def debug(self, *args): def warning(self, *args): strargs = " ".join([str(arg) for arg in args]) - + if self.instance: self.instance.warning(strargs) - + elif config.pushservice.log_shell.value: print strargs - + if int(config.pushservice.popups_warning_timeout.value) != 0: if currentThread().getName() == 'MainThread': AddPopup( @@ -115,10 +115,10 @@ def warning(self, *args): def error(self, *args): strargs = " ".join([str(arg) for arg in args]) - + if self.instance: self.instance.error(strargs) - + elif config.pushservice.log_shell.value: print strargs @@ -130,16 +130,16 @@ def error(self, *args): int(config.pushservice.popups_error_timeout.value), 'PS_PopUp_ID_Error_' + strargs ) - + def exception(self, *args): strargs = " ".join([str(arg) for arg in args]) - + if self.instance: self.instance.exception(strargs) - + elif config.pushservice.log_shell.value: print strargs - + if int(config.pushservice.popups_error_timeout.value) != 0: if currentThread().getName() == 'MainThread': AddPopup( @@ -148,7 +148,7 @@ def exception(self, *args): int(config.pushservice.popups_error_timeout.value), 'PS_PopUp_ID_Exception_' + strargs ) - + import os import sys import traceback @@ -161,4 +161,3 @@ def exception(self, *args): log = Logger() - diff --git a/src/ModuleBase.py b/src/ModuleBase.py index bfd6eb3..954f716 100644 --- a/src/ModuleBase.py +++ b/src/ModuleBase.py @@ -33,12 +33,12 @@ class ModuleBase(object): def __init__(self): # Is called on instance creation - + # Default configuration self.enable = NoSave(ConfigYesNo(default=False)) - + self.options = OrderedDict() - + # Build a list of key-value string tuples # [ (key, value, description, config element) , ] #self.options['enabled'] = ConfigYesNo( default = False ) diff --git a/src/Modules.py b/src/Modules.py index 375bc3b..ad575d1 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -41,33 +41,33 @@ def __init__(self): # Module functions def loadModules(self, path, base): modules = {} - + if not os.path.exists(path): return - + # Import all subfolders to allow relative imports for root, dirs, files in os.walk(path): if root not in sys.path: sys.path.append(root) - + # Import PushService modules files = [fname[:-3] for fname in os.listdir(path) if fname.endswith(".py")] for name in files: module = None - + if name == "__init__": continue - + try: fp, pathname, description = imp.find_module(name, [path]) except Exception, e: log.exception(("PushService Find module exception: ") + str(e)) fp = None - + if not fp: log.debug(("PushService No module found: ") + str(name)) continue - + try: module = imp.load_module(name, fp, pathname, description) except Exception, e: @@ -76,27 +76,27 @@ def loadModules(self, path, base): # Since we may exit via an exception, close fp explicitly. if fp: fp.close() - + if not module: log.debug(("PushService No module available: ") + str(name)) continue - + # Continue only if the attribute is available if not hasattr(module, name): log.debug(("PushService Warning attribute not available: ") + str(name)) continue - + # Continue only if attr is a class attr = getattr(module, name) if not inspect.isclass(attr): log.debug(("PushService Warning no class definition: ") + str(name)) continue - + # Continue only if the class is a subclass of the corresponding base class if not issubclass(attr, base): log.debug(("PushService Warning no subclass of base: ") + str(name)) continue - + # Add module to the module list modules[name] = attr return modules diff --git a/src/PushService.py b/src/PushService.py index 744d707..b3cc600 100644 --- a/src/PushService.py +++ b/src/PushService.py @@ -43,18 +43,18 @@ class PushService(PushServiceBase): def __init__(self): PushServiceBase.__init__(self) - + self.state = PSBOOT if config.pushservice.runonboot.value else PSFIRST - + self.timer = eTimer() try: self.timer_conn = self.timer.timeout.connect(self.do) except: self.timer.callback.append(self.do) - + # Read XML file, parse it and instantiate configured plugins self.load() - + #TODO Run in a new thread ###################################### @@ -62,17 +62,17 @@ def __init__(self): def start(self): log.reinit() - + log.info("PushService start") self.stopTimer() - + self.begin() self.next() def stop(self): log.debug("PushService stop") self.stopTimer() - + self.end() self.state = PSFIRST @@ -80,10 +80,10 @@ def next(self, state=None): if state: self.state = state log.debug("PushService next", self.state) - + if self.state == PSBOOT: self.startTimer(int(config.pushservice.bootdelay.value), PSBOOTRUN) - + elif self.state == PSBOOTRUN \ or self.state == PSFIRST: cltime = config.pushservice.time.value @@ -92,7 +92,7 @@ def next(self, state=None): ctime = cltime[0] * 60 + cltime[1] seconds = 60 * abs(ctime - ltime) self.startTimer(seconds, PSFIRSTRUN) - + elif self.state == PSFIRSTRUN \ or self.state == PSCYCLE: period = int(config.pushservice.period.value) diff --git a/src/PushServiceBase.py b/src/PushServiceBase.py index 991dbb4..103b8ca 100644 --- a/src/PushServiceBase.py +++ b/src/PushServiceBase.py @@ -55,13 +55,13 @@ class PushServiceBase(Modules, ConfigFile): def __init__(self, path=""): Modules.__init__(self) ConfigFile.__init__(self) - + self.services = [] self.controllers = [] - + self.pushcallbacks = {} self.pusherrbacks = {} - + # Read module files from subfolders self.servicemodules = self.loadModules(SERVICE_PATH, ServiceBase) self.controllermodules = self.loadModules(CONTROLLER_PATH, ControllerBase) @@ -170,7 +170,7 @@ def load(self): if root: services = [] controllers = [] - + # Reset the unique id counters ServiceBase.resetUniqueID() ControllerBase.resetUniqueID() @@ -187,7 +187,7 @@ def parse(root, typ, modules): instance = self.instantiateModule(module) if instance: instance.setEnable(eval(enable)) - + # Set instance options options = [] for option in element.findall(OPTION): @@ -195,16 +195,16 @@ def parse(root, typ, modules): value = option.text if key and value: options.append((key, value)) - + if options: instance.setOptions(options) - + # Append to active controller list instances.append(instance) return instances services = parse(root, SERVICE, self.servicemodules) controllers = parse(root, CONTROLLER, self.controllermodules) - + self.services = services self.controllers = controllers else: @@ -216,13 +216,13 @@ def save(self): root = None services = self.services controllers = self.controllers - + # Build Header from plugin import NAME, VERSION root = Element(NAME) root.set('version', VERSION) root.append(Comment(_("Don't edit this manually unless you really know what you are doing"))) - + # Build Body def build(root, instances, typ): for instance in instances: @@ -234,12 +234,12 @@ def build(root, instances, typ): for key, value, description in options: SubElement(element, OPTION, key=stringToXML(key)).text = stringToXML(value) return root - + if services: root = build(root, services, SERVICE) if controllers: root = build(root, controllers, CONTROLLER) - + self.writeXML(root) ###################################### @@ -267,17 +267,17 @@ def end(self): def run(self): log.debug(("PushService started: ") + strftime(_("%d.%m.%Y %H:%M"), localtime())) - + controllers = self.controllers self.pushcallbacks = {} self.pusherrbacks = {} - + # Loop over all Controllers if controllers: for controller in controllers: if controller.getEnable(): log.debug(("PushService running: ") + str(controller.getName())) - + try: # Run controller ret = controller.run( @@ -291,7 +291,7 @@ def run(self): def runcallback(self, controller, *args): services = self.services subject, body, attachments = "", "", [] - + # Parse return value(s) if args: if len(args) == 3: @@ -302,7 +302,7 @@ def runcallback(self, controller, *args): else: # Only header returned subject = args - + if subject: # Push notification self.push(controller, subject, body, attachments) @@ -376,7 +376,7 @@ def pushcheckbacks(self, key): errparam = self.pusherrbacks.get(key, []) cnterr = len(errparam) cntservices = len([service for service in self.services if service.getEnable()]) - + # Check if all services already called and returned if (cntservices == (cntcall + cnterr)): service, controller = key diff --git a/src/ServiceBase.py b/src/ServiceBase.py index 8caba7c..615b9a6 100644 --- a/src/ServiceBase.py +++ b/src/ServiceBase.py @@ -23,11 +23,11 @@ class ServiceBase(ModuleBase): # You only have to overwrite the functions You need # If You don't have to save something, You don't need getOptions / setOptions - + UniqueCounter = 0 - + ForceSingleInstance = True - + def __init__(self): ModuleBase.__init__(self) # Is called on instance creation diff --git a/src/Services/GNTP.py b/src/Services/GNTP.py index 4d1c9dd..beb6a55 100644 --- a/src/Services/GNTP.py +++ b/src/Services/GNTP.py @@ -36,14 +36,14 @@ class GNTP(ServiceBase): - + ForceSingleInstance = False - + def __init__(self): # Is called on instance creation ServiceBase.__init__(self) #self.sockets = [] - + # Default configuration self.setOption('growlhost', NoSave(ConfigText(default="host", fixed_size=False)), _("Growl Host name")) self.setOption('growlport', NoSave(ConfigNumber(default=23053)), _("Growl Port")) @@ -54,17 +54,17 @@ def __init__(self): def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE - + box = config.pushservice.boxname.value app = APP_NAME.format(**{'box': box, 'name': NAME}) nottype = NOTIFICATION_TYPE.format(**{'box': box, 'name': NAME}) - + # Prepare message if body == "": body = subject subject = GROWL_SUBJECT_TEMPLATE.format(**{'box': box, 'subject': subject}) body = GROWL_BODY_TEMPLATE.format(**{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE}) - + # Registrate growl = gntp.notifier.GrowlNotifier( applicationName=app, @@ -76,9 +76,9 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): ) growl.socketTimeout = self.getValue('timeout') growl.register() - + # Send a message - #socket = + #socket = sent = growl.notify( noteType=nottype, title=subject, @@ -88,7 +88,7 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): priority=self.getValue('priority') ) #self.sockets.append(socket) - + if sent is True: callback() else: diff --git a/src/Services/PopUp.py b/src/Services/PopUp.py index ad837ee..65b2015 100644 --- a/src/Services/PopUp.py +++ b/src/Services/PopUp.py @@ -33,9 +33,9 @@ class PopUp(ServiceBase): - + ForceSingleInstance = True - + def __init__(self): # Is called on instance creation ServiceBase.__init__(self) diff --git a/src/Services/SMTP.py b/src/Services/SMTP.py index f4a7aae..fae6206 100644 --- a/src/Services/SMTP.py +++ b/src/Services/SMTP.py @@ -38,30 +38,30 @@ class SMTP(ServiceBase): - + ForceSingleInstance = False - + def __init__(self): # Is called on instance creation ServiceBase.__init__(self) self.connectors = [] - + # Default configuration self.setOption('smtpserver', NoSave(ConfigText(default="smtp.server.com", fixed_size=False)), _("SMTP Server")) self.setOption('smtpport', NoSave(ConfigNumber(default=587)), _("SMTP Port")) self.setOption('smtpssl', NoSave(ConfigYesNo(default=True)), _("SMTP SSL")) self.setOption('smtptls', NoSave(ConfigYesNo(default=True)), _("SMTP TLS")) self.setOption('timeout', NoSave(ConfigNumber(default=30)), _("Timeout")) - + self.setOption('username', NoSave(ConfigText(default="user", fixed_size=False)), _("User name")) self.setOption('password', NoSave(ConfigPassword(default="password")), _("Password")) - + self.setOption('mailfrom', NoSave(ConfigText(default="abc@provider.com", fixed_size=False)), _("Mail from")) self.setOption('mailto', NoSave(ConfigText(fixed_size=False)), _("Mail to or leave empty (From will be used)")) def push(self, callback, errback, pluginname, subject, body="", attachments=[]): from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE - + # Set SMTP parameters mailconf = {} mailconf["host"] = self.getValue('smtpserver') @@ -71,11 +71,11 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): mailconf["ssl"] = self.getValue('smtpssl') mailconf["tls"] = self.getValue('smtptls') mailconf["timeout"] = self.getValue('timeout') - + # Create message object from_addr = self.getValue('mailfrom') to_addrs = [self.getValue('mailto') or from_addr] - + # Prepare message if body == "": body = subject @@ -85,15 +85,15 @@ def push(self, callback, errback, pluginname, subject, body="", attachments=[]): if attachments: for attachment in attachments: message.attach(attachment) #TODO change mime=None, charset=None, content=None): - + # Send message log.debug(("PushService PushMail: Sending message: %s") % subject) deferred, connector = sendmail(mailconf, message) - + # Add callbacks deferred.addCallback(callback) deferred.addErrback(errback) - + self.connectors.append(connector) def cancel(self): diff --git a/src/Services/mail/mail.py b/src/Services/mail/mail.py index 530acdd..d8229c7 100644 --- a/src/Services/mail/mail.py +++ b/src/Services/mail/mail.py @@ -47,55 +47,55 @@ def __init__(self, from_addr, to_addrs, subject, message, mime="text/plain", cha self.subject = subject self.from_addr = from_addr self.to_addrs = isinstance(to_addrs, types.StringType) and [to_addrs] or to_addrs - + self.msg = None self.__cache = None self.message = MIMEText(message) self.message.set_charset(charset) self.message.set_type(mime) - + def attach(self, filename, mime=None, charset=None, content=None): base = os.path.basename(filename) if content is None: fd = open(filename) content = fd.read() fd.close() - + if not isinstance(content, types.StringType): raise TypeError("don't know how to handle content: %s" % type(content)) - + part = MIMEBase("application", "octet-stream") part.set_payload(content) Encoders.encode_base64(part) part.add_header("Content-Disposition", "attachment; filename=\"%s\"" % base) - + if mime is not None: part.set_type(mime) - + if charset is not None: part.set_charset(charset) - + if self.msg is None: self.msg = MIMEMultipart() self.msg.attach(self.message) - + self.msg.attach(part) - + def __str__(self): return self.__cache or "nuswit mail message: not rendered yet" - + def render(self): if self.msg is None: self.msg = self.message - + self.msg["Subject"] = self.subject self.msg["From"] = self.from_addr self.msg["To"] = COMMASPACE.join(self.to_addrs) self.msg["Date"] = formatdate(localtime=True) - + if self.__cache is None: self.__cache = self.msg.as_string() - + return StringIO(self.__cache) @@ -112,14 +112,14 @@ def sendmail(mailconf, message): """ if not isinstance(mailconf, types.DictType): raise TypeError("mailconf must be a regular python dictionary") - + if not isinstance(message, Message): raise TypeError("message must be an instance of nuswit.mail.Message") - + host = mailconf.get("host") if not isinstance(host, types.StringType): raise ValueError("mailconf requires a 'host' configuration") - + ssl = mailconf.get("ssl", True) tls = mailconf.get("tls", True) if ssl is True: @@ -129,13 +129,13 @@ def sendmail(mailconf, message): else: port = mailconf.get("port", 25) contextFactory = None - + retries = mailconf.get("retries", 0) timeout = mailconf.get("timeout", 30) - + if not isinstance(port, types.IntType): raise ValueError("mailconf requires a proper 'port' configuration") - + deferred = Deferred() username, password = mailconf.get("username"), mailconf.get("password") factory = ESMTPSenderFactory( @@ -145,10 +145,10 @@ def sendmail(mailconf, message): requireAuthentication=(username and password), requireTransportSecurity=tls, retries=retries, timeout=timeout) - + if not ssl: connector = reactor.connectTCP(host, port, factory, timeout=timeout) else: connector = reactor.connectSSL(host, port, factory, contextFactory, timeout=timeout) - + return deferred, connector diff --git a/src/__init__.py b/src/__init__.py index 444cbf3..78da1ef 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -27,9 +27,9 @@ config.pushservice.popups_warning_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) config.pushservice.popups_error_timeout = ConfigSelectionNumber(-1, 20, 1, default=-1) -config.pushservice.log_shell = ConfigEnableDisable(default=False) -config.pushservice.log_write = ConfigEnableDisable(default=False) -config.pushservice.log_file = ConfigText(default="/tmp/pushservice.log", fixed_size=False) +config.pushservice.log_shell = ConfigEnableDisable(default=False) +config.pushservice.log_write = ConfigEnableDisable(default=False) +config.pushservice.log_file = ConfigText(default="/tmp/pushservice.log", fixed_size=False) def localeInit(): @@ -43,7 +43,7 @@ def _(txt): t = gettext.dgettext("PushService", txt) if t == txt: t = gettext.gettext(txt) - return t + return t else: return "" diff --git a/src/plugin.py b/src/plugin.py index a38b69d..2805e64 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -79,13 +79,13 @@ def autostart(reason, **kwargs): ####################################################### # Plugin main function def Plugins(**kwargs): - + descriptors = [] - + if config.pushservice.enable.value: # AutoStart descriptors.append(PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART, fnc=autostart, needsRestart=False)) - + #TODO icon descriptors.append(PluginDescriptor(name=NAME, description=NAME + " " + _("configuration"), where=PluginDescriptor.WHERE_PLUGINMENU, fnc=setup, needsRestart=False)) #icon = "/icon.png"