python 2 compat
This commit is contained in:
@ -3,6 +3,11 @@ import os
|
|||||||
import select
|
import select
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
|
try:
|
||||||
|
from shlex import quote as cmd_quote
|
||||||
|
except ImportError:
|
||||||
|
from pipes import quote as cmd_quote
|
||||||
|
|
||||||
class CmdPipe:
|
class CmdPipe:
|
||||||
"""a pipe of one or more commands. also takes care of utf-8 encoding/decoding and line based parsing"""
|
"""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']) + ")"
|
ret = ret + "(" + " ".join(item['cmd']) + ")"
|
||||||
else:
|
else:
|
||||||
#make it copy-pastable, will make a mess of quotes sometimes, but is correct
|
#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
|
return ret
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
|
||||||
from zfs_autobackup.CmdPipe import CmdPipe
|
from zfs_autobackup.CmdPipe import CmdPipe
|
||||||
from zfs_autobackup.LogStub import LogStub
|
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):
|
class ExecuteError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -62,7 +67,7 @@ class ExecuteNode(LogStub):
|
|||||||
|
|
||||||
ret.append(self.ssh_to)
|
ret.append(self.ssh_to)
|
||||||
|
|
||||||
ret.append(" ".join(map(shlex.quote, cmd)))
|
ret.append(" ".join(map(cmd_quote, cmd)))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user