← Back to team overview

duplicity-team team mailing list archive

[Merge] lp:~mgorse/duplicity/0.8-series into lp:duplicity

 

Mgorse has proposed merging lp:~mgorse/duplicity/0.8-series into lp:duplicity.

Commit message:
More python 3 fixes

Requested reviews:
  duplicity-team (duplicity-team)

For more details, see:
https://code.launchpad.net/~mgorse/duplicity/0.8-series/+merge/363752
-- 
Your team duplicity-team is requested to review the proposed merge of lp:~mgorse/duplicity/0.8-series into lp:duplicity.
=== modified file 'bin/duplicity'
--- bin/duplicity	2018-11-29 19:00:15 +0000
+++ bin/duplicity	2019-02-27 22:47:02 +0000
@@ -1136,7 +1136,7 @@
     @rtype: void
     @return: void
     """
-    suffixes = [u".g", u".gpg", u".z", u".gz", u".part"]
+    suffixes = [b".g", b".gpg", b".z", b".gz", b".part"]
 
     def get_metafiles(filelist):
         u"""

=== modified file 'duplicity/backends/ncftpbackend.py'
--- duplicity/backends/ncftpbackend.py	2018-11-29 19:00:15 +0000
+++ duplicity/backends/ncftpbackend.py	2019-02-27 22:47:02 +0000
@@ -31,6 +31,7 @@
 from duplicity import globals
 from duplicity import log
 from duplicity import tempdir
+from duplicity import util
 
 
 class NCFTPBackend(duplicity.backend.Backend):
@@ -86,28 +87,31 @@
         else:
             self.conn_opt = u'-F'
 
-        self.tempfile, self.tempname = tempdir.default().mkstemp()
-        os.write(self.tempfile, u"host %s\n" % self.parsed_url.hostname)
-        os.write(self.tempfile, u"user %s\n" % self.parsed_url.username)
-        os.write(self.tempfile, u"pass %s\n" % self.password)
-        os.close(self.tempfile)
+        self.tempfd, self.tempname = tempdir.default().mkstemp()
+        self.tempfile = os.fdopen(self.tempfd, u"w")
+        self.tempfile.write(u"host %s\n" % self.parsed_url.hostname)
+        self.tempfile.write(u"user %s\n" % self.parsed_url.username)
+        self.tempfile.write(u"pass %s\n" % self.password)
+        self.tempfile.close()
         self.flags = u"-f %s %s -t %s -o useCLNT=0,useHELP_SITE=0 " % \
             (self.tempname, self.conn_opt, globals.timeout)
         if parsed_url.port is not None and parsed_url.port != 21:
             self.flags += u" -P '%s'" % (parsed_url.port)
 
     def _put(self, source_path, remote_filename):
+        remote_filename = util.fsdecode(remote_filename)
         remote_path = os.path.join(urllib.parse.unquote(re.sub(u'^/', u'', self.parsed_url.path)),
                                    remote_filename).rstrip()
         commandline = u"ncftpput %s -m -V -C '%s' '%s'" % \
-            (self.flags, source_path.name, remote_path)
+            (self.flags, source_path.uc_name, remote_path)
         self.subprocess_popen(commandline)
 
     def _get(self, remote_filename, local_path):
+        remote_filename = util.fsdecode(remote_filename)
         remote_path = os.path.join(urllib.parse.unquote(re.sub(u'^/', u'', self.parsed_url.path)),
                                    remote_filename).rstrip()
         commandline = u"ncftpget %s -V -C '%s' '%s' '%s'" % \
-            (self.flags, self.parsed_url.hostname, remote_path.lstrip(u'/'), local_path.name)
+            (self.flags, self.parsed_url.hostname, remote_path.lstrip(u'/'), local_path.uc_name)
         self.subprocess_popen(commandline)
 
     def _list(self):
@@ -115,7 +119,7 @@
         commandline = u"ncftpls %s -l '%s'" % (self.flags, self.url_string)
         _, l, _ = self.subprocess_popen(commandline)
         # Look for our files as the last element of a long list line
