diff --git a/patoolib/programs/__init__.py b/patoolib/programs/__init__.py
index 27a8694..d03824d 100644
--- a/patoolib/programs/__init__.py
+++ b/patoolib/programs/__init__.py
@@ -13,3 +13,36 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
+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})
diff --git a/patoolib/programs/bzip2.py b/patoolib/programs/bzip2.py
index 2b24dac..1b61c87 100644
--- a/patoolib/programs/bzip2.py
+++ b/patoolib/programs/bzip2.py
@@ -15,29 +15,11 @@
# along with this program. If not, see .
"""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."""
diff --git a/patoolib/programs/gzip.py b/patoolib/programs/gzip.py
index 056be3f..32e0624 100644
--- a/patoolib/programs/gzip.py
+++ b/patoolib/programs/gzip.py
@@ -14,21 +14,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""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})
diff --git a/patoolib/programs/lzip.py b/patoolib/programs/lzip.py
index af5f8e7..28fec36 100644
--- a/patoolib/programs/lzip.py
+++ b/patoolib/programs/lzip.py
@@ -14,36 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""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
diff --git a/patoolib/programs/lzma.py b/patoolib/programs/lzma.py
index ede4f44..fc4f008 100644
--- a/patoolib/programs/lzma.py
+++ b/patoolib/programs/lzma.py
@@ -14,36 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""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
diff --git a/patoolib/programs/lzop.py b/patoolib/programs/lzop.py
index 46d7449..73745c5 100644
--- a/patoolib/programs/lzop.py
+++ b/patoolib/programs/lzop.py
@@ -14,19 +14,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""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."""
diff --git a/patoolib/programs/xz.py b/patoolib/programs/xz.py
index 4022e34..ed01282 100644
--- a/patoolib/programs/xz.py
+++ b/patoolib/programs/xz.py
@@ -14,36 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
"""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