Package duplicity :: Module robust
[hide private]
[frames] | no frames]

Source Code for Module duplicity.robust

 1  # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- 
 2  # 
 3  # Copyright 2002 Ben Escoto <ben@emerose.org> 
 4  # Copyright 2007 Kenneth Loafman <kenneth@loafman.com> 
 5  # 
 6  # This file is part of duplicity. 
 7  # 
 8  # Duplicity is free software; you can redistribute it and/or modify it 
 9  # under the terms of the GNU General Public License as published by the 
10  # Free Software Foundation; either version 2 of the License, or (at your 
11  # option) any later version. 
12  # 
13  # Duplicity is distributed in the hope that it will be useful, but 
14  # WITHOUT ANY WARRANTY; without even the implied warranty of 
15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
16  # General Public License for more details. 
17  # 
18  # You should have received a copy of the GNU General Public License 
19  # along with duplicity; if not, write to the Free Software Foundation, 
20  # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
21   
22  import errno 
23   
24  tmp_file_index = 1 
25   
26 -def check_common_error(error_handler, function, args = ()):
27 """Apply function to args, if error, run error_handler on exception 28 29 This only catches certain exceptions which seem innocent 30 enough. 31 32 """ 33 # todo: import here to avoid circular dependency issue 34 from duplicity import path 35 36 try: 37 return function(*args) 38 #except (EnvironmentError, SkipFileException, DSRPPermError, 39 # RPathException, Rdiff.RdiffException, 40 # librsync.librsyncError, C.UnknownFileTypeError), exc: 41 # TracebackArchive.add() 42 except (IOError, EnvironmentError, librsync.librsyncError, path.PathException), exc: 43 if (not isinstance(exc, EnvironmentError) or 44 ((exc[0] in errno.errorcode) 45 and errno.errorcode[exc[0]] in 46 ['EPERM', 'ENOENT', 'EACCES', 'EBUSY', 'EEXIST', 47 'ENOTDIR', 'ENAMETOOLONG', 'EINTR', 'ENOTEMPTY', 48 'EIO', 'ETXTBSY', 'ESRCH', 'EINVAL'])): 49 #Log.exception() 50 if error_handler: 51 return error_handler(exc, *args) 52 else: 53 #Log.exception(1, 2) 54 raise
55
56 -def listpath(path):
57 """Like path.listdir() but return [] if error, and sort results""" 58 def error_handler(exc): 59 log.Warn(_("Error listing directory %s") % path.name) 60 return []
61 dir_listing = check_common_error(error_handler, path.listdir) 62 dir_listing.sort() 63 return dir_listing 64 65 from duplicity import librsync 66 from duplicity import log 67