-        return [x.split()[-1] for x in l.split(u'\n') if x and not x.startswith(u"total ")]
+        return [x.split()[-1] for x in l.split(b'\n') if x and not x.startswith(b"total ")]
 
     def _delete(self, filename):
         commandline = u"ncftpls %s -l -X 'DELE %s' '%s'" % \

=== modified file 'duplicity/backends/rsyncbackend.py'
--- duplicity/backends/rsyncbackend.py	2018-11-29 19:00:15 +0000
+++ duplicity/backends/rsyncbackend.py	2019-02-27 22:47:02 +0000
@@ -109,13 +109,15 @@
                                 u"" % self.munge_password(url))
 
     def _put(self, source_path, remote_filename):
+        remote_filename = util.fsdecode(remote_filename)
         remote_path = os.path.join(self.url_string, remote_filename)
-        commandline = u"%s %s %s" % (self.cmd, source_path.name, remote_path)
+        commandline = u"%s %s %s" % (self.cmd, source_path.uc_name, remote_path)
         self.subprocess_popen(commandline)
 
     def _get(self, remote_filename, local_path):
+        remote_filename = util.fsdecode(remote_filename)
         remote_path = os.path.join(self.url_string, remote_filename)
-        commandline = u"%s %s %s" % (self.cmd, remote_path, local_path.name)
+        commandline = u"%s %s %s" % (self.cmd, remote_path, local_path.uc_name)
         self.subprocess_popen(commandline)
 
     def _list(self):
@@ -127,7 +129,7 @@
                 return None
         commandline = u"%s %s" % (self.cmd, self.url_string)
         result, stdout, stderr = self.subprocess_popen(commandline)
-        return [x for x in map(split, stdout.split(u'\n')) if x]
+        return [x for x in map(split, stdout.split(b'\n')) if x]
 
     def _delete_list(self, filename_list):
         delete_list = filename_list

=== modified file 'duplicity/backends/ssh_pexpect_backend.py'
--- duplicity/backends/ssh_pexpect_backend.py	2019-02-25 16:30:59 +0000
+++ duplicity/backends/ssh_pexpect_backend.py	2019-02-27 22:47:02 +0000
@@ -38,10 +38,9 @@
 import duplicity.backend
 from duplicity import globals
 from duplicity import log
+from duplicity import util
 from duplicity.errors import BackendException
 
