Mercurial > gcp
comparison gcp @ 9:599b84e4ff01
- added utf-8 decoding of strings in logs, with 'replace' for badly encoded names
- vfat filename fixing now remove traling spaces
- new param "no_journal" in __filename_fix to avoid writing in journal. Mainly used as a temporary workaround as directory creation is not journalised yet.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Sep 2010 12:26:18 +0800 |
parents | 144cb2669f21 |
children | 00b27fce4677 |
comparison
equal
deleted
inserted
replaced
8:144cb2669f21 | 9:599b84e4ff01 |
---|---|
193 | 193 |
194 def __appendToList(self, path, dest_path, options): | 194 def __appendToList(self, path, dest_path, options): |
195 """Add a file to the copy list | 195 """Add a file to the copy list |
196 @param path: absolute path of file | 196 @param path: absolute path of file |
197 @param options: options as return by optparse""" | 197 @param options: options as return by optparse""" |
198 debug ("Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)" % {"path":path, | 198 debug (_("Adding to copy list: %(path)s ==> %(dest_path)s (%(fs_type)s)") % {"path":path.decode('utf-8','replace'), |
199 "dest_path":dest_path, | 199 "dest_path":dest_path.decode('utf-8','replace'), |
200 "fs_type":self.getFsType(dest_path)} ) | 200 "fs_type":self.getFsType(dest_path)} ) |
201 try: | 201 try: |
202 self.bytes_total+=os.path.getsize(path) | 202 self.bytes_total+=os.path.getsize(path) |
203 self.copy_list.insert(0,(path, dest_path, options)) | 203 self.copy_list.insert(0,(path, dest_path, options)) |
204 except OSError,e: | 204 except OSError,e: |
205 error(_("Can't copy %(path)s: %(exception)s") % {'path':path, 'exception':e.strerror}) | 205 error(_("Can't copy %(path)s: %(exception)s") % {'path':path.decode('utf-8','replace'), 'exception':e.strerror}) |
206 | 206 |
207 | 207 |
208 def __appendDirToList(self, dirpath, dest_path, options): | 208 def __appendDirToList(self, dirpath, dest_path, options): |
209 """Add recursively directory to the copy list | 209 """Add recursively directory to the copy list |
210 @param path: absolute path of dir | 210 @param path: absolute path of dir |
211 @param options: options as return by optparse""" | 211 @param options: options as return by optparse""" |
212 #We first check that the dest path exists, and create it if needed | 212 #We first check that the dest path exists, and create it if needed |
213 dest_path = self.__filename_fix(dest_path, options) | 213 dest_path = self.__filename_fix(dest_path, options, no_journal=True) |
214 if not os.path.exists(dest_path): | 214 if not os.path.exists(dest_path): |
215 debug (_("Creating directory %s") % dest_path) | 215 debug ("Creating directory %s" % dest_path) |
216 os.makedirs(dest_path) #TODO: check permissions | 216 os.makedirs(dest_path) #TODO: check permissions |
217 #TODO: check that dest_path is an accessible dir, | 217 #TODO: check that dest_path is an accessible dir, |
218 # and skip file/write error in log if needed | 218 # and skip file/write error in log if needed |
219 try: | 219 try: |
220 for filename in os.listdir(dirpath): | 220 for filename in os.listdir(dirpath): |
223 full_dest_path = os.path.join(dest_path,filename) | 223 full_dest_path = os.path.join(dest_path,filename) |
224 self.__appendDirToList(filepath, full_dest_path, options) | 224 self.__appendDirToList(filepath, full_dest_path, options) |
225 else: | 225 else: |
226 self.__appendToList(filepath, dest_path, options) | 226 self.__appendToList(filepath, dest_path, options) |
227 except OSError,e: | 227 except OSError,e: |
228 error(_("Can't copy %(path)s: %(exception)s") % {'path':dirpath, 'exception':e.strerror}) | 228 error(_("Can't append %(path)s to copy list: %(exception)s") % {'path':filepath.decode('utf-8','replace'), |
229 'exception':e.strerror}) | |
229 | 230 |
230 def __checkArgs(self, options, source_path, args): | 231 def __checkArgs(self, options, source_path, args): |
231 """Check thats args are files, and add them to copy list""" | 232 """Check thats args are files, and add them to copy list""" |
232 assert(len (args)>=2) | 233 assert(len (args)>=2) |
233 try: | 234 try: |
272 return True | 273 return True |
273 | 274 |
274 gobject.io_add_watch(source_fd,gobject.IO_IN,self._copyFile, | 275 gobject.io_add_watch(source_fd,gobject.IO_IN,self._copyFile, |
275 (dest_fd, options), priority=gobject.PRIORITY_HIGH) | 276 (dest_fd, options), priority=gobject.PRIORITY_HIGH) |
276 if not self.progress: | 277 if not self.progress: |
277 info(_("COPYING %(source)s ==> %(dest)s") % {"source":source_path,"dest":dest_file}) | 278 info(_("COPYING %(source)s ==> %(dest)s") % {"source":source_path.decode('utf-8','replace'), |
279 "dest":dest_file.decode('utf-8','replace')}) | |
278 return True | 280 return True |
279 else: | 281 else: |
280 #Nothing left to copy, we quit | 282 #Nothing left to copy, we quit |
281 if self.progress: | 283 if self.progress: |
282 self.__pbar_finish() | 284 self.__pbar_finish() |
321 self.__post_copy(source_fd.name, dest_fd.name, options) | 323 self.__post_copy(source_fd.name, dest_fd.name, options) |
322 self.journal.closeFile() | 324 self.journal.closeFile() |
323 return False | 325 return False |
324 return True | 326 return True |
325 | 327 |
326 def __filename_fix(self, filename, options): | 328 def __filename_fix(self, filename, options, no_journal=False): |
327 """Fix filenames incompatibilities/mistake according to options | 329 """Fix filenames incompatibilities/mistake according to options |
328 @param filename: full path to the file | 330 @param filename: full path to the file |
329 @param options: options as parsed on command line | 331 @param options: options as parsed on command line |
332 @param no_journal: don't write any entry in journal | |
330 @return: fixed filename""" | 333 @return: fixed filename""" |
331 fixed_filename = filename | 334 fixed_filename = filename |
332 | 335 |
333 if self.getFsType(filename) == 'vfat' and options.fs_fix: | 336 if self.getFsType(filename) == 'vfat' and options.fs_fix: |
334 fixed_filename = filename.replace('\\','_')\ | 337 fixed_filename = filename.replace('\\','_')\ |
335 .replace(':',';')\ | 338 .replace(':',';')\ |
336 .replace('*','+')\ | 339 .replace('*','+')\ |
337 .replace('?','')\ | 340 .replace('?','_')\ |
338 .replace('"','\'')\ | 341 .replace('"','\'')\ |
339 .replace('<','[')\ | 342 .replace('<','[')\ |
340 .replace('>',']')\ | 343 .replace('>',']')\ |
341 .replace('|','!') | 344 .replace('|','!')\ |
342 | 345 .rstrip() #XXX: suffixed spaces cause issues (must check FAT doc for why) |
343 if fixed_filename != filename: | 346 |
347 if not fixed_filename: | |
348 fixed_filename = '_' | |
349 if fixed_filename != filename and not no_journal: | |
344 self.journal.error('filename fixed') | 350 self.journal.error('filename fixed') |
345 return fixed_filename | 351 return fixed_filename |
346 | 352 |
347 def __post_copy(self, source_file, dest_file, options): | 353 def __post_copy(self, source_file, dest_file, options): |
348 """Do post copy traitement (mainly managing --preserve option)""" | 354 """Do post copy traitement (mainly managing --preserve option)""" |
447 return self.gcp_main.addArgs(os.getcwd(),pickle.dumps(full_args)) | 453 return self.gcp_main.addArgs(os.getcwd(),pickle.dumps(full_args)) |
448 else: | 454 else: |
449 if len(args) < 2: | 455 if len(args) < 2: |
450 _error_msg = _("Wrong number of arguments") | 456 _error_msg = _("Wrong number of arguments") |
451 return (False, _error_msg) | 457 return (False, _error_msg) |
452 debug(_("adding args to gcp: %s"),args) | 458 debug(_("adding args to gcp: %s") % str(args).decode('utf-8','replace')) |
453 self.__checkArgs(options, source_path, args) | 459 self.__checkArgs(options, source_path, args) |
454 self.journal = Journal() | 460 self.journal = Journal() |
455 gobject.idle_add(self.__copyNextFile) | 461 gobject.idle_add(self.__copyNextFile) |
456 return (True,'') | 462 return (True,'') |
457 | 463 |