From 8cbef81a506e527bfc52e02c92330e73a82d73ff Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sun, 4 Apr 2010 19:12:24 +0200 Subject: [PATCH] Only quote commandline arguments that need quoting. --- patoolib/programs/bzip2.py | 17 ++++++++--------- patoolib/programs/compress.py | 9 ++++----- patoolib/programs/cpio.py | 18 ++++++++---------- patoolib/programs/gzip.py | 17 ++++++++--------- patoolib/programs/lzip.py | 17 ++++++++--------- patoolib/programs/lzma.py | 17 ++++++++--------- patoolib/programs/lzop.py | 8 ++++---- patoolib/programs/rpm2cpio.py | 12 ++++++------ patoolib/programs/uncompress.py | 8 ++++---- patoolib/programs/xz.py | 17 ++++++++--------- 10 files changed, 66 insertions(+), 74 deletions(-) diff --git a/patoolib/programs/bzip2.py b/patoolib/programs/bzip2.py index ee889ab..2b24dac 100644 --- a/patoolib/programs/bzip2.py +++ b/patoolib/programs/bzip2.py @@ -19,15 +19,15 @@ from patoolib import util def extract_bzip2 (archive, encoding, cmd, **kwargs): """Extract a BZIP2 archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.extend(['-c', '-d']) 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) 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): """Create a BZIP2 archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.extend(['-c', '-z', '--']) - cmdlist.extend(args) - cmdlist.extend(['>', archive]) + cmdlist.extend([util.shell_quote(x) for x in args]) + cmdlist.extend(['>', util.shell_quote(archive)]) # note that for shell calls the command must be a string - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/compress.py b/patoolib/programs/compress.py index db4f0c7..8fa0515 100644 --- a/patoolib/programs/compress.py +++ b/patoolib/programs/compress.py @@ -19,12 +19,11 @@ from patoolib import util def create_compress (archive, encoding, cmd, *args, **kwargs): """Create a compressed archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.append('-c') - cmdlist.extend(args) - cmdlist.extend(['>', archive]) + cmdlist.extend([util.shell_quote(x) for x in args]) + cmdlist.extend(['>', util.shell_quote(archive)]) # note that for shell calls the command must be a string - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/cpio.py b/patoolib/programs/cpio.py index 8362dcf..0eb036b 100644 --- a/patoolib/programs/cpio.py +++ b/patoolib/programs/cpio.py @@ -19,14 +19,13 @@ from patoolib import util def extract_cpio (archive, encoding, cmd, **kwargs): """Extract a CPIO archive.""" - cmdlist = [cmd, '--extract', '--make-directories', + cmdlist = [util.shell_quote(cmd), '--extract', '--make-directories', '--preserve-modification-time', '--no-absolute-filenames', - '--force-local', '--nonmatching', '"*\.\.*"'] + '--force-local', '--nonmatching', r'"*\.\.*"'] if kwargs['verbose']: cmdlist.append('-v') - cmdlist.extend(['<', os.path.abspath(archive)]) - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'cwd': kwargs['outdir'], 'shell': True}) + cmdlist.extend(['<', util.shell_quote(os.path.abspath(archive))]) + return (" ".join(cmdlist), {'cwd': kwargs['outdir'], 'shell': True}) def list_cpio (archive, encoding, cmd, **kwargs): @@ -41,15 +40,14 @@ test_cpio = list_cpio def create_cpio(archive, encoding, cmd, *args, **kwargs): """Create a CPIO archive.""" - cmdlist = [cmd, '--create'] + cmdlist = [util.shell_quote(cmd), '--create'] if kwargs['verbose']: cmdlist.append('-v') if len(args) != 0: findcmd = ['find', '-print0'] - findcmd.extend(args) + findcmd.extend([util.shell_quote(x) for x in args]) findcmd.append('|') cmdlist[0:0] = findcmd cmdlist.append('-0') - cmdlist.extend([">", archive]) - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + cmdlist.extend([">", util.shell_quote(archive)]) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/gzip.py b/patoolib/programs/gzip.py index 10683f6..056be3f 100644 --- a/patoolib/programs/gzip.py +++ b/patoolib/programs/gzip.py @@ -19,14 +19,14 @@ from patoolib import util def extract_gzip (archive, encoding, cmd, **kwargs): """Extract a GZIP archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) extract_compress = extract_gzip @@ -50,13 +50,12 @@ test_compress = test_gzip def create_gzip (archive, encoding, cmd, *args, **kwargs): """Create a GZIP archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.append('-c') cmdlist.append('--') - cmdlist.extend(args) - cmdlist.extend(['>', archive]) + cmdlist.extend([util.shell_quote(x) for x in args]) + cmdlist.extend(['>', util.shell_quote(archive)]) # note that for shell calls the command must be a string - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/lzip.py b/patoolib/programs/lzip.py index 1227096..af5f8e7 100644 --- a/patoolib/programs/lzip.py +++ b/patoolib/programs/lzip.py @@ -19,14 +19,14 @@ from patoolib import util def extract_lzip (archive, encoding, cmd, **kwargs): """Extract a LZIP archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) def test_lzip (archive, encoding, cmd, **kwargs): """Test a LZIP archive.""" @@ -38,13 +38,12 @@ def test_lzip (archive, encoding, cmd, **kwargs): def create_lzip (archive, encoding, cmd, *args, **kwargs): """Create a LZIP archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.append('-c') cmdlist.append('--') - cmdlist.extend(args) - cmdlist.extend(['>', archive]) + cmdlist.extend([util.shell_quote(x) for x in args]) + cmdlist.extend(['>', util.shell_quote(archive)]) # note that for shell calls the command must be a string - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/lzma.py b/patoolib/programs/lzma.py index 006aaa9..ede4f44 100644 --- a/patoolib/programs/lzma.py +++ b/patoolib/programs/lzma.py @@ -19,14 +19,14 @@ from patoolib import util def extract_lzma (archive, encoding, cmd, **kwargs): """Extract a LZMA archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) def test_lzma (archive, encoding, cmd, **kwargs): """Test a LZMA archive.""" @@ -38,13 +38,12 @@ def test_lzma (archive, encoding, cmd, **kwargs): def create_lzma (archive, encoding, cmd, *args, **kwargs): """Create a LZMA archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.append('-c') cmdlist.append('--') - cmdlist.extend(args) - cmdlist.extend(['>', archive]) + cmdlist.extend([util.shell_quote(x) for x in args]) + cmdlist.extend(['>', util.shell_quote(archive)]) # note that for shell calls the command must be a string - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/lzop.py b/patoolib/programs/lzop.py index 3542d88..46d7449 100644 --- a/patoolib/programs/lzop.py +++ b/patoolib/programs/lzop.py @@ -19,14 +19,14 @@ from patoolib import util def extract_lzop (archive, encoding, cmd, **kwargs): """Extract a LZOP archive.""" - cmdlist = [cmd, '-c', '-d'] + cmdlist = [util.shell_quote(cmd), '-c', '-d'] if kwargs['verbose']: cmdlist.append('--verbose') 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) def list_lzop (archive, encoding, cmd, **kwargs): """List a LZOP archive.""" diff --git a/patoolib/programs/rpm2cpio.py b/patoolib/programs/rpm2cpio.py index e66482d..2ff289f 100644 --- a/patoolib/programs/rpm2cpio.py +++ b/patoolib/programs/rpm2cpio.py @@ -18,16 +18,16 @@ import os from patoolib import util def extract_rpm (archive, encoding, cmd, **kwargs): - """Extract a DEB archive.""" + """Extract a RPM archive.""" # also check cpio cpio = util.find_program("cpio") if not cpio: raise util.PatoolError("cpio(1) is required for rpm2cpio extraction; please install it") - cmdlist = [cmd, os.path.abspath(archive), "|", cpio, '--extract', - '--make-directories', '--preserve-modification-time', + path = util.shell_quote(os.path.abspath(archive)) + cmdlist = [util.shell_quote(cmd), path, "|", util.shell_quote(cpio), + '--extract', '--make-directories', '--preserve-modification-time', '--no-absolute-filenames', '--force-local', '--nonmatching', - '"*\.\.*"'] + r'"*\.\.*"'] if kwargs['verbose']: cmdlist.append('-v') - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'cwd': kwargs['outdir'], 'shell': True}) + return (" ".join(cmdlist), {'cwd': kwargs['outdir'], 'shell': True}) diff --git a/patoolib/programs/uncompress.py b/patoolib/programs/uncompress.py index 1cfc2ac..e552f53 100644 --- a/patoolib/programs/uncompress.py +++ b/patoolib/programs/uncompress.py @@ -19,11 +19,11 @@ from patoolib import util def extract_compress (archive, encoding, cmd, **kwargs): """Extract a compressed archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) diff --git a/patoolib/programs/xz.py b/patoolib/programs/xz.py index bfbab57..4022e34 100644 --- a/patoolib/programs/xz.py +++ b/patoolib/programs/xz.py @@ -19,14 +19,14 @@ from patoolib import util def extract_xz (archive, encoding, cmd, **kwargs): """Extract a XZ archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') 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 - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True}) def test_xz (archive, encoding, cmd, **kwargs): """Test a XZ archive.""" @@ -38,13 +38,12 @@ def test_xz (archive, encoding, cmd, **kwargs): def create_xz (archive, encoding, cmd, *args, **kwargs): """Create a XZ archive.""" - cmdlist = [cmd] + cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') cmdlist.append('-c') cmdlist.append('--') - cmdlist.extend(args) - cmdlist.extend(['>', archive]) + cmdlist.extend([util.shell_quote(x) for x in args]) + cmdlist.extend(['>', util.shell_quote(archive)]) # note that for shell calls the command must be a string - cmd = " ".join([util.shell_quote(x) for x in cmdlist]) - return (cmd, {'shell': True}) + return (" ".join(cmdlist), {'shell': True})