[pitivi] Fix pylint broad-except



commit 1ba172da48704c72ce54db9f1bf5e9daaee0d421
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Oct 29 15:57:17 2019 +0100

    Fix pylint broad-except

 pitivi/application.py       |  1 +
 pitivi/project.py           | 31 +++++++++++--------------------
 pitivi/timeline/timeline.py |  8 ++------
 pitivi/utils/misc.py        | 11 ++++-------
 pitivi/utils/pipeline.py    |  2 +-
 tests/test_project.py       | 16 ++++++----------
 6 files changed, 25 insertions(+), 44 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index b8087bab..d08d1e52 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -308,6 +308,7 @@ class Pitivi(Gtk.Application, Loggable):
         giofile.load_contents_async(None, self._version_info_received_cb, None)
 
     def _version_info_received_cb(self, giofile, result, user_data):
+        # pylint: disable=broad-except
         try:
             raw = giofile.load_contents_finish(result)[1]
             if not isinstance(raw, str):
diff --git a/pitivi/project.py b/pitivi/project.py
index 03754f6e..c079c891 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -50,6 +50,7 @@ from pitivi.timeline.previewers import ThumbnailCache
 from pitivi.undo.project import AssetAddedIntention
 from pitivi.undo.project import AssetProxiedIntention
 from pitivi.utils.loggable import Loggable
+from pitivi.utils.misc import disconnectAllByFunc
 from pitivi.utils.misc import fixate_caps_with_default_values
 from pitivi.utils.misc import isWritable
 from pitivi.utils.misc import path_from_uri
@@ -388,7 +389,7 @@ class ProjectManager(GObject.Object, Loggable):
             saved = self.current_project.save(
                 self.current_project.ges_timeline, uri,
                 formatter_type, overwrite=True)
-        except Exception as e:
+        except GLib.Error as e:
             saved = False
             self.emit("save-project-failed", uri, e)
 
@@ -418,13 +419,13 @@ class ProjectManager(GObject.Object, Loggable):
 
         directory = os.path.dirname(uri)
         tmp_uri = os.path.join(directory, tmp_name)
-        try:
-            # saveProject updates the project URI... so we better back it up:
-            _old_uri = self.current_project.uri
-            self.saveProject(tmp_uri)
-            self.current_project.uri = _old_uri
+        # saveProject updates the project URI... so we better back it up:
+        _old_uri = self.current_project.uri
+        self.saveProject(tmp_uri)
+        self.current_project.uri = _old_uri
 
-            # create tar file
+        # create tar file
+        try:
             with tarfile.open(path_from_uri(uri), mode="w") as tar:
                 # top directory in tar-file
                 top = "%s-export" % project_name
@@ -447,7 +448,7 @@ class ProjectManager(GObject.Object, Loggable):
         # This catches errors with tarring; the GUI already shows errors while
         # saving projects (ex: permissions), so probably no GUI needed here.
         # Keep the exception generic enough to catch programming errors:
-        except Exception as e:
+        except tarfile.TarError as e:
             everything_ok = False
             self.error(e)
             tar_file = path_from_uri(uri)
@@ -498,18 +499,8 @@ class ProjectManager(GObject.Object, Loggable):
             self.current_project = None
             project.create_thumb()
             self.emit("project-closed", project)
-            # We should never choke on silly stuff like disconnecting signals
-            # that were already disconnected. It blocks the UI for nothing.
-            # This can easily happen when a project load/creation failed.
-            try:
-                project.disconnect_by_function(self._projectChangedCb)
-            except Exception:
-                self.debug(
-                    "Tried disconnecting signals, but they were not connected")
-            try:
-                project.pipeline.disconnect_by_function(self._projectPipelineDiedCb)
-            except Exception:
-                self.fixme("Handle better the errors and not get to this point")
+            disconnectAllByFunc(project, self._projectChangedCb)
+            disconnectAllByFunc(project.pipeline, self._projectPipelineDiedCb)
             self._cleanBackup(project.uri)
             self.exitcode = project.release()
 
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index a9c61851..e18ab092 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1987,12 +1987,8 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
             progress_dialog.window.destroy()
 
         auto_aligner = AutoAligner(self.timeline.selection, alignedCb)
-        try:
-            progress_meter = auto_aligner.start()
-            progress_meter.addWatcher(progress_dialog.updatePosition)
-        except Exception as e:
-            self.error("Could not start the autoaligner: %s", e)
-            progress_dialog.window.destroy()
+        progress_meter = auto_aligner.start()
+        progress_meter.addWatcher(progress_dialog.updatePosition)
 
     def _splitCb(self, unused_action, unused_parameter):
         """Splits clips.
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index 291b5755..004783c3 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -64,8 +64,6 @@ def disconnectAllByFunc(obj, func):
         except TypeError:
             return i
 
-    return i
-
 
 def format_ns(timestamp):
     if timestamp is None:
@@ -269,14 +267,13 @@ def show_user_manual(page=None):
         try:
             Gtk.show_uri(None, page_uri, time_now)
             return
-        except Exception as e:
+        except GLib.Error as e:
             log.info("utils", "Failed loading URI %s: %s", uri, e)
-            continue
 
+    # Last try calling yelp directly (used in flatpak while we do
+    # not have a portal to access system wild apps)
+    page_uri = get_page_uri(APPMANUALURL_OFFLINE, page)
     try:
-        # Last try calling yelp directly (used in flatpak while we do
-        # not have a portal to access system wild apps)
-        page_uri = get_page_uri(APPMANUALURL_OFFLINE, page)
         subprocess.Popen(["yelp", page_uri])
     except FileNotFoundError as e:
         log.warning("utils", "Failed loading %s: %s", page_uri, e)
diff --git a/pitivi/utils/pipeline.py b/pitivi/utils/pipeline.py
index a66c81b1..ce419f61 100644
--- a/pitivi/utils/pipeline.py
+++ b/pitivi/utils/pipeline.py
@@ -480,7 +480,7 @@ class SimplePipeline(GObject.Object, Loggable):
     def _queryDurationAsync(self, *unused_args, **unused_kwargs):
         try:
             self.getDuration()
-        except Exception as e:
+        except PipelineError as e:
             self.warning("Could not get duration because: %s", e)
         return False
 
diff --git a/tests/test_project.py b/tests/test_project.py
index 904c9034..b985365b 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -155,21 +155,17 @@ class TestProjectManager(common.TestCase):
         self.assertTrue(project is self.manager.current_project)
 
     def testCloseRunningProject(self):
-        current = mock.Mock()
-        current.uri = None
-        self.manager.current_project = current
+        project = self.manager.new_blank_project()
         self.assertTrue(self.manager.closeRunningProject())
-        self.assertEqual(2, len(self.signals))
+        self.assertEqual(5, len(self.signals), self.signals)
 
-        name, args = self.signals[0]
+        name, args = self.signals[-2]
         self.assertEqual("closing-project", name)
-        project = args[0]
-        self.assertTrue(project is current)
+        self.assertEqual(args[0], project)
 
-        name, args = self.signals[1]
+        name, args = self.signals[-1]
         self.assertEqual("project-closed", name)
-        project = args[0]
-        self.assertTrue(project is current)
+        self.assertEqual(args[0], project)
 
         self.assertTrue(self.manager.current_project is None)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]