1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import os
23 import types
24 import errno
25
26 import duplicity.backend
27 from duplicity import log
28 from duplicity import path
29 from duplicity import util
30 from duplicity.errors import *
31
32
34 """Use this backend when saving to local disk
35
36 Urls look like file://testfiles/output. Relative to root can be
37 gotten with extra slash (file:///usr/local).
38
39 """
46
62
63 - def move(self, source_path, remote_filename = None):
64 self.put(source_path, remote_filename, rename_instead = True)
65
66 - def put(self, source_path, remote_filename = None, rename_instead = False):
67 if not remote_filename:
68 remote_filename = source_path.get_filename()
69 target_path = self.remote_pathdir.append(remote_filename)
70 log.Info("Writing %s" % target_path.name)
71 """Try renaming first (if allowed to), copying if doesn't work"""
72 if rename_instead:
73 try:
74 source_path.rename(target_path)
75 except OSError:
76 pass
77 except Exception, e:
78 self.handle_error(e, 'put', source_path.name, target_path.name)
79 else:
80 return
81 try:
82 target_path.writefileobj(source_path.open("rb"))
83 except Exception, e:
84 self.handle_error(e, 'put', source_path.name, target_path.name)
85
86 """If we get here, renaming failed previously"""
87 if rename_instead:
88 """We need to simulate its behaviour"""
89 source_path.delete()
90
91 - def get(self, filename, local_path):
98
100 """List files in that directory"""
101 try:
102 os.makedirs(self.remote_pathdir.base)
103 except Exception:
104 pass
105 try:
106 return self.remote_pathdir.listdir()
107 except Exception, e:
108 self.handle_error(e, 'list', self.remote_pathdir.name)
109
110 - def delete(self, filename_list):
111 """Delete all files in filename list"""
112 assert type(filename_list) is not types.StringType
113 for filename in filename_list:
114 try:
115 self.remote_pathdir.append(filename).delete()
116 except Exception, e:
117 self.handle_error(e, 'delete', self.remote_pathdir.append(filename).name)
118
120 """Query attributes on filename"""
121 try:
122 target_file = self.remote_pathdir.append(filename)
123 if not os.path.exists(target_file.name):
124 return {'size': -1}
125 target_file.setdata()
126 size = target_file.getsize()
127 return {'size': size}
128 except Exception, e:
129 self.handle_error(e, 'query', target_file.name)
130 return {'size': None}
131
132 duplicity.backend.register_backend("file", LocalBackend)
133