[pitivi] project_: Avoid backtrace when loading project failed due to missing sources



commit 582d401ace912b9b2aa8b227b4d547c198330b8b
Author: Thibault Saunier <tsaunier gnome org>
Date:   Fri Jan 29 10:41:08 2016 +0100

    project_: Avoid backtrace when loading project failed due to missing sources
    
    And add a unit test.
    
    Reviewed-by: Alex Băluț <alexandru balut gmail com>
    Differential Revision: https://phabricator.freedesktop.org/D715

 pitivi/project.py           |   33 ++++++++++++++++++++++-----------
 tests/test_media_library.py |   35 +++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index 171edfc..232f58f 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -1087,19 +1087,24 @@ class Project(Loggable, GES.Project):
                        error):
         if asset is None:
             asset_id = self.app.proxy_manager.getTargetUri(proxy)
-            asset = GES.Asset.request(proxy.get_extractable_type(),
-                                      asset_id)
-            if not asset:
-                for tmpasset in self.loading_assets.keys():
-                    if tmpasset.props.id == asset_id:
-                        asset = tmpasset
-                        break
-
+            if asset_id:
+                asset = GES.Asset.request(proxy.get_extractable_type(),
+                                          asset_id)
                 if not asset:
-                    self.error("Could not get the asset %s from its proxy %s", asset_id,
-                               proxy.props.id)
+                    for tmpasset in self.loading_assets:
+                        if tmpasset.props.id == asset_id:
+                            asset = tmpasset
+                            break
+
+                    if not asset:
+                        self.error("Could not get the asset %s from its proxy %s", asset_id,
+                                   proxy.props.id)
+
+                        return
+            else:
+                self.info("%s is not a proxy asset", proxy.props.id)
 
-                    return
+                return
 
         asset.proxying_error = error
         asset.creation_progress = 100
@@ -1189,6 +1194,12 @@ class Project(Loggable, GES.Project):
 
     def do_loading_error(self, error, asset_id, unused_type):
         """ vmethod, get called on "asset-loading-error"""
+        if not self.loaded:
+            self.info("Error loading asset %s while loading a project"
+                      " not updating proxy creation progress", asset_id)
+            self.__updateAssetLoadingProgress()
+            return
+
         asset = None
         for asset in self.loading_assets:
             if asset.get_id() == asset_id:
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index 4ea08a6..1d8209e 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -18,6 +18,7 @@
 # Boston, MA 02110-1301, USA.
 
 import os
+import tempfile
 
 from unittest import mock
 from gettext import gettext as _
@@ -59,7 +60,7 @@ class TestMediaLibrary(common.TestCase):
             self.medialibrary.finalize()
             self.medialibrary = None
 
-    def _customSetUp(self, settings):
+    def _customSetUp(self, settings, project_uri=None):
         # Always make sure we start with a clean medialibrary, and no other
         # is connected to some assets.
         self.clean()
@@ -69,7 +70,12 @@ class TestMediaLibrary(common.TestCase):
         self.app = common.getPitiviMock(settings)
         self.app.project_manager = ProjectManager(self.app)
         self.medialibrary = medialibrary.MediaLibraryWidget(self.app)
-        self.app.project_manager.newBlankProject(ignore_unsaved_changes=True)
+
+        if project_uri:
+            self.app.project_manager.loadProject(project_uri)
+        else:
+            self.app.project_manager.newBlankProject(ignore_unsaved_changes=True)
+
         self.app.project_manager.current_project.connect(
             "loaded", self.projectLoadedCb)
         self.mainloop.run()
@@ -187,3 +193,28 @@ class TestMediaLibrary(common.TestCase):
 
         self.assertEqual(asset.creation_progress, 100)
         self.assertEqual(asset.get_proxy(), proxy)
+
+    def testMissingUriDisplayed(self):
+        # Load a project with a missing asset.
+        unused, xges_path = tempfile.mkstemp()
+        with open(xges_path, "w") as xges:
+            xges.write("""<ges version='0.1'>
+  <project>
+    <ressources>
+      <asset id='file:///icantpossiblyexist.png' extractable-type-name='GESUriClip' />
+    </ressources>
+    <timeline>
+      <track caps='video/x-raw' track-type='4' track-id='0' />
+      <layer priority='0'>
+        <clip id='0' asset-id='file:///icantpossiblyexist.png' type-name='GESUriClip' layer-priority='0' 
track-types='4' start='0' duration='2590000000' inpoint='0' rate='0' />
+      </layer>
+    </timeline>
+</project>
+</ges>""")
+        uri = "file://%s" % xges_path
+
+        try:
+            self._customSetUp(None, project_uri=uri)
+            self.assertTrue(self.medialibrary._import_warning_infobar.props.visible)
+        finally:
+            os.remove(xges_path)


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