reduce ammount of try/except-blocks used,
authorMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Thu, 31 Jul 2008 21:28:38 +0000 (21:28 +0000)
committerMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Thu, 31 Jul 2008 21:28:38 +0000 (21:28 +0000)
make some remaining ones more obvious,
smaller import cleanup,
add newlines to end of files

12 files changed:
autotimer/src/AutoPoller.py
autotimer/src/AutoTimer.py
autotimer/src/AutoTimerComponent.py
autotimer/src/AutoTimerConfiguration.py
autotimer/src/AutoTimerEditor.py
autotimer/src/AutoTimerImporter.py
autotimer/src/AutoTimerList.py
autotimer/src/AutoTimerOverview.py
autotimer/src/AutoTimerPreview.py
autotimer/src/AutoTimerSettings.py
autotimer/src/__init__.py
autotimer/src/plugin.py

index 6401754..2b84fc2 100644 (file)
@@ -17,11 +17,13 @@ class AutoPoller:
                else:
                        delay = config.plugins.autotimer.interval.value*3600
 
-               self.timer.callback.append(self.query)
+               if self.query not in self.timer.callback:
+                       self.timer.callback.append(self.query)
                self.timer.startLongTimer(delay)
 
        def stop(self):
-               self.timer.callback.remove(self.query)
+               if self.query in self.timer.callback:
+                       self.timer.callback.remove(self.query)
                self.timer.stop()
 
        def query(self):
@@ -36,3 +38,4 @@ class AutoPoller:
                        traceback.print_exc(file=sys.stdout)
 
                self.timer.startLongTimer(config.plugins.autotimer.interval.value*3600)
+
index 5cf0d56..e1269a1 100644 (file)
@@ -238,10 +238,9 @@ class AutoTimer:
                                                        if config.plugins.autotimer.refresh.value == "none" or newEntry.repeated:
                                                                raise AutoTimerIgnoreTimerException("Won't modify existing timer because either no modification allowed or repeated timer")
 
-                                                       try:
-                                                               if newEntry.isAutoTimer:
+                                                       if hasattr(newEntry, "isAutoTimer"):
                                                                        print "[AutoTimer] Modifying existing AutoTimer!"
-                                                       except AttributeError, ae:
+                                                       else:
                                                                if config.plugins.autotimer.refresh.value != "all":
                                                                        raise AutoTimerIgnoreTimerException("Won't modify existing timer because it's no timer set by us")
                                                                print "[AutoTimer] Warning, we're messing with a timer which might not have been set by us"
@@ -312,3 +311,4 @@ class AutoTimer:
                                func(newEntry)
 
                return (total, new, modified, timers)
+
index 57840bc..e91bb18 100644 (file)
@@ -501,16 +501,14 @@ class AutoTimerComponent(object):
                )
 
        def __eq__(self, other):
-               try:
+               if hasattr(other, "id"):
                        return self.id == other.id
-               except AttributeError:
-                       return False
+               return False
 
        def __lt__(self, other):
-               try:
+               if hasattr(other, "name"):
                        return self.name.lower() < other.name.lower()
-               except:
-                       return False
+               return False
 
        def __ne__(self, other):
                return not self.__eq__(other)
@@ -551,3 +549,4 @@ class AutoTimerComponent(object):
                         ]),
                         ")>"
                ])
+
index e7314e8..03d4a33 100644 (file)
@@ -13,14 +13,14 @@ def getValue(definitions, default):
        ret = ""
 
        # How many definitions are present
-       try:
-               childNodes = definitions.childNodes
-       except:
+       if isinstance(definitions, list):
                Len = len(definitions)
                if Len > 0:
                        childNodes = definitions[Len-1].childNodes
                else:
                        childNodes = []
+       else:
+               childNodes = definitions.childNodes
 
        # Iterate through nodes of last one
        for node in childNodes:
@@ -147,17 +147,18 @@ def parseEntry(element, baseTimer, defaults = False):
 
                try:
                        value = idx[value]
-                       start = element.getAttribute("from")
-                       end = element.getAttribute("to")
-                       if start and end:
-                               start = [int(x) for x in start.split(':')]
-                               end = [int(x) for x in end.split(':')]
-                               afterevent.append((value, (start, end)))
-                       else:
-                               afterevent.append((value, None))
                except KeyError, ke:
                        print '[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition'
                        continue
+
+               start = element.getAttribute("from")
+               end = element.getAttribute("to")
+               if start and end:
+                       start = [int(x) for x in start.split(':')]
+                       end = [int(x) for x in end.split(':')]
+                       afterevent.append((value, (start, end)))
+               else:
+                       afterevent.append((value, None))
        baseTimer.afterevent = afterevent
 
        # Read out exclude
