comparison gcp @ 25:f82731c70956

Error are now shown after the end of the copy
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2010 16:18:45 +0800
parents 154fe67bae72
children d0c00ef2b917
comparison
equal deleted inserted replaced
24:154fe67bae72 25:f82731c70956
74 const_PRESERVE = set(['mode','ownership','timestamps']) 74 const_PRESERVE = set(['mode','ownership','timestamps'])
75 const_FILES_DIR = "~/.gcp" 75 const_FILES_DIR = "~/.gcp"
76 const_JOURNAL_PATH = const_FILES_DIR + "/journal" 76 const_JOURNAL_PATH = const_FILES_DIR + "/journal"
77 const_SAVED_LIST = const_FILES_DIR + "/saved_list" 77 const_SAVED_LIST = const_FILES_DIR + "/saved_list"
78 78
79 COLOR_RED = "\033[00;31m"
80 COLOR_END = '\033[0m'
81
82
83
79 84
80 class DbusObject(dbus.service.Object): 85 class DbusObject(dbus.service.Object):
81 86
82 def __init__(self, gcp, bus, path): 87 def __init__(self, gcp, bus, path):
83 self._gcp = gcp 88 self._gcp = gcp
111 116
112 class Journal(): 117 class Journal():
113 def __init__(self, path=const_JOURNAL_PATH): 118 def __init__(self, path=const_JOURNAL_PATH):
114 self.journal_path = os.path.expanduser(path) 119 self.journal_path = os.path.expanduser(path)
115 self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals 120 self.journal_fd = open(self.journal_path,'w') #TODO: check and maybe save previous journals
116 self.__entry_open = False 121 self.__entry_open = None
122 self.failed = []
123 self.partial = []
117 124
118 def __del__(self): 125 def __del__(self):
119 self.journal_fd.flush() 126 self.journal_fd.flush()
120 self.journal_fd.close() 127 self.journal_fd.close()
121 128
122 def startFile(self, source_path): 129 def startFile(self, source_path):
123 """Start an entry in the journal""" 130 """Start an entry in the journal"""
124 assert not self.__entry_open 131 assert not self.__entry_open
125 self.__entry_open = True 132 self.__entry_open = source_path
126 self.journal_fd.write(source_path+"\n") 133 self.journal_fd.write(source_path+"\n")
127 self.journal_fd.flush() 134 self.journal_fd.flush()
128 self.success=True 135 self.success=True
129 self.errors=[] 136 self.errors=[]
130 137
135 status = "FAILED" 142 status = "FAILED"
136 else: 143 else:
137 status = "OK" if not self.errors else "PARTIAL" 144 status = "OK" if not self.errors else "PARTIAL"
138 self.journal_fd.write("%(status)s: %(errors)s\n" % {'status': status, 'errors': ', '.join(self.errors)}) 145 self.journal_fd.write("%(status)s: %(errors)s\n" % {'status': status, 'errors': ', '.join(self.errors)})
139 self.journal_fd.flush() 146 self.journal_fd.flush()
140 self.__entry_open = False 147 self.__entry_open = None
141 148
142 def copyFailed(self): 149 def copyFailed(self):
143 """Must be called when something is wrong with the copy itself""" 150 """Must be called when something is wrong with the copy itself"""
144 assert self.__entry_open 151 assert self.__entry_open
145 self.success = False 152 self.success = False
153 self.failed.append(self.__entry_open)
146 154
147 def error(self, name): 155 def error(self, name):
148 """Something went wrong""" 156 """Something went wrong"""
149 assert self.__entry_open 157 assert self.__entry_open
150 self.errors.append(name) 158 self.errors.append(name)
151 159 self.partial.append(self.__entry_open)
160
161 def showErrors(self):
162 """Show which files were not successfully copied"""
163 failed = set(self.failed)
164 partial = set(self.partial)
165 for entry in failed:
166 partial.discard(entry)
167
168 if failed:
169 error(_(COLOR_RED+"/!\\ THE FOLLOWING FILES WERE NOT SUCCESSFULY COPIED:" + COLOR_END))
170 #TODO: use logging capability to print all error message in read instead of COLOR_RED
171 for entry in failed:
172 info("\t- %s" % entry)
173 info ('--\n')
174 if partial:
175 warning(_("The following files were copied, but some errors happened:"))
176 for entry in partial:
177 info("\t- %s" % entry)
178 info ('--\n')
179
180 if failed or partial:
181 info(_("Please check journal: %s") % self.journal_path)
182
183
184
152 185
153 class GCP(): 186 class GCP():
154 187
155 def __init__(self): 188 def __init__(self):
156 files_dir = os.path.expanduser(const_FILES_DIR) 189 files_dir = os.path.expanduser(const_FILES_DIR)
297 return True 330 return True
298 else: 331 else:
299 #Nothing left to copy, we quit 332 #Nothing left to copy, we quit
300 if self.progress: 333 if self.progress:
301 self.__pbar_finish() 334 self.__pbar_finish()
335 self.journal.showErrors()
302 self.loop.quit() 336 self.loop.quit()
303 337
304 def __copyFailed(self, reason, source_fd, dest_fd): 338 def __copyFailed(self, reason, source_fd, dest_fd):
305 """Write the failure in the journal and close files descriptors""" 339 """Write the failure in the journal and close files descriptors"""
306 self.journal.copyFailed() 340 self.journal.copyFailed()