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

« back to all changes in this revision

Viewing changes to src/backend.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
#
26
29
import time
27
30
import re
28
31
import getpass
 
32
import gettext
29
33
 
30
34
import duplicity.dup_temp as dup_temp
 
35
import duplicity.dup_threading as dup_threading
31
36
import duplicity.file_naming as file_naming
32
37
import duplicity.globals as globals
33
38
import duplicity.log as log
88
93
    else:
89
94
        return _backends[pu.scheme](pu)
90
95
 
 
96
_urlparser_initialized = False
 
97
_urlparser_initialized_lock = dup_threading.threading_module().Lock()
 
98
 
 
99
def _ensure_urlparser_initialized():
 
100
    """
 
101
    Ensure that the appropriate clobbering of variables in the
 
102
    urlparser module has been done. In the future, the need for this
 
103
    clobbering to begin with should preferably be eliminated.
 
104
    """
 
105
    def init():
 
106
        global _urlparser_initialized
 
107
 
 
108
        if not _urlparser_initialized:
 
109
            # These URL schemes have a backend with a notion of an RFC "network location".
 
110
            # The 'file' and 's3+http' schemes should not be in this list.
 
111
            # 'http' and 'https' are not actually used for duplicity backend urls, but are needed
 
112
            # in order to properly support urls returned from some webdav servers. adding them here
 
113
            # is a hack. we should instead not stomp on the url parsing module to begin with.
 
114
            #
 
115
            # todo: eliminate the need for backend specific hacking here completely.
 
116
            urlparser.uses_netloc = [ 'ftp', 'hsi', 'rsync', 's3', 'scp', 'ssh', 'webdav', 'webdavs', 'http', 'https', 'imap', 'imaps' ]
 
117
 
 
118
            # Do not transform or otherwise parse the URL path component.
 
119
            urlparser.uses_query = []
 
120
            urlparser.uses_fragm = []
 
121
        
 
122
            _urlparser_initialized = True
 
123
    
 
124
    dup_threading.with_lock(_urlparser_initialized_lock,
 
125
                            init)
 
126
 
91
127
def ParsedUrl(url_string):
92
 
    # These URL schemes have a backend with a notion of an RFC "network location".
93
 
    # The 'file' and 's3+http' schemes should not be in this list.
94
 
    # 'http' and 'https' are not actually used for duplicity backend urls, but are needed
95
 
    # in order to properly support urls returned from some webdav servers. adding them here
96
 
    # is a hack. we should instead not stomp on the url parsing module to begin with.
97
 
    #
98
 
    # todo: eliminate the need for backend specific hacking here completely.
99
 
    urlparser.uses_netloc = [ 'ftp', 'hsi', 'rsync', 's3', 'scp', 'ssh', 'webdav', 'webdavs', 'http', 'https', 'gmail' ]
100
 
 
101
 
    # Do not transform or otherwise parse the URL path component.
102
 
    urlparser.uses_query = []
103
 
    urlparser.uses_fragment = []
 
128
    """
 
129
    Parse the given URL as a duplicity backend URL.
 
130
 
 
131
    @return A parsed URL of the same form as that of the standard
 
132
            urlparse.urlparse().
 
133
 
 
134
    @raise InvalidBackendURL
 
135
    """
 
136
    _ensure_urlparser_initialized()
104
137
 
105
138
    pu = urlparser.urlparse(url_string)
106
139
 
211
244
        raise a BackendException.
212
245
        """
213
246
        private = self.munge_password(commandline)
214
 
        log.Log("Running '%s'" % private, 5)
 
247
        log.Log(_("Running '%s'") % private, 5)
215
248
        if os.system(commandline):
216
249
            raise BackendException("Error running '%s'" % private)
217
250
 
222
255
        """
223
256
        private = self.munge_password(commandline)
224
257
        for n in range(1, globals.num_retries+1):
225
 
            log.Log("Running '%s' (attempt #%d)" % (private, n), 5)
 
258
            log.Log(gettext.ngettext("Running '%s' (attempt #%d)",
 
259
                                     "Running '%s' (attempt #%d)", n) %
 
260
                                     (private, n), 5)
226
261
            if not os.system(commandline):
227
262
                return
228
 
            log.Log("Running '%s' failed (attempt #%d)" % (private, n), 1)
 
263
            log.Log(gettext.ngettext("Running '%s' failed (attempt #%d)",
 
264
                                     "Running '%s' failed (attempt #%d)", n) %
 
265
                                     (private, n), 1)
229
266
            time.sleep(30)
230
 
        log.Log("Giving up trying to execute '%s' after %d attempts" % (private, globals.num_retries), 1)
 
267
        log.Log(gettext.ngettext("Giving up trying to execute '%s' after %d attempt",
 
268
                                 "Giving up trying to execute '%s' after %d attempts",
 
269
                                 globals.num_retries) % (private, globals.num_retries),
 
270
                1)
231
271
        raise BackendException("Error running '%s'" % private)
232
272
 
233
273
    def popen(self, commandline):
236
276
        contents read from stdout) as a string.
237
277
        """
238
278
        private = self.munge_password(commandline)
239
 
        log.Log("Reading results of '%s'" % private, 5)
 
279
        log.Log(_("Reading results of '%s'") % private, 5)
240
280
        fout = os.popen(commandline)
241
281
        results = fout.read()
242
282
        if fout.close():
250
290
        """
251
291
        private = self.munge_password(commandline)
252
292
        for n in range(1, globals.num_retries+1):
253
 
            log.Log("Reading results of '%s'" % private, 5)
 
293
            log.Log(_("Reading results of '%s'") % private, 5)
254
294
            fout = os.popen(commandline)
255
295
            results = fout.read()
256
296
            result_status = fout.close()
260
300
                # This squelches the "file not found" result fromm ncftpls when
261
301
                # the ftp backend looks for a collection that does not exist.
262
302
                return ''
263
 
            log.Log("Running '%s' failed (attempt #%d)" % (private, n), 1)
 
303
            log.Log(gettext.ngettext("Running '%s' failed (attempt #%d)",
 
304
                                     "Running '%s' failed (attempt #%d)", n) %
 
305
                                     (private, n), 1)
264
306
            time.sleep(30)
265
 
        log.Log("Giving up trying to execute '%s' after %d attempts" % (private, globals.num_retries), 1)
 
307
        log.Log(gettext.ngettext("Giving up trying to execute '%s' after %d attempt",
 
308
                                 "Giving up trying to execute '%s' after %d attempts",
 
309
                                 globals.num_retries) % (private, globals.num_retries),
 
310
                1)
266
311
        raise BackendException("Error running '%s'" % private)
267
312
 
268
313
    def get_fileobj_read(self, filename, parseresults = None):