@@ -354,18 +355,19 @@ def parseConfigOld(configuration, list, uniqueTimerId = 0):
 
                        try:
                                value = idx[value]
-                               start = element.getAttribute("from")
-                               end = element.getAttribute("to")
-                               if start and end:
-                                       start = [int(x) for x in start.split(':')]
-                                       end = [int(x) for x in end.split(':')]
-                                       afterevent.append((value, (start, end)))
-                               else:
-                                       afterevent.append((value, None))
                        except KeyError, ke:
                                print '[AutoTimer] Erroneous config contains invalid value for "afterevent":', afterevent,', ignoring definition'
                                continue
 
+                       start = element.getAttribute("from")
+                       end = element.getAttribute("to")
+                       if start and end:
+                               start = [int(x) for x in start.split(':')]
+                               end = [int(x) for x in end.split(':')]
+                               afterevent.append((value, (start, end)))
+                       else:
+                               afterevent.append((value, None))
+
                # Read out exclude (V*)
                idx = {"title": 0, "shortdescription": 1, "description": 2, "dayofweek": 3}
                excludes = ([], [], [], []) 
@@ -636,3 +638,4 @@ def writeConfig(filename, defaultTimer, timers):
        file.writelines(list)
 
        file.close()
+
index c2aca01..7f6f8d4 100644 (file)
@@ -218,12 +218,8 @@ class AutoTimerEditorBase():
                self.useDestination = ConfigYesNo(default = default)
 
                default = timer.destination or Directories.resolveFilename(Directories.SCOPE_HDD)
-               choices = []
-               try:
-                       choices = config.movielist.videodirs.value
-               except:
-                       print "config.movielist.videodirs.value not set"
-                       
+               choices = config.movielist.videodirs.value
+
                if default not in choices:
                        choices.append(default)
                self.destination = ConfigSelection(default = default, choices = choices)
@@ -1057,3 +1053,4 @@ def editorCallback(ret):
                # Save xml (as long as we added something)
                ret and autotimer and autotimer.writeXml()
                autotimer = None
+
index edc91a0..b53203f 100644 (file)
@@ -264,3 +264,4 @@ class AutoTimerImporter(Screen):
                                self.autotimer,
                                self.session
                        ))
+
index a2c5010..95bb925 100644 (file)
@@ -92,3 +92,4 @@ class AutoTimerPreviewList(MenuList):
                                self.instance.moveSelectionTo(idx)
                                break
                        idx += 1
+
index e6aa7ce..cf6c8d6 100644 (file)
@@ -229,3 +229,4 @@ class AutoTimerOverview(Screen, HelpableScreen):
        def save(self):
                # Just close here, saving will be done by cb
                self.close(self.session)
+
index 45d0e7f..ee1659b 100644 (file)
@@ -70,3 +70,4 @@ class AutoTimerPreview(Screen):
 
        def save(self):
                self.close(True)
+
index aa2f559..629f805 100644 (file)
@@ -70,3 +70,4 @@ class AutoTimerSettings(Screen, ConfigListScreen):
 
        def createSummary(self):
                return SetupSummary
+
index f5e1466..96ac7ed 100644 (file)
@@ -2,11 +2,12 @@
 
 from Components.Language import language
 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
-import os,gettext
+from os import environ as os_environ
+import gettext
 
 def localeInit():
     lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
-    os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
+    os_environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
     print "[AutoTimer] set language to ", lang
     gettext.bindtextdomain("AutoTimer", resolveFilename(SCOPE_PLUGINS, "Extensions/AutoTimer/locale"))
 
index 982aa08..49a5543 100644 (file)
@@ -47,12 +47,7 @@ def autostart(reason, **kwargs):
        elif reason == 1:
                # Stop Poller
                if autopoller is not None:
-                       # We might shutdown when configuring, timer won't be running then
-                       try:
-                               autopoller.stop()
-                       except ValueError, ve:
-                               pass
-
+                       autopoller.stop()
                        autopoller = None
 
                if autotimer is not None:
@@ -140,3 +135,4 @@ def Plugins(**kwargs):
                PluginDescriptor(name="AutoTimer", description = _("Edit Timers and scan for new Events"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = main),
                PluginDescriptor(name="AutoTimer", description= _("Add AutoTimer..."), where = PluginDescriptor.WHERE_MOVIELIST, fnc = movielist)
        ]
+