Mercurial > gcp
comparison gcp @ 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 | 8603fcb8615a |
children | f82731c70956 |
comparison
equal
deleted
inserted
replaced
23:568af0d2333a | 24:154fe67bae72 |
---|---|
101 @return: success (boolean) and error message if any (string)""" | 101 @return: success (boolean) and error message if any (string)""" |
102 try: | 102 try: |
103 args = pickle.loads(str(args)) | 103 args = pickle.loads(str(args)) |
104 except TypeError, pickle.UnpicklingError: | 104 except TypeError, pickle.UnpicklingError: |
105 return (False, _("INTERNAL ERROR: invalid arguments")) | 105 return (False, _("INTERNAL ERROR: invalid arguments")) |
106 return self._gcp.parseArguments(args, str(source_path)) | 106 try: |
107 source_path = pickle.loads(str(source_path)) | |
108 except TypeError, pickle.UnpicklingError: | |
109 return (False, _("INTERNAL ERROR: invalid source_path")) | |
110 return self._gcp.parseArguments(args, source_path) | |
107 | 111 |
108 class Journal(): | 112 class Journal(): |
109 def __init__(self, path=const_JOURNAL_PATH): | 113 def __init__(self, path=const_JOURNAL_PATH): |
110 self.journal_path = os.path.expanduser(path) | 114 self.journal_path = os.path.expanduser(path) |
111 self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals | 115 self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals |
116 self.__entry_open = False | |
112 | 117 |
113 def __del__(self): | 118 def __del__(self): |
114 self.journal_fd.flush() | 119 self.journal_fd.flush() |
115 self.journal_fd.close() | 120 self.journal_fd.close() |
116 | 121 |
117 def startFile(self, source_path): | 122 def startFile(self, source_path): |
118 """Start an entry in the journal""" | 123 """Start an entry in the journal""" |
124 assert not self.__entry_open | |
125 self.__entry_open = True | |
119 self.journal_fd.write(source_path+"\n") | 126 self.journal_fd.write(source_path+"\n") |
120 self.journal_fd.flush() | 127 self.journal_fd.flush() |
121 self.success=True | 128 self.success=True |
122 self.errors=[] | 129 self.errors=[] |
123 | 130 |
124 def closeFile(self): | 131 def closeFile(self): |
125 """Close the entry in the journal""" | 132 """Close the entry in the journal""" |
133 assert self.__entry_open | |
126 if not self.success: | 134 if not self.success: |
127 status = "FAILED" | 135 status = "FAILED" |
128 else: | 136 else: |
129 status = "OK" if not self.errors else "PARTIAL" | 137 status = "OK" if not self.errors else "PARTIAL" |
130 self.journal_fd.write("%(status)s: %(errors)s\n" % {'status': status, 'errors': ', '.join(self.errors)}) | 138 self.journal_fd.write("%(status)s: %(errors)s\n" % {'status': status, 'errors': ', '.join(self.errors)}) |
131 self.journal_fd.flush() | 139 self.journal_fd.flush() |
140 self.__entry_open = False | |
132 | 141 |
133 def copyFailed(self): | 142 def copyFailed(self): |
134 """Must be called when something is wrong with the copy itself""" | 143 """Must be called when something is wrong with the copy itself""" |
144 assert self.__entry_open | |
135 self.success = False | 145 self.success = False |
136 | 146 |
137 def error(self, name): | 147 def error(self, name): |
138 """Something went wrong""" | 148 """Something went wrong""" |
149 assert self.__entry_open | |
139 self.errors.append(name) | 150 self.errors.append(name) |
140 | 151 |
141 | 152 |
142 class GCP(): | 153 class GCP(): |
143 | 154 |
497 | 508 |
498 parser.add_option("--preserve", action="store", default='mode,ownership,timestamps', | 509 parser.add_option("--preserve", action="store", default='mode,ownership,timestamps', |
499 help=_("preserve the specified attributes")) | 510 help=_("preserve the specified attributes")) |
500 | 511 |
501 #parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True, | 512 #parser.add_option("--no-unicode-fix", action="store_false", dest='unicode_fix', default=True, |
502 # help=_("don't fixe name encoding errors")) #TODO | 513 # help=_("don't fix name encoding errors")) #TODO |
503 | 514 |
504 parser.add_option("--no-fs-fix", action="store_false", dest='fs_fix', default=True, | 515 parser.add_option("--no-fs-fix", action="store_false", dest='fs_fix', default=True, |
505 help=_("don't fixe filesystem name incompatibily")) | 516 help=_("don't fix filesystem name incompatibily")) |
506 | 517 |
507 parser.add_option("--no-progress", action="store_false", dest="progress", default=True, | 518 parser.add_option("--no-progress", action="store_false", dest="progress", default=True, |
508 help=_("deactivate progress bar")) | 519 help=_("deactivate progress bar")) |
509 | 520 |
510 parser.add_option("-v", "--verbose", action="store_true", default=False, | 521 parser.add_option("-v", "--verbose", action="store_true", default=False, |
558 #if there is an other instance of gcp, we send options to it | 569 #if there is an other instance of gcp, we send options to it |
559 if not self._main_instance: | 570 if not self._main_instance: |
560 info (_("There is already one instance of %s running, pluging to it") % NAME_SHORT) | 571 info (_("There is already one instance of %s running, pluging to it") % NAME_SHORT) |
561 #XXX: we have to serialize data as dbus only accept valid unicode, and filenames | 572 #XXX: we have to serialize data as dbus only accept valid unicode, and filenames |
562 # can have invalid unicode. | 573 # can have invalid unicode. |
563 return self.gcp_main.addArgs(os.getcwd(),pickle.dumps(full_args)) | 574 return self.gcp_main.addArgs(pickle.dumps(os.getcwd()),pickle.dumps(full_args)) |
564 else: | 575 else: |
565 if len(args) < 2: | 576 if len(args) < 2: |
566 _error_msg = _("Wrong number of arguments") | 577 _error_msg = _("Wrong number of arguments") |
567 return (False, _error_msg) | 578 return (False, _error_msg) |
568 debug(_("adding args to gcp: %s") % str(args).decode('utf-8','replace')) | 579 debug(_("adding args to gcp: %s") % str(args).decode('utf-8','replace')) |