From 9cfc1b1e6180a2d90ca61a6cbba1c660e9c22111 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Mon, 15 Nov 2010 21:29:51 +0100 Subject: [PATCH] Remove duplicate code. --- patoolib/programs/p7azip.py | 86 +++++++++++-------------------------- patoolib/programs/unrar.py | 27 +----------- 2 files changed, 25 insertions(+), 88 deletions(-) diff --git a/patoolib/programs/p7azip.py b/patoolib/programs/p7azip.py index 19db07b..554d1da 100644 --- a/patoolib/programs/p7azip.py +++ b/patoolib/programs/p7azip.py @@ -20,65 +20,27 @@ From the man page: but does not need any others. """ -def extract_7z (archive, encoding, cmd, **kwargs): - """Extract a 7z archive.""" - cmdlist = [cmd, 'x'] - if not kwargs['verbose']: - cmdlist.append('-bd') - cmdlist.extend(['-o%s' % kwargs['outdir'], '--', archive]) - return cmdlist - -extract_bzip2 = \ - extract_gzip = \ - extract_zip = \ - extract_compress = \ - extract_rar = \ - extract_cab = \ - extract_7z - -def list_7z (archive, encoding, cmd, **kwargs): - """List a 7z archive.""" - cmdlist = [cmd, 'l'] - if not kwargs['verbose']: - cmdlist.append('-bd') - cmdlist.append('--') - cmdlist.append(archive) - return cmdlist - -list_bzip2 = \ - list_gzip = \ - list_zip = \ - list_compress = \ - list_rar = \ - list_cab = \ - list_rpm = \ - list_7z - - -def test_7z (archive, encoding, cmd, **kwargs): - """Test a 7z archive.""" - cmdlist = [cmd, 't'] - if not kwargs['verbose']: - cmdlist.append('-bd') - cmdlist.append('--') - cmdlist.append(archive) - return cmdlist - -test_bzip2 = \ - test_gzip = \ - test_zip = \ - test_compress = \ - test_rar = \ - test_cab = \ - test_7z - - -def create_7z (archive, encoding, cmd, *args, **kwargs): - """Create a 7z archive.""" - cmdlist = [cmd, 'a'] - if not kwargs['verbose']: - cmdlist.append('-bd') - cmdlist.append('--') - cmdlist.append(archive) - cmdlist.extend(args) - return cmdlist +from .p7zip import \ + extract_bzip2, \ + extract_gzip, \ + extract_zip, \ + extract_compress, \ + extract_rar, \ + extract_cab, \ + extract_7z, \ + list_bzip2, \ + list_gzip, \ + list_zip, \ + list_compress, \ + list_rar, \ + list_cab, \ + list_rpm, \ + list_7z, \ + test_bzip2, \ + test_gzip, \ + test_zip, \ + test_compress, \ + test_rar, \ + test_cab, \ + test_7z, \ + create_7z diff --git a/patoolib/programs/unrar.py b/patoolib/programs/unrar.py index 4d93511..8cf2d5b 100644 --- a/patoolib/programs/unrar.py +++ b/patoolib/programs/unrar.py @@ -15,29 +15,4 @@ # along with this program. If not, see . """Archive commands for the unrar program.""" -def extract_rar (archive, encoding, cmd, **kwargs): - """Extract a RAR archive.""" - cmdlist = [cmd, 'x'] - if not kwargs['verbose']: - cmdlist.append('-c-') - cmdlist.extend(['-r', '--', archive, kwargs['outdir']]) - return cmdlist - -def list_rar (archive, encoding, cmd, **kwargs): - """List a RAR archive.""" - cmdlist = [cmd] - if kwargs['verbose']: - cmdlist.append('v') - else: - cmdlist.append('l') - cmdlist.append('-c-') - cmdlist.extend(['--', archive]) - return cmdlist - -def test_rar (archive, encoding, cmd, **kwargs): - """Test a RAR archive.""" - cmdlist = [cmd, 't'] - if not kwargs['verbose']: - cmdlist.append('-c-') - cmdlist.extend(['--', archive]) - return cmdlist +from .rar import extract_rar, list_rar, test_rar