python 2 compat

This commit is contained in:
Edwin Eefting 2021-05-09 13:04:22 +02:00
parent c682665888
commit 0ce3bf1297
2 changed files with 13 additions and 3 deletions

@ -3,6 +3,11 @@ import os
import select
import shlex
try:
from shlex import quote as cmd_quote
except ImportError:
from pipes import quote as cmd_quote
class CmdPipe:
"""a pipe of one or more commands. also takes care of utf-8 encoding/decoding and line based parsing"""
@ -43,7 +48,7 @@ class CmdPipe:
ret = ret + "(" + " ".join(item['cmd']) + ")"
else:
#make it copy-pastable, will make a mess of quotes sometimes, but is correct
ret = ret + "(" + " ".join(map(shlex.quote,item['cmd'])) + ")"
ret = ret + "(" + " ".join(map(cmd_quote,item['cmd'])) + ")"
return ret

@ -1,10 +1,15 @@
import os
import select
import subprocess
import shlex
from zfs_autobackup.CmdPipe import CmdPipe
from zfs_autobackup.LogStub import LogStub
try:
from shlex import quote as cmd_quote
except ImportError:
from pipes import quote as cmd_quote
class ExecuteError(Exception):
pass
@ -62,7 +67,7 @@ class ExecuteNode(LogStub):
ret.append(self.ssh_to)
ret.append(" ".join(map(shlex.quote, cmd)))
ret.append(" ".join(map(cmd_quote, cmd)))
return ret