changeset 24:154fe67bae72

Journal double-entry check + unicode source_path fix + typo - journal now fail assertion when trying to write log whitout entry created, or when trying to create 2 entries without closing the first one - unicode source_path are now fixed: there was a decoding error when trying to add an unicode source_path from a second instance of gcp - small typo in --help page
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2010 15:49:16 +0800
parents 568af0d2333a
children f82731c70956
files README gcp
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/README	Tue Sep 28 18:14:43 2010 +0800
+++ b/README	Thu Sep 30 15:49:16 2010 +0800
@@ -25,7 +25,7 @@
 gcp is a file copier, loosely inspired from cp, but with high level functionalities like:
 	- progression indicator
 	- gcp continue copying even when there is an issue: he just skip the file with problem, and go on
-	- journalization: gcp write what he is doing, this allow to know which files where effectively copied
+	- journalization: gcp write what he is doing, this allow to know which files were effectively copied
 	- fixing names to be compatible with the target filesystem (e.g. removing incompatible chars like "?" or "*" on vfat)
 	- if you launch a copy when an other is already running, the files are added to the first queue, this avoid your hard drive to move its read/write head all the time
 	- files saving: you can keep track of files you have copied, and re-copy them later (useful when, for example, you always copy some free music to all your friends).
--- a/gcp	Tue Sep 28 18:14:43 2010 +0800
+++ b/gcp	Thu Sep 30 15:49:16 2010 +0800
@@ -103,12 +103,17 @@
             args = pickle.loads(str(args))
         except TypeError, pickle.UnpicklingError:
             return (False, _("INTERNAL ERROR: invalid arguments"))
-        return self._gcp.parseArguments(args, str(source_path))
+        try:
+            source_path = pickle.loads(str(source_path))
+        except TypeError, pickle.UnpicklingError:
+            return (False, _("INTERNAL ERROR: invalid source_path"))
+        return self._gcp.parseArguments(args, source_path)
 
 class Journal():
     def __init__(self, path=const_JOURNAL_PATH):
         self.journal_path = os.path.expanduser(path)
         self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals
+        self.__entry_open = False
 
     def __del__(self):
         self.journal_fd.flush()
@@ -116,6 +121,8 @@
 
     def startFile(self, source_path):
         """Start an entry in the journal"""
+        assert not self.__entry_open
+        self.__entry_open = True
         self.journal_fd.write(source_path+"\n")
         self.journal_fd.flush()
         self.success=True
@@ -123,19 +130,23 @@
 
     def closeFile(self):
         """Close the entry in the journal"""
+        assert self.__entry_open
         if not self.success:
             status = "FAILED"
         else:
             status = "OK" if not self.errors else "PARTIAL"
         self.journal_fd.write("%(status)s: %(errors)s\n" % {'status': status, 'errors': ', '.join(self.errors)})
         self.journal_fd.flush()
+        self.__entry_open = False
 
     def copyFailed(self):
         """Must be called when something is wrong with the copy itself"""
+        assert self.__entry_open
         self.success = False
 
     def error(self, name):
         """Something went wrong"""
+        assert self.__entry_open
         self.errors.append(name)
         
 
@@ -499,10 +510,10 @@
                     help=_("preserve  the  specified  attributes"))
         
         #parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True,
-        #            help=_("don't fixe name encoding errors")) #TODO
+        #            help=_("don't fix name encoding errors")) #TODO
 
         parser.add_option("--no-fs-fix", action="store_false", dest='fs_fix', default=True,
-                    help=_("don't fixe filesystem name incompatibily"))
+                    help=_("don't fix filesystem name incompatibily"))
 
         parser.add_option("--no-progress", action="store_false", dest="progress", default=True,
                     help=_("deactivate progress bar"))
@@ -560,7 +571,7 @@
             info (_("There is already one instance of %s running, pluging to it") % NAME_SHORT)
             #XXX: we have to serialize data as dbus only accept valid unicode, and filenames
             #     can have invalid unicode.
-            return self.gcp_main.addArgs(os.getcwd(),pickle.dumps(full_args))
+            return self.gcp_main.addArgs(pickle.dumps(os.getcwd()),pickle.dumps(full_args))
         else:
             if len(args) < 2:
                 _error_msg = _("Wrong number of arguments")