91
91
conn_kwargs['os_options'] = os_options
93
self.container = parsed_url.path.lstrip('/')
93
# This folds the null prefix and all null parts, which means that:
94
# //MyContainer/ and //MyContainer are equivalent.
95
# //MyContainer//My/Prefix/ and //MyContainer/My/Prefix are equivalent.
96
url_parts = [x for x in parsed_url.path.split('/') if x != '']
98
self.container = url_parts.pop(0)
100
self.prefix = '%s/' % '/'.join(url_parts)
95
104
container_metadata = None
118
127
return log.ErrorCode.backend_not_found
120
129
def _put(self, source_path, remote_filename):
121
self.conn.put_object(self.container, remote_filename,
130
self.conn.put_object(self.container, self.prefix + remote_filename,
122
131
file(source_path.name))
124
133
def _get(self, remote_filename, local_path):
125
headers, body = self.conn.get_object(self.container, remote_filename)
134
headers, body = self.conn.get_object(self.container, self.prefix + remote_filename)
126
135
with open(local_path.name, 'wb') as f:
127
136
for chunk in body:
131
headers, objs = self.conn.get_container(self.container, full_listing=True)
132
return [o['name'] for o in objs]
140
headers, objs = self.conn.get_container(self.container, full_listing=True, path=self.prefix)
141
# removes prefix from return values. should check for the prefix ?
142
return [o['name'][len(self.prefix):] for o in objs]
134
144
def _delete(self, filename):
135
self.conn.delete_object(self.container, filename)
145
self.conn.delete_object(self.container, self.prefix + filename)
137
147
def _query(self, filename):
138
sobject = self.conn.head_object(self.container, filename)
148
sobject = self.conn.head_object(self.container, self.prefix + filename)
139
149
return {'size': int(sobject['content-length'])}
141
151
duplicity.backend.register_backend("swift", SwiftBackend)