~aaron-whitehouse/duplicity/PEP8_line_length

« back to all changes in this revision

Viewing changes to duplicity/backends/swiftbackend.py

  • Committer: ken
  • Date: 2016-05-30 13:29:33 UTC
  • mfrom: (1213.1.1 duplicity_bzr)
  • Revision ID: ken-20160530132933-restu9dv8lxk6mzo
* Merged in lp:~ghoz/duplicity/swift-prefix
  - adds the abiliy to use path in the swift backend, in order to have multiple
    backups to the same container neatly organized.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
 
91
91
        conn_kwargs['os_options'] = os_options
92
92
 
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 != '']
 
97
 
 
98
        self.container = url_parts.pop(0)
 
99
        if url_parts:
 
100
            self.prefix = '%s/' % '/'.join(url_parts)
 
101
        else:
 
102
            self.prefix = ''
94
103
 
95
104
        container_metadata = None
96
105
        try:
118
127
                return log.ErrorCode.backend_not_found
119
128
 
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))
123
132
 
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:
128
137
                f.write(chunk)
129
138
 
130
139
    def _list(self):
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]
133
143
 
134
144
    def _delete(self, filename):
135
 
        self.conn.delete_object(self.container, filename)
 
145
        self.conn.delete_object(self.container, self.prefix + filename)
136
146
 
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'])}
140
150
 
141
151
duplicity.backend.register_backend("swift", SwiftBackend)