[pitivi] project: Factor out a function to check backup project



commit 9e9f25f8a744c7951c24fad57c9bf1f7e5fc48fd
Author: Thibault Saunier <tsaunier gnome org>
Date:   Thu Oct 16 10:32:43 2014 +0200

    project: Factor out a function to check backup project
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739251

 pitivi/project.py |   39 ++++++++++++++++++++++-----------------
 1 files changed, 22 insertions(+), 17 deletions(-)
---
diff --git a/pitivi/project.py b/pitivi/project.py
index a5671cd..6f547ef 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -189,22 +189,11 @@ class ProjectManager(GObject.Object, Loggable):
         self.disable_save = False
         self._backup_lock = 0
 
-    def loadProject(self, uri):
-        """
-        Load the given URI as a project. If a backup file exists, ask if it
-        should be loaded instead, and if so, force the user to use "Save as"
-        afterwards.
-        """
-        if self.current_project is not None and not self.closeRunningProject():
-            return False
-
-        self.emit("new-project-loading", uri)
-
-        # We really want a path for os.path to work
-        path = path_from_uri(uri)
+    def _tryUsingBackupFile(self, uri):
         backup_path = self._makeBackupURI(path_from_uri(uri))
         use_backup = False
         try:
+            path = path_from_uri(uri)
             time_diff = os.path.getmtime(backup_path) - os.path.getmtime(path)
             self.debug(
                 'Backup file is %d secs newer: %s', time_diff, backup_path)
@@ -216,12 +205,10 @@ class ProjectManager(GObject.Object, Loggable):
             if time_diff > 0:
                 use_backup = self._restoreFromBackupDialog(time_diff)
 
-        if use_backup:
-            uri = self._makeBackupURI(uri)
+                if use_backup:
+                    uri = self._makeBackupURI(uri)
             self.debug('Loading project from backup: %s', uri)
 
-        # Load the project:
-        self.current_project = Project(self.app, uri=uri)
         # For backup files and legacy formats, force the user to use "Save as"
         if use_backup or path.endswith(".xptv"):
             self.debug("Enforcing read-only mode")
@@ -229,6 +216,24 @@ class ProjectManager(GObject.Object, Loggable):
         else:
             self.disable_save = False
 
+        return uri
+
+    def loadProject(self, uri):
+        """
+        Load the given URI as a project. If a backup file exists, ask if it
+        should be loaded instead, and if so, force the user to use "Save as"
+        afterwards.
+        """
+        if self.current_project is not None and not self.closeRunningProject():
+            return False
+
+        self.emit("new-project-loading", uri)
+
+        uri = self._tryUsingBackupFile(uri)
+
+        # Load the project:
+        self.current_project = Project(self.app, uri=uri)
+
         self.current_project.connect("missing-uri", self._missingURICb)
         self.current_project.connect("loaded", self._projectLoadedCb)
 


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