From 4e2f43393f9e5957d35473e95567b55b15be4944 Mon Sep 17 00:00:00 2001 From: Moritz Venn Date: Mon, 8 Aug 2011 14:22:22 +0200 Subject: [PATCH] epgrefresh: update to newer python syntax --- epgrefresh/src/EPGRefresh.py | 32 ++++++++++++----------- epgrefresh/src/EPGRefreshConfiguration.py | 6 +++-- epgrefresh/src/EPGRefreshResource.py | 11 +++++--- epgrefresh/src/EPGRefreshTimer.py | 18 +++++++------ epgrefresh/src/MainPictureAdapter.py | 4 ++- epgrefresh/src/PipAdapter.py | 6 +++-- epgrefresh/src/RecordAdapter.py | 6 +++-- epgrefresh/src/plugin.py | 12 +++++---- 8 files changed, 56 insertions(+), 39 deletions(-) diff --git a/epgrefresh/src/EPGRefresh.py b/epgrefresh/src/EPGRefresh.py index bc448dce..1504a739 100644 --- a/epgrefresh/src/EPGRefresh.py +++ b/epgrefresh/src/EPGRefresh.py @@ -1,4 +1,6 @@ # -*- coding: UTF-8 -*- +from __future__ import print_function + # To check if in Standby import Screens.Standby @@ -136,7 +138,7 @@ class EPGRefresh: self.refreshAdapter = None def forceRefresh(self, session = None): - print "[EPGRefresh] Forcing start of EPGRefresh" + print("[EPGRefresh] Forcing start of EPGRefresh") if self.session is None: if session is not None: self.session = session @@ -154,18 +156,18 @@ class EPGRefresh: epgrefreshtimer.setRefreshTimer(self.createWaitTimer) def stop(self): - print "[EPGRefresh] Stopping Timer" + print("[EPGRefresh] Stopping Timer") self.maybeStopAdapter() epgrefreshtimer.clear() def prepareRefresh(self): - print "[EPGRefresh] About to start refreshing EPG" + print("[EPGRefresh] About to start refreshing EPG") # Maybe read in configuration try: self.readConfiguration() - except Exception, e: - print "[EPGRefresh] Error occured while reading in configuration:", e + except Exception as e: + print("[EPGRefresh] Error occured while reading in configuration:", e) # This will hold services which are not explicitely in our list additionalServices = [] @@ -186,8 +188,8 @@ class EPGRefresh: # Read in configuration autotimer.readXml() - except Exception, e: - print "[EPGRefresh] Could not inherit AutoTimer Services:", e + except Exception as e: + print("[EPGRefresh] Could not inherit AutoTimer Services:", e) else: # Fetch services for timer in autotimer.getEnabledTimerList(): @@ -233,7 +235,7 @@ class EPGRefresh: del additionalServices[:] # Debug - print "[EPGRefresh] Services we're going to scan:", ', '.join([repr(x) for x in scanServices]) + print("[EPGRefresh] Services we're going to scan:", ', '.join([repr(x) for x in scanServices])) self.maybeStopAdapter() # NOTE: start notification is handled in adapter initializer @@ -246,7 +248,7 @@ class EPGRefresh: refreshAdapter = MainPictureAdapter(self.session) if (not refreshAdapter.backgroundCapable and Screens.Standby.inStandby) or not refreshAdapter.prepare(): - print "[EPGRefresh] Adapter is not able to run in background or not available, falling back to MainPictureAdapter" + print("[EPGRefresh] Adapter is not able to run in background or not available, falling back to MainPictureAdapter") refreshAdapter = MainPictureAdapter(self.session) refreshAdapter.prepare() self.refreshAdapter = refreshAdapter @@ -273,8 +275,8 @@ class EPGRefresh: # Parse EPG autotimer.parseEPG() - except Exception, e: - print "[EPGRefresh] Could not start AutoTimer:", e + except Exception as e: + print("[EPGRefresh] Could not start AutoTimer:", e) finally: # Remove instance if there wasn't one before if removeInstance: @@ -313,10 +315,10 @@ class EPGRefresh: config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value): - print "[EPGRefresh] Gone out of timespan while refreshing, sorry!" + print("[EPGRefresh] Gone out of timespan while refreshing, sorry!") self.cleanUp() else: - print "[EPGRefresh] Box no longer in Standby or Recording started, rescheduling" + print("[EPGRefresh] Box no longer in Standby or Recording started, rescheduling") # Recheck later epgrefreshtimer.add(EPGRefreshTimerEntry( @@ -333,14 +335,14 @@ class EPGRefresh: def nextService(self): # Debug - print "[EPGRefresh] Maybe zap to next service" + print("[EPGRefresh] Maybe zap to next service") try: # Get next reference service = self.scanServices.pop(0) except IndexError: # Debug - print "[EPGRefresh] Done refreshing EPG" + print("[EPGRefresh] Done refreshing EPG") # Clean up self.cleanUp() diff --git a/epgrefresh/src/EPGRefreshConfiguration.py b/epgrefresh/src/EPGRefreshConfiguration.py index 70fdcbc1..0d4b69c8 100644 --- a/epgrefresh/src/EPGRefreshConfiguration.py +++ b/epgrefresh/src/EPGRefreshConfiguration.py @@ -1,3 +1,5 @@ +from __future__ import print_function + # for localized messages from . import _ @@ -75,8 +77,8 @@ class EPGRefreshConfiguration(Screen, ConfigListScreen): self.list.append(getConfigListEntry(_("Inherit Services from AutoTimer"), config.plugins.epgrefresh.inherit_autotimer, _("Extend the list of services to refresh by those your AutoTimers use?"))) self.list.append(getConfigListEntry(_("Run AutoTimer after refresh"), config.plugins.epgrefresh.parse_autotimer, _("After a successful refresh the AutoTimer will automatically search for new matches if this is enabled."))) - except ImportError, ie: - print "[EPGRefresh] AutoTimer Plugin not installed:", ie + except ImportError as ie: + print("[EPGRefresh] AutoTimer Plugin not installed:", ie) ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed) diff --git a/epgrefresh/src/EPGRefreshResource.py b/epgrefresh/src/EPGRefreshResource.py index 469537e8..31fb170c 100644 --- a/epgrefresh/src/EPGRefreshResource.py +++ b/epgrefresh/src/EPGRefreshResource.py @@ -5,7 +5,10 @@ from enigma import eServiceReference from Components.config import config from Components.SystemInfo import SystemInfo from time import localtime -from urllib import unquote +try: + from urllib import unquote +except ImportError as ie: + from urllib.parse import unquote class EPGRefreshStartRefreshResource(resource.Resource): def render(self, req): @@ -51,7 +54,7 @@ class EPGRefreshAddRemoveServiceResource(resource.Resource): duration = req.args.get("duration", None) try: duration = duration and int(duration) - except ValueError, ve: + except ValueError as ve: output = 'invalid value for "duration": ' + str(duration) else: for sref in req.args.get('sref'): @@ -132,7 +135,7 @@ class EPGRefreshListServicesResource(resource.Resource): class EPGRefreshChangeSettingsResource(resource.Resource): def render(self, req): statetext = "config changed." - for key, value in req.args.iteritems(): + for key, value in req.args.items(): value = value[0] if key == "enabled": config.plugins.epgrefresh.enabled.value = True if value == "true" else False @@ -214,7 +217,7 @@ class EPGRefreshSettingsResource(resource.Resource): try: from Plugins.Extensions.AutoTimer.AutoTimer import AutoTimer hasAutoTimer = True - except ImportError, ie: pass + except ImportError as ie: pass return """ diff --git a/epgrefresh/src/EPGRefreshTimer.py b/epgrefresh/src/EPGRefreshTimer.py index 1597f9af..8eaade5d 100644 --- a/epgrefresh/src/EPGRefreshTimer.py +++ b/epgrefresh/src/EPGRefreshTimer.py @@ -1,3 +1,5 @@ +from __future__ import print_function + # To check if in Standby import Screens.Standby @@ -54,19 +56,19 @@ class EPGRefreshTimerEntry(timer.TimerEntry): if self.state == self.StateWaiting: # Check if in timespan if checkTimespan(config.plugins.epgrefresh.begin.value, config.plugins.epgrefresh.end.value): - print "[EPGRefresh] In Timespan, will check if we're in Standby and have no Recordings running next" + print("[EPGRefresh] In Timespan, will check if we're in Standby and have no Recordings running next") # Do we realy want to check nav? from NavigationInstance import instance if config.plugins.epgrefresh.force.value or (Screens.Standby.inStandby and instance is not None and not instance.RecordTimer.isRecording()): return True else: - print "[EPGRefresh] Box still in use, rescheduling" + print("[EPGRefresh] Box still in use, rescheduling") # Recheck later self.begin = time() + config.plugins.epgrefresh.delay_standby.value*60 return False else: - print "[EPGRefresh] Not in timespan, ending timer" + print("[EPGRefresh] Not in timespan, ending timer") self.state = self.StateEnded return False elif self.state == self.StateRunning: @@ -102,7 +104,7 @@ class EPGRefreshTimer(timer.Timer): timer.Timer.__init__(self) def remove(self, entry): - print "[EPGRefresh] Timer removed " + str(entry) + print("[EPGRefresh] Timer removed " + str(entry)) # avoid re-enqueuing entry.repeated = False @@ -114,9 +116,9 @@ class EPGRefreshTimer(timer.Timer): if entry.state != entry.StateEnded: self.timeChanged(entry) - print "state: ", entry.state - print "in processed: ", entry in self.processed_timers - print "in running: ", entry in self.timer_list + print("state: ", entry.state) + print("in processed: ", entry in self.processed_timers) + print("in running: ", entry in self.timer_list) # now the timer should be in the processed_timers list. remove it from there. self.processed_timers.remove(entry) @@ -153,7 +155,7 @@ class EPGRefreshTimer(timer.Timer): def add(self, entry): entry.timeChanged() - print "[EPGRefresh] Timer added " + str(entry) + print("[EPGRefresh] Timer added " + str(entry)) self.addTimerEntry(entry) def clear(self): diff --git a/epgrefresh/src/MainPictureAdapter.py b/epgrefresh/src/MainPictureAdapter.py index 4f670c20..783fd0ee 100644 --- a/epgrefresh/src/MainPictureAdapter.py +++ b/epgrefresh/src/MainPictureAdapter.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import Screens.Standby # MessageBox @@ -19,7 +21,7 @@ class MainPictureAdapter: return True def play(self, service): - print "[EPGRefresh.MainPictureAdapter.play]" + print("[EPGRefresh.MainPictureAdapter.play]") return self.navcore.playService(service) def stop(self): diff --git a/epgrefresh/src/PipAdapter.py b/epgrefresh/src/PipAdapter.py index bbf0546a..63a431a6 100644 --- a/epgrefresh/src/PipAdapter.py +++ b/epgrefresh/src/PipAdapter.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from Screens.PictureInPicture import PictureInPicture from Components.SystemInfo import SystemInfo from enigma import ePoint, eSize @@ -39,7 +41,7 @@ class PipAdapter: def hidePiP(self): # set pip size to 1 pixel - print "[EPGRefresh.PipAdapter.hidePiP]" + print("[EPGRefresh.PipAdapter.hidePiP]") x = y = 0 w = h = 1 self.session.pip.instance.move(ePoint(x, y)) @@ -57,7 +59,7 @@ class PipAdapter: self.session.pip.servicePath = newservice.getPath() def play(self, service): - print "[EPGRefresh.PipAdapter.play]" + print("[EPGRefresh.PipAdapter.play]") if not self.pipAvail: return False if not self.session.pipshown: # make sure pip still exists diff --git a/epgrefresh/src/RecordAdapter.py b/epgrefresh/src/RecordAdapter.py index 3520dbc5..e82d2ef7 100644 --- a/epgrefresh/src/RecordAdapter.py +++ b/epgrefresh/src/RecordAdapter.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from Components.SystemInfo import SystemInfo # MessageBox @@ -27,7 +29,7 @@ class RecordAdapter: return True def play(self, service): - print "[EPGRefresh.RecordAdapter.play]" + print("[EPGRefresh.RecordAdapter.play]") if not self.backgroundRefreshAvailable: return False self.stopStreaming() self.__service = self.navcore.recordService(service) @@ -43,6 +45,6 @@ class RecordAdapter: self.__service = None def stop(self): - print "[EPGRefresh.RecordAdapter.stop]" + print("[EPGRefresh.RecordAdapter.stop]") self.stopStreaming() diff --git a/epgrefresh/src/plugin.py b/epgrefresh/src/plugin.py index 7dde3ce2..45efa01a 100644 --- a/epgrefresh/src/plugin.py +++ b/epgrefresh/src/plugin.py @@ -1,3 +1,5 @@ +from __future__ import print_function + # for localized messages from . import _ @@ -56,8 +58,8 @@ try: from Tools.Directories import resolveFilename, SCOPE_PLUGINS reader = XMLHelpReader(resolveFilename(SCOPE_PLUGINS, "Extensions/EPGRefresh/mphelp.xml")) epgrefreshHelp = registerHelp(*reader) -except Exception, e: - print "[EPGRefresh] Unable to initialize MPHelp:", e,"- Help not available!" +except Exception as e: + print("[EPGRefresh] Unable to initialize MPHelp:", e,"- Help not available!") epgrefreshHelp = None #pragma mark - @@ -77,7 +79,7 @@ def standbyQuestionCallback(session, res = None): # Autostart def autostart(reason, **kwargs): - if reason == 0 and kwargs.has_key("session"): + if reason == 0 and "session" in kwargs: session = kwargs["session"] epgrefresh.session = session @@ -164,8 +166,8 @@ def housekeepingExtensionsmenu(el): else: try: plugins.removePlugin(extDescriptor) - except ValueError, ve: - print "[EPGRefresh] housekeepingExtensionsmenu got confused, tried to remove non-existant plugin entry... ignoring." + except ValueError as ve: + print("[EPGRefresh] housekeepingExtensionsmenu got confused, tried to remove non-existant plugin entry... ignoring.") config.plugins.epgrefresh.show_in_extensionsmenu.addNotifier(housekeepingExtensionsmenu, initial_call = False, immediate_feedback = True) extDescriptor = PluginDescriptor(name="EPGRefresh", description = _("Automatically refresh EPG"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = extensionsmenu, needsRestart=False) -- 2.20.1