Only quote commandline arguments that need quoting.

This commit is contained in:
Bastian Kleineidam 2010-04-04 19:12:24 +02:00
parent 7d39df7748
commit 8cbef81a50
10 changed files with 66 additions and 74 deletions

View File

@ -19,15 +19,15 @@ from patoolib import util
def extract_bzip2 (archive, encoding, cmd, **kwargs): def extract_bzip2 (archive, encoding, cmd, **kwargs):
"""Extract a BZIP2 archive.""" """Extract a BZIP2 archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.extend(['-c', '-d']) cmdlist.extend(['-c', '-d'])
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['--', archive, '>', outfile]) cmdlist.extend(['--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})
def test_bzip2 (archive, encoding, cmd, **kwargs): def test_bzip2 (archive, encoding, cmd, **kwargs):
@ -41,12 +41,11 @@ def test_bzip2 (archive, encoding, cmd, **kwargs):
def create_bzip2 (archive, encoding, cmd, *args, **kwargs): def create_bzip2 (archive, encoding, cmd, *args, **kwargs):
"""Create a BZIP2 archive.""" """Create a BZIP2 archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.extend(['-c', '-z', '--']) cmdlist.extend(['-c', '-z', '--'])
cmdlist.extend(args) cmdlist.extend([util.shell_quote(x) for x in args])
cmdlist.extend(['>', archive]) cmdlist.extend(['>', util.shell_quote(archive)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,12 +19,11 @@ from patoolib import util
def create_compress (archive, encoding, cmd, *args, **kwargs): def create_compress (archive, encoding, cmd, *args, **kwargs):
"""Create a compressed archive.""" """Create a compressed archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.append('-c') cmdlist.append('-c')
cmdlist.extend(args) cmdlist.extend([util.shell_quote(x) for x in args])
cmdlist.extend(['>', archive]) cmdlist.extend(['>', util.shell_quote(archive)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,14 +19,13 @@ from patoolib import util
def extract_cpio (archive, encoding, cmd, **kwargs): def extract_cpio (archive, encoding, cmd, **kwargs):
"""Extract a CPIO archive.""" """Extract a CPIO archive."""
cmdlist = [cmd, '--extract', '--make-directories', cmdlist = [util.shell_quote(cmd), '--extract', '--make-directories',
'--preserve-modification-time', '--no-absolute-filenames', '--preserve-modification-time', '--no-absolute-filenames',
'--force-local', '--nonmatching', '"*\.\.*"'] '--force-local', '--nonmatching', r'"*\.\.*"']
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.extend(['<', os.path.abspath(archive)]) cmdlist.extend(['<', util.shell_quote(os.path.abspath(archive))])
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'cwd': kwargs['outdir'], 'shell': True})
return (cmd, {'cwd': kwargs['outdir'], 'shell': True})
def list_cpio (archive, encoding, cmd, **kwargs): def list_cpio (archive, encoding, cmd, **kwargs):
@ -41,15 +40,14 @@ test_cpio = list_cpio
def create_cpio(archive, encoding, cmd, *args, **kwargs): def create_cpio(archive, encoding, cmd, *args, **kwargs):
"""Create a CPIO archive.""" """Create a CPIO archive."""
cmdlist = [cmd, '--create'] cmdlist = [util.shell_quote(cmd), '--create']
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
if len(args) != 0: if len(args) != 0:
findcmd = ['find', '-print0'] findcmd = ['find', '-print0']
findcmd.extend(args) findcmd.extend([util.shell_quote(x) for x in args])
findcmd.append('|') findcmd.append('|')
cmdlist[0:0] = findcmd cmdlist[0:0] = findcmd
cmdlist.append('-0') cmdlist.append('-0')
cmdlist.extend([">", archive]) cmdlist.extend([">", util.shell_quote(archive)])
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,14 +19,14 @@ from patoolib import util
def extract_gzip (archive, encoding, cmd, **kwargs): def extract_gzip (archive, encoding, cmd, **kwargs):
"""Extract a GZIP archive.""" """Extract a GZIP archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', archive, '>', outfile]) cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})
extract_compress = extract_gzip extract_compress = extract_gzip
@ -50,13 +50,12 @@ test_compress = test_gzip
def create_gzip (archive, encoding, cmd, *args, **kwargs): def create_gzip (archive, encoding, cmd, *args, **kwargs):
"""Create a GZIP archive.""" """Create a GZIP archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.append('-c') cmdlist.append('-c')
cmdlist.append('--') cmdlist.append('--')
cmdlist.extend(args) cmdlist.extend([util.shell_quote(x) for x in args])
cmdlist.extend(['>', archive]) cmdlist.extend(['>', util.shell_quote(archive)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,14 +19,14 @@ from patoolib import util
def extract_lzip (archive, encoding, cmd, **kwargs): def extract_lzip (archive, encoding, cmd, **kwargs):
"""Extract a LZIP archive.""" """Extract a LZIP archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', archive, '>', outfile]) cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})
def test_lzip (archive, encoding, cmd, **kwargs): def test_lzip (archive, encoding, cmd, **kwargs):
"""Test a LZIP archive.""" """Test a LZIP archive."""
@ -38,13 +38,12 @@ def test_lzip (archive, encoding, cmd, **kwargs):
def create_lzip (archive, encoding, cmd, *args, **kwargs): def create_lzip (archive, encoding, cmd, *args, **kwargs):
"""Create a LZIP archive.""" """Create a LZIP archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.append('-c') cmdlist.append('-c')
cmdlist.append('--') cmdlist.append('--')
cmdlist.extend(args) cmdlist.extend([util.shell_quote(x) for x in args])
cmdlist.extend(['>', archive]) cmdlist.extend(['>', util.shell_quote(archive)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,14 +19,14 @@ from patoolib import util
def extract_lzma (archive, encoding, cmd, **kwargs): def extract_lzma (archive, encoding, cmd, **kwargs):
"""Extract a LZMA archive.""" """Extract a LZMA archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', archive, '>', outfile]) cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})
def test_lzma (archive, encoding, cmd, **kwargs): def test_lzma (archive, encoding, cmd, **kwargs):
"""Test a LZMA archive.""" """Test a LZMA archive."""
@ -38,13 +38,12 @@ def test_lzma (archive, encoding, cmd, **kwargs):
def create_lzma (archive, encoding, cmd, *args, **kwargs): def create_lzma (archive, encoding, cmd, *args, **kwargs):
"""Create a LZMA archive.""" """Create a LZMA archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.append('-c') cmdlist.append('-c')
cmdlist.append('--') cmdlist.append('--')
cmdlist.extend(args) cmdlist.extend([util.shell_quote(x) for x in args])
cmdlist.extend(['>', archive]) cmdlist.extend(['>', util.shell_quote(archive)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,14 +19,14 @@ from patoolib import util
def extract_lzop (archive, encoding, cmd, **kwargs): def extract_lzop (archive, encoding, cmd, **kwargs):
"""Extract a LZOP archive.""" """Extract a LZOP archive."""
cmdlist = [cmd, '-c', '-d'] cmdlist = [util.shell_quote(cmd), '-c', '-d']
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('--verbose') cmdlist.append('--verbose')
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['--', archive, '>', outfile]) cmdlist.extend(['--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})
def list_lzop (archive, encoding, cmd, **kwargs): def list_lzop (archive, encoding, cmd, **kwargs):
"""List a LZOP archive.""" """List a LZOP archive."""

View File

@ -18,16 +18,16 @@ import os
from patoolib import util from patoolib import util
def extract_rpm (archive, encoding, cmd, **kwargs): def extract_rpm (archive, encoding, cmd, **kwargs):
"""Extract a DEB archive.""" """Extract a RPM archive."""
# also check cpio # also check cpio
cpio = util.find_program("cpio") cpio = util.find_program("cpio")
if not cpio: if not cpio:
raise util.PatoolError("cpio(1) is required for rpm2cpio extraction; please install it") raise util.PatoolError("cpio(1) is required for rpm2cpio extraction; please install it")
cmdlist = [cmd, os.path.abspath(archive), "|", cpio, '--extract', path = util.shell_quote(os.path.abspath(archive))
'--make-directories', '--preserve-modification-time', cmdlist = [util.shell_quote(cmd), path, "|", util.shell_quote(cpio),
'--extract', '--make-directories', '--preserve-modification-time',
'--no-absolute-filenames', '--force-local', '--nonmatching', '--no-absolute-filenames', '--force-local', '--nonmatching',
'"*\.\.*"'] r'"*\.\.*"']
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'cwd': kwargs['outdir'], 'shell': True})
return (cmd, {'cwd': kwargs['outdir'], 'shell': True})

View File

@ -19,11 +19,11 @@ from patoolib import util
def extract_compress (archive, encoding, cmd, **kwargs): def extract_compress (archive, encoding, cmd, **kwargs):
"""Extract a compressed archive.""" """Extract a compressed archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', archive, '>', outfile]) cmdlist.extend(['-c', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})

View File

@ -19,14 +19,14 @@ from patoolib import util
def extract_xz (archive, encoding, cmd, **kwargs): def extract_xz (archive, encoding, cmd, **kwargs):
"""Extract a XZ archive.""" """Extract a XZ archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive) outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', archive, '>', outfile]) cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})
def test_xz (archive, encoding, cmd, **kwargs): def test_xz (archive, encoding, cmd, **kwargs):
"""Test a XZ archive.""" """Test a XZ archive."""
@ -38,13 +38,12 @@ def test_xz (archive, encoding, cmd, **kwargs):
def create_xz (archive, encoding, cmd, *args, **kwargs): def create_xz (archive, encoding, cmd, *args, **kwargs):
"""Create a XZ archive.""" """Create a XZ archive."""
cmdlist = [cmd] cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']: if kwargs['verbose']:
cmdlist.append('-v') cmdlist.append('-v')
cmdlist.append('-c') cmdlist.append('-c')
cmdlist.append('--') cmdlist.append('--')
cmdlist.extend(args) cmdlist.extend([util.shell_quote(x) for x in args])
cmdlist.extend(['>', archive]) cmdlist.extend(['>', util.shell_quote(archive)])
# note that for shell calls the command must be a string # note that for shell calls the command must be a string
cmd = " ".join([util.shell_quote(x) for x in cmdlist]) return (" ".join(cmdlist), {'shell': True})
return (cmd, {'shell': True})