~duplicity-team/duplicity/0.7-series

« back to all changes in this revision

Viewing changes to duplicity/backends/lftpbackend.py

  • Committer: Kenneth Loafman
  • Date: 2014-12-12 14:39:54 UTC
  • Revision ID: kenneth@loafman.com-20141212143954-wyln65yd1ynzsrlx
* Source formatted, using PyDev, all source files to fix some easily fixed
  PEP8 issues. Use ignore space when comparing against previous versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
#        # strip lftp+ prefix
62
62
#        self.url_string = duplicity.backend.strip_prefix(self.url_string, 'lftp')
63
63
 
64
 
        self.scheme = duplicity.backend.strip_prefix( parsed_url.scheme, 'lftp' ).lower()
65
 
        self.scheme = re.sub('^webdav','http',self.scheme)
 
64
        self.scheme = duplicity.backend.strip_prefix(parsed_url.scheme, 'lftp').lower()
 
65
        self.scheme = re.sub('^webdav', 'http', self.scheme)
66
66
        self.url_string = self.scheme + '://' + parsed_url.hostname
67
67
        if parsed_url.port :
68
68
            self.url_string += ":%s" % parsed_url.port
69
69
 
70
 
        self.remote_path = re.sub('^/','',parsed_url.path)
 
70
        self.remote_path = re.sub('^/', '', parsed_url.path)
71
71
 
72
72
        # Use an explicit directory name.
73
73
        if self.remote_path[-1] != '/':
77
77
        if self.parsed_url.username:
78
78
            self.username = self.parsed_url.username
79
79
            self.password = self.get_password()
80
 
            self.authflag = "-u '%s,%s'" % (self.username,self.password)
 
80
            self.authflag = "-u '%s,%s'" % (self.username, self.password)
81
81
 
82
82
        if globals.ftp_connection == 'regular':
83
83
            self.conn_opt = 'off'
102
102
                raise duplicity.errors.FatalBackendException("""For certificate verification a cacert database file is needed in one of these locations: %s
103
103
Hints:
104
104
  Consult the man page, chapter 'SSL Certificate Verification'.
105
 
  Consider using the options --ssl-cacert-file, --ssl-no-check-certificate .""" % ", ".join(cacert_candidates) )
 
105
  Consider using the options --ssl-cacert-file, --ssl-no-check-certificate .""" % ", ".join(cacert_candidates))
106
106
 
107
107
        self.tempfile, self.tempname = tempdir.default().mkstemp()
108
 
        os.write(self.tempfile, "set ssl:verify-certificate " + ( "false" if globals.ssl_no_check_certificate else "true" ) + "\n")
 
108
        os.write(self.tempfile, "set ssl:verify-certificate " + ("false" if globals.ssl_no_check_certificate else "true") + "\n")
109
109
        if globals.ssl_cacert_file :
110
110
            os.write(self.tempfile, "set ssl:ca-file '" + globals.ssl_cacert_file + "'\n")
111
111
        if self.parsed_url.scheme == 'ftps':
120
120
        os.write(self.tempfile, "set ftp:passive-mode %s\n" % self.conn_opt)
121
121
        if log.getverbosity() >= log.DEBUG :
122
122
            os.write(self.tempfile, "debug\n")
123
 
        os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string) )
 
123
        os.write(self.tempfile, "open %s %s\n" % (self.authflag, self.url_string))
124
124
#        os.write(self.tempfile, "open %s %s\n" % (self.portflag, self.parsed_url.hostname))
125
125
        # allow .netrc auth by only setting user/pass when user was actually given
126
126
#        if self.parsed_url.username:
129
129
        if log.getverbosity() >= log.DEBUG :
130
130
            f = open(self.tempname, 'r')
131
131
            log.Debug("SETTINGS: \n"
132
 
                  "%s" % f.readlines() )
 
132
                  "%s" % f.readlines())
133
133
 
134
134
    def _put(self, source_path, remote_filename):
135
 
        #remote_path = os.path.join(urllib.unquote(self.parsed_url.path.lstrip('/')), remote_filename).rstrip()
 
135
        # remote_path = os.path.join(urllib.unquote(self.parsed_url.path.lstrip('/')), remote_filename).rstrip()
136
136
        commandline = "lftp -c 'source \'%s\'; mkdir -p %s; put \'%s\' -o \'%s\''" % \
137
137
            (self.tempname, self.remote_path, source_path.name, self.remote_path + remote_filename)
138
138
        log.Debug("CMD: %s" % commandline)
144
144
                  "%s" % (l))
145
145
 
146
146
    def _get(self, remote_filename, local_path):
147
 
        #remote_path = os.path.join(urllib.unquote(self.parsed_url.path), remote_filename).rstrip()
 
147
        # remote_path = os.path.join(urllib.unquote(self.parsed_url.path), remote_filename).rstrip()
148
148
        commandline = "lftp -c 'source \'%s\'; get \'%s\' -o \'%s\''" % \
149
 
            (self.tempname, self.remote_path+remote_filename, local_path.name)
 
149
            (self.tempname, self.remote_path + remote_filename, local_path.name)
150
150
        log.Debug("CMD: %s" % commandline)
151
151
        _, l, e = self.subprocess_popen(commandline)
152
152
        log.Debug("STDERR:\n"
156
156
 
157
157
    def _list(self):
158
158
        # Do a long listing to avoid connection reset
159
 
        #remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/')).rstrip()
 
159
        # remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/')).rstrip()
160
160
        remote_dir = urllib.unquote(self.parsed_url.path)
161
 
        #print remote_dir
 
161
        # print remote_dir
162
162
        commandline = "lftp -c 'source \'%s\'; cd \'%s\' || exit 0; ls'" % (self.tempname, self.remote_path)
163
163
        log.Debug("CMD: %s" % commandline)
164
164
        _, l, e = self.subprocess_popen(commandline)
171
171
        return [x.split()[-1] for x in l.split('\n') if x]
172
172
 
173
173
    def _delete(self, filename):
174
 
        #remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/')).rstrip()
 
174
        # remote_dir = urllib.unquote(self.parsed_url.path.lstrip('/')).rstrip()
175
175
        commandline = "lftp -c 'source \'%s\'; cd \'%s\'; rm \'%s\''" % (self.tempname, self.remote_path, filename)
176
176
        log.Debug("CMD: %s" % commandline)
177
177
        _, l, e = self.subprocess_popen(commandline)