Use common functions for standard operations on singlefile archives.

This commit is contained in:
Bastian Kleineidam 2010-04-05 13:55:23 +02:00
parent 3c67f6a6a0
commit a1c9ced204
7 changed files with 60 additions and 162 deletions

View File

@ -13,3 +13,36 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from patoolib import util
def extract_singlefile_standard (archive, encoding, cmd, **kwargs):
"""Standard routine to extract a singlefile archive (like gzip)."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
def test_singlefile_standard (archive, encoding, cmd, **kwargs):
"""Standard routine to test a singlefile archive (like gzip)."""
cmdlist = [cmd]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-t', '--', archive])
return cmdlist
def create_singlefile_standard (archive, encoding, cmd, *args, **kwargs):
"""Standard routine to create a singlefile archive (like gzip)."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-c', '--'])
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
return (" ".join(cmdlist), {'shell': True})

View File

@ -15,29 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the bzip2 program."""
from patoolib import util
from patoolib.programs import extract_singlefile_standard, \
test_singlefile_standard
def extract_bzip2 (archive, encoding, cmd, **kwargs):
"""Extract a BZIP2 archive."""
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(['--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
def test_bzip2 (archive, encoding, cmd, **kwargs):
"""Test a BZIP2 archive."""
cmdlist = [cmd]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-t', '--', archive])
return cmdlist
extract_bzip2 = extract_singlefile_standard
test_bzip2 = test_singlefile_standard
def create_bzip2 (archive, encoding, cmd, *args, **kwargs):
"""Create a BZIP2 archive."""

View File

@ -14,21 +14,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the gzip program."""
from patoolib import util
from patoolib.programs import extract_singlefile_standard, \
test_singlefile_standard, create_singlefile_standard
def extract_gzip (archive, encoding, cmd, **kwargs):
"""Extract a GZIP archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
extract_compress = extract_gzip
extract_gzip = extract_compress = extract_singlefile_standard
test_gzip = test_compress = test_singlefile_standard
create_gzip = create_singlefile_standard
def list_gzip (archive, encoding, cmd, **kwargs):
"""List a GZIP archive."""
@ -37,25 +28,3 @@ def list_gzip (archive, encoding, cmd, **kwargs):
cmdlist.append('-v')
cmdlist.extend(['-l', '--', archive])
return cmdlist
def test_gzip (archive, encoding, cmd, **kwargs):
"""Test a GZIP archive."""
cmdlist = [cmd]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-t', '--', archive])
return cmdlist
test_compress = test_gzip
def create_gzip (archive, encoding, cmd, *args, **kwargs):
"""Create a GZIP archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.append('-c')
cmdlist.append('--')
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
return (" ".join(cmdlist), {'shell': True})

View File

@ -14,36 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the lzip program."""
from patoolib import util
from patoolib.programs import extract_singlefile_standard, \
test_singlefile_standard, create_singlefile_standard
def extract_lzip (archive, encoding, cmd, **kwargs):
"""Extract a LZIP archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
def test_lzip (archive, encoding, cmd, **kwargs):
"""Test a LZIP archive."""
cmdlist = [cmd]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-t', '--', archive])
return cmdlist
def create_lzip (archive, encoding, cmd, *args, **kwargs):
"""Create a LZIP archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.append('-c')
cmdlist.append('--')
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
return (" ".join(cmdlist), {'shell': True})
extract_lzip = extract_singlefile_standard
test_lzip = test_singlefile_standard
create_lzip = create_singlefile_standard

View File

@ -14,36 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the lzma program."""
from patoolib import util
from patoolib.programs import extract_singlefile_standard, \
test_singlefile_standard, create_singlefile_standard
def extract_lzma (archive, encoding, cmd, **kwargs):
"""Extract a LZMA archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
def test_lzma (archive, encoding, cmd, **kwargs):
"""Test a LZMA archive."""
cmdlist = [cmd]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-t', '--', archive])
return cmdlist
def create_lzma (archive, encoding, cmd, *args, **kwargs):
"""Create a LZMA archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.append('-c')
cmdlist.append('--')
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
return (" ".join(cmdlist), {'shell': True})
extract_lzma = extract_singlefile_standard
test_lzma = test_singlefile_standard
create_lzma = create_singlefile_standard

View File

@ -14,19 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the lzop program."""
from patoolib import util
from patoolib.programs import extract_singlefile_standard
def extract_lzop (archive, encoding, cmd, **kwargs):
"""Extract a LZOP archive."""
cmdlist = [util.shell_quote(cmd), '-c', '-d']
if kwargs['verbose']:
cmdlist.append('--verbose')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
extract_lzop = extract_singlefile_standard
def list_lzop (archive, encoding, cmd, **kwargs):
"""List a LZOP archive."""

View File

@ -14,36 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Archive commands for the xz program."""
from patoolib import util
from patoolib.programs import extract_singlefile_standard, \
test_singlefile_standard, create_singlefile_standard
def extract_xz (archive, encoding, cmd, **kwargs):
"""Extract a XZ archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
outfile = util.get_single_outfile(kwargs['outdir'], archive)
cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
util.shell_quote(outfile)])
# note that for shell calls the command must be a string
return (" ".join(cmdlist), {'shell': True})
def test_xz (archive, encoding, cmd, **kwargs):
"""Test a XZ archive."""
cmdlist = [cmd]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.extend(['-t', '--', archive])
return cmdlist
def create_xz (archive, encoding, cmd, *args, **kwargs):
"""Create a XZ archive."""
cmdlist = [util.shell_quote(cmd)]
if kwargs['verbose']:
cmdlist.append('-v')
cmdlist.append('-c')
cmdlist.append('--')
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
return (" ".join(cmdlist), {'shell': True})
extract_xz = extract_singlefile_standard
test_xz = test_singlefile_standard
create_xz = create_singlefile_standard