1
0
mirror of https://github.com/gryf/fs-uae-wrapper.git synced 2025-12-20 04:48:02 +01:00

Removed archive from utils

This commit is contained in:
2017-01-02 10:00:35 +01:00
parent 989c268b56
commit ab71e270d8
2 changed files with 13 additions and 35 deletions

View File

@@ -11,18 +11,7 @@ except ImportError:
import ConfigParser as configparser import ConfigParser as configparser
from fs_uae_wrapper import message from fs_uae_wrapper import message
from fs_uae_wrapper import file_archive
ARCHIVERS = {'.tar': ['tar', 'xf'],
'.tgz': ['tar', 'xf'],
'.tar.gz': ['tar', 'xf'],
'.tar.bz2': ['tar', 'xf'],
'.tar.xz': ['tar', 'xf'],
'.rar': ['unrar', 'x'],
'.7z': ['7z', 'x'],
'.zip': ['7z', 'x'],
'.lha': ['lha', 'x'],
'.lzx': ['unlzx']}
class CmdOption(dict): class CmdOption(dict):
@@ -73,16 +62,11 @@ def extract_archive(arch_name, title=''):
Extract provided archive to current directory Extract provided archive to current directory
""" """
if not os.path.exists(arch_name): archiver = file_archive.get_archiver(arch_name)
sys.stderr.write("Archive `%s' doesn't exists.\n" % arch_name)
return False
_, ext = os.path.splitext(arch_name) if archiver is None:
sys.stderr.write("Unable find archive type for `%s' or executable "
cmd = ARCHIVERS.get(ext) "doesn't exists.\n" % arch_name)
if cmd is None:
sys.stderr.write("Unable find archive type for `%s'.\n" % arch_name)
return False return False
msg = message.Message("Extracting files for `%s'. Please be " msg = message.Message("Extracting files for `%s'. Please be "
@@ -90,18 +74,13 @@ def extract_archive(arch_name, title=''):
if title: if title:
msg.show() msg.show()
try: res = archiver.extract(arch_name)
subprocess.check_call(cmd + [arch_name])
except OSError:
sys.stderr.write("Error executing `%s'.\n" % cmd)
msg.close()
return False
except subprocess.CalledProcessError:
sys.stderr.write("Error during extracting archive `%s'.\n" % arch_name)
msg.close() msg.close()
if not res:
sys.stderr.write("Error extracting `%s'.\n" % arch_name)
return False return False
msg.close()
return True return True

View File

@@ -91,8 +91,8 @@ class TestUtils(TestCase):
fobj.write("\n") fobj.write("\n")
self.assertFalse(utils.extract_archive('supported-archive.7z')) self.assertFalse(utils.extract_archive('supported-archive.7z'))
@mock.patch('subprocess.check_call') @mock.patch('fs_uae_wrapper.file_archive.Archive.extract')
def test_extract_archive_positive(self, sp_check_call): def test_extract_archive_positive(self, arch_extract):
os.chdir(self.dirname) os.chdir(self.dirname)
# archive is known, and extraction should succeed # archive is known, and extraction should succeed
@@ -100,8 +100,7 @@ class TestUtils(TestCase):
with open(arch_name, 'w') as fobj: with open(arch_name, 'w') as fobj:
fobj.write("\n") fobj.write("\n")
self.assertTrue(utils.extract_archive(arch_name)) self.assertTrue(utils.extract_archive(arch_name))
sp_check_call.assert_called_once_with(utils.ARCHIVERS['.7z'] + arch_extract.assert_called_once_with(arch_name)
[arch_name])
def test_merge_all_options(self): def test_merge_all_options(self):