Browse Source

gcp: reorganize __copyNextFile()

Matteo Cypriani 9 months ago
parent
commit
cbd96480c5
1 changed files with 45 additions and 38 deletions
  1. 45
    38
      gcp

+ 45
- 38
gcp View File

@@ -310,49 +310,56 @@ class GCP():
310 310
                     self.__appendToList(abspath, dest_path, options)
311 311
 
312 312
     def __copyNextFile(self):
313
-        """Take the last file in the list, and launch the copy using glib io_watch event
314
-           @return: True a file was added, False else"""
315
-        if self.copy_list:
316
-            source_file, dest_path, options = self.copy_list.pop()
317
-            self.journal.startFile(source_file)
318
-            try:
319
-                source_fd = open(source_file, 'rb')
320
-            except:
321
-                self.journal.copyFailed()
322
-                self.journal.error("can't open source")
323
-                self.journal.closeFile()
324
-                return True
325
-            filename = os.path.basename(source_file)
326
-            assert(filename)
327
-            dest_file = self.__filename_fix(options.dest_file,options) if options.dest_file else self.__filename_fix(os.path.join(dest_path,filename),options)
328
-            if os.path.exists(dest_file) and not options.force:
329
-                warning (_("File [%s] already exists, skipping it!") % dest_file)
330
-                self.journal.copyFailed()
331
-                self.journal.error("already exists")
332
-                self.journal.closeFile()
333
-                source_fd.close()
334
-                return True
335
-            try:
336
-                dest_fd = open(dest_file, 'wb')
337
-            except:
338
-                self.journal.copyFailed()
339
-                self.journal.error("can't open dest")
340
-                self.journal.closeFile()
341
-                source_fd.close()
342
-                return True
343
-
344
-            GObject.io_add_watch(source_fd, GObject.IO_IN,self._copyFile,
345
-                                 (dest_fd, options), priority=GObject.PRIORITY_DEFAULT)
346
-            if not self.progress:
347
-                info(_("COPYING %(source)s ==> %(dest)s") % {"source":source_file, "dest":dest_file})
348
-            return True
349
-        else:
350
-            #Nothing left to copy, we quit
313
+        """Takes the last file in the list and launches the copy using glib
314
+           io_watch event."""
315
+        if not self.copy_list:
316
+            # Nothing left to copy, we quit
351 317
             if self.progress:
352 318
                 self.__pbar_finish()
353 319
             self.journal.showErrors()
354 320
             self.loop.quit()
355 321
 
322
+        source_file, dest_path, options = self.copy_list.pop()
323
+        self.journal.startFile(source_file)
324
+        try:
325
+            source_fd = open(source_file, 'rb')
326
+        except:
327
+            self.journal.copyFailed()
328
+            self.journal.error("can't open source")
329
+            self.journal.closeFile()
330
+            return
331
+
332
+        filename = os.path.basename(source_file)
333
+        assert(filename)
334
+        if options.dest_file:
335
+            dest_file = self.__filename_fix(options.dest_file, options)
336
+        else:
337
+            dest_file = self.__filename_fix(os.path.join(dest_path, filename),
338
+                                            options)
339
+        if os.path.exists(dest_file) and not options.force:
340
+            warning (_("File [%s] already exists, skipping it!") % dest_file)
341
+            self.journal.copyFailed()
342
+            self.journal.error("already exists")
343
+            self.journal.closeFile()
344
+            source_fd.close()
345
+            return
346
+
347
+        try:
348
+            dest_fd = open(dest_file, 'wb')
349
+        except:
350
+            self.journal.copyFailed()
351
+            self.journal.error("can't open dest")
352
+            self.journal.closeFile()
353
+            source_fd.close()
354
+            return
355
+
356
+        GObject.io_add_watch(source_fd, GObject.IO_IN,self._copyFile,
357
+                             (dest_fd, options),
358
+                             priority=GObject.PRIORITY_DEFAULT)
359
+        if not self.progress:
360
+            info(_("COPYING %(source)s ==> %(dest)s")
361
+                 % {"source":source_file, "dest":dest_file})
362
+
356 363
     def __copyFailed(self, reason, source_fd, dest_fd):
357 364
         """Write the failure in the journal and close files descriptors"""
358 365
         self.journal.copyFailed()

Loading…
Cancel
Save