-global pexpect
-
 
 class SSHPExpectBackend(duplicity.backend.Backend):
     u"""This backend copies files using scp.  List not supported.  Filenames
@@ -52,6 +51,8 @@
 
         try:
             import pexpect
+            global pexpect
+
         except ImportError:
             raise
 
@@ -172,7 +173,7 @@
                      u"open(.*): Failure"]
         max_response_len = max([len(p) for p in responses[1:]])
         log.Info(u"Running '%s'" % (commandline))
-        child = pexpect.spawn(commandline, timeout=None, maxread=maxread)
+        child = pexpect.spawn(commandline, timeout=None, maxread=maxread, encoding=globals.fsencoding)
         cmdloc = 0
         passprompt = 0
         while 1:
@@ -228,6 +229,7 @@
             raise BackendException(u"Error running '%s': %s" % (commandline, msg))
 
     def _put(self, source_path, remote_filename):
+        remote_filename = util.fsdecode(remote_filename)
         if self.use_scp:
             self.put_scp(source_path, remote_filename)
         else:
@@ -235,7 +237,7 @@
 
     def put_sftp(self, source_path, remote_filename):
         commands = [u"put \"%s\" \"%s.%s.part\"" %
-                    (source_path.name, self.remote_prefix, remote_filename),
+                    (source_path.uc_name, self.remote_prefix, remote_filename),
                     u"rename \"%s.%s.part\" \"%s%s\"" %
                     (self.remote_prefix, remote_filename, self.remote_prefix, remote_filename)]
         commandline = (u"%s %s %s" % (self.sftp_command,
@@ -245,11 +247,12 @@
 
     def put_scp(self, source_path, remote_filename):
         commandline = u"%s %s %s %s:%s%s" % \
-            (self.scp_command, globals.ssh_options, source_path.name, self.host_string,
+            (self.scp_command, globals.ssh_options, source_path.uc_name, self.host_string,
              self.remote_prefix, remote_filename)
         self.run_scp_command(commandline)
 
     def _get(self, remote_filename, local_path):
+        remote_filename = util.fsdecode(remote_filename)
         if self.use_scp:
             self.get_scp(remote_filename, local_path)
         else:
@@ -257,7 +260,7 @@
 
     def get_sftp(self, remote_filename, local_path):
         commands = [u"get \"%s%s\" \"%s\"" %
-                    (self.remote_prefix, remote_filename, local_path.name)]
+                    (self.remote_prefix, remote_filename, local_path.uc_name)]
         commandline = (u"%s %s %s" % (self.sftp_command,
                                       globals.ssh_options,
                                       self.host_string))
@@ -266,7 +269,7 @@
     def get_scp(self, remote_filename, local_path):
         commandline = u"%s %s %s:%s%s %s" % \
             (self.scp_command, globals.ssh_options, self.host_string, self.remote_prefix,
-             remote_filename, local_path.name)
+             remote_filename, local_path.uc_name)
         self.run_scp_command(commandline)
 
     def _list(self):
@@ -289,7 +292,7 @@
 
         l = self.run_sftp_command(commandline, commands).split(u'\n')[1:]
 
-        return [x for x in map(string.strip, l) if x]
+        return [x for x in map(u"".__class__.strip, l) if x]
 
     def _delete(self, filename):
         commands = [u"cd \"%s\"" % (self.remote_dir,)]

=== modified file 'duplicity/backends/sxbackend.py'
--- duplicity/backends/sxbackend.py	2018-07-23 14:55:39 +0000
+++ duplicity/backends/sxbackend.py	2019-02-27 22:47:02 +0000
@@ -20,6 +20,7 @@
 
 import os.path
 import duplicity.backend
+import duplicity.util
 
 
 class SXBackend(duplicity.backend.Backend):
@@ -29,13 +30,15 @@
         self.url_string = parsed_url.url_string
 
     def _put(self, source_path, remote_filename):
+        remote_filename = util.fsdecode(remote_filename)
         remote_path = os.path.join(self.url_string, remote_filename)
-        commandline = u"sxcp {0} {1}".format(source_path.name, remote_path)
+        commandline = u"sxcp {0} {1}".format(source_path.uc_name, remote_path)
         self.subprocess_popen(commandline)
 
     def _get(self, remote_filename, local_path):
+        remote_filename = util.fsdecode(remote_filename)
         remote_path = os.path.join(self.url_string, remote_filename)
-        commandline = u"sxcp {0} {1}".format(remote_path, local_path.name)
+        commandline = u"sxcp {0} {1}".format(remote_path, local_path.uc_name)
         self.subprocess_popen(commandline)
 
     def _list(self):
@@ -43,7 +46,7 @@
         commandline = u"sxls {0}".format(self.url_string)
         _, l, _ = self.subprocess_popen(commandline)
         # Look for our files as the last element of a long list line
-        return [x[x.rindex(u'/') + 1:].split()[-1] for x in l.split(u'\n') if x and not x.startswith(u"total ")]
+        return [x[x.rindex(u'/') + 1:].split()[-1] for x in l.split(b'\n') if x and not x.startswith(b"total ")]
 
     def _delete(self, filename):
         commandline = u"sxrm {0}/{1}".format(self.url_string, filename)

=== modified file 'testing/unit/test_selection.py'
--- testing/unit/test_selection.py	2018-11-29 19:00:15 +0000
+++ testing/unit/test_selection.py	2019-02-27 22:47:02 +0000
@@ -45,7 +45,7 @@
 
     def testRegexp(self):
         u"""Test regular expression selection func"""
-        sf1 = self.Select.regexp_get_sf(u".*\.py", 1)
+        sf1 = self.Select.regexp_get_sf(u".*\\.py", 1)
         assert sf1(self.makeext(u"1.py")) == 1
         assert sf1(self.makeext(u"usr/foo.py")) == 1
         assert sf1(self.root.append(u"1.doc")) is None


Follow ups