~ubuntu-branches/ubuntu/maverick/duplicity/maverick-proposed

« back to all changes in this revision

Viewing changes to src/backends/botobackend.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Hahler
  • Date: 2009-02-12 23:31:44 UTC
  • mfrom: (1.1.8 upstream) (5.2.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090212233144-fzxu9a94bnd2l05d
Tags: 0.5.08-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2002 Ben Escoto
 
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>
2
5
#
3
6
# This file is part of duplicity.
4
7
#
23
26
import duplicity.globals as globals
24
27
import duplicity.log as log
25
28
from duplicity.errors import *
 
29
from duplicity.util import exception_traceback
26
30
 
27
31
class BotoBackend(duplicity.backend.Backend):
28
32
    """
78
82
                if cfs_supported:
79
83
                    calling_format = SubdomainCallingFormat()
80
84
                else:
81
 
                    log.FataError("Use of new-style (subdomain) S3 bucket addressing was"
82
 
                                  "requested, but does not seem to be supported by the "
83
 
                                  "boto library. Either you need to upgrade your boto "
84
 
                                  "library or duplicity has failed to correctly detect "
85
 
                                  "the appropriate support.")
 
85
                    log.FatalError("Use of new-style (subdomain) S3 bucket addressing was"
 
86
                                   "requested, but does not seem to be supported by the "
 
87
                                   "boto library. Either you need to upgrade your boto "
 
88
                                   "library or duplicity has failed to correctly detect "
 
89
                                   "the appropriate support.",
 
90
                                   log.ErrorCode.boto_old_style)
86
91
            else:
87
92
                if cfs_supported:
88
93
                    calling_format = OrdinaryCallingFormat()
91
96
 
92
97
        except ImportError:
93
98
            log.FatalError("This backend  (s3) requires boto library, version 0.9d or later, "
94
 
                           "(http://code.google.com/p/boto/).")
 
99
                           "(http://code.google.com/p/boto/).",
 
100
                           log.ErrorCode.boto_lib_too_old)
95
101
 
96
102
        if not os.environ.has_key('AWS_ACCESS_KEY_ID'):
97
103
            raise BackendException("The AWS_ACCESS_KEY_ID environment variable is not set.")
110
116
            if calling_format is None:
111
117
                log.FatalError("It seems we previously failed to detect support for calling "
112
118
                               "formats in the boto library, yet the support is there. This is "
113
 
                               "almost certainly a duplicity bug.")
 
119
                               "almost certainly a duplicity bug.",
 
120
                               log.ErrorCode.boto_calling_format)
114
121
            else:
115
122
                self.conn.calling_format = calling_format
116
123
 
155
162
            try:
156
163
                key.set_contents_from_filename(source_path.name, {'Content-Type': 'application/octet-stream'})
157
164
                return
158
 
            except:
159
 
                pass
160
 
            log.Log("Upload '%s/%s' failed (attempt #%d)" % (self.straight_url, remote_filename, n), 1)
 
165
            except Exception, e:
 
166
                log.Log("Upload '%s/%s' failed (attempt #%d, reason: %s: %s)"
 
167
                        "" % (self.straight_url,
 
168
                              remote_filename,
 
169
                              n,
 
170
                              e.__class__.__name__,
 
171
                              str(e)), 1)
 
172
                log.Log("Backtrace of previous error: %s" % (exception_traceback(),), 6)
161
173
            time.sleep(30)
162
174
        log.Log("Giving up trying to upload %s/%s after %d attempts" % (self.straight_url, remote_filename, globals.num_retries), 1)
163
175
        raise BackendException("Error uploading %s/%s" % (self.straight_url, remote_filename))
171
183
                key.get_contents_to_filename(local_path.name)
172
184
                local_path.setdata()
173
185
                return
174
 
            except:
175
 
                pass
176
 
            log.Log("Download %s/%s failed (attempt #%d)" % (self.straight_url, remote_filename, n), 1)
 
186
            except Exception, e:
 
187
                log.Log("Download %s/%s failed (attempt #%d, reason: %s: %s)"
 
188
                        "" % (self.straight_url,
 
189
                              remote_filename,
 
190
                              n,
 
191
                              e.__class__.__name__,
 
192
                              str(e)), 1)
 
193
                log.Log("Backtrace of previous error: %s" % (exception_traceback(),), 6)
 
194
                
177
195
            time.sleep(30)
178
196
        log.Log("Giving up trying to download %s/%s after %d attempts" % (self.straight_url, remote_filename, globals.num_retries), 1)
179
197
        raise BackendException("Error downloading %s/%s" % (self.straight_url, remote_filename))