aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2014-12-09 17:46:32 +0000
committerBryn M. Reeves <bmr@redhat.com>2014-12-09 17:46:32 +0000
commitf342d39e714c0d9bf7567028766410a9a71b7ea5 (patch)
tree6a443048aa0a7fc9fe923328dbc6d145d5743ec0
parent081e1ce9f9ad7570d057babd81b474fd407149d7 (diff)
downloadsos-f342d39e714c0d9bf7567028766410a9a71b7ea5.tar.gz
[archive] remove ZipArchive
Remove the ZipArchive class and associated test code. Fixes #322. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/archive.py66
-rw-r--r--tests/archive_tests.py83
-rw-r--r--tests/plugin_tests.py2
3 files changed, 2 insertions, 149 deletions
diff --git a/sos/archive.py b/sos/archive.py
index 0e019bfd..19638981 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -415,70 +415,4 @@ class TarFileArchive(FileCacheArchive):
last_error = e
raise last_error
-
-class ZipFileArchive(Archive):
- """ archive class using python ZipFile to create zip archives """
-
- def __init__(self, name):
- self._name = name
- try:
- import zlib
- assert zlib
- self.compression = zipfile.ZIP_DEFLATED
- except:
- self.compression = zipfile.ZIP_STORED
-
- self.zipfile = zipfile.ZipFile(self.name(), mode="w",
- compression=self.compression)
-
- def name(self):
- return "%s.zip" % self._name
-
- def finalize(self, method):
- super(ZipFileArchive, self).finalize(method)
- return self.name()
-
- def add_file(self, src, dest=None):
- src = str(src)
- if dest:
- dest = str(dest)
-
- if os.path.isdir(src):
- # We may not need, this, but if we do I only want to do it
- # one time
- regex = re.compile(r"^" + src)
- for path, dirnames, filenames in os.walk(src):
- for filename in filenames:
- filename = "/".join((path, filename))
- if dest:
- self.zipfile.write(filename, re.sub(regex, dest,
- filename))
- else:
- self.zipfile.write(filename)
- else:
- if dest:
- self.zipfile.write(src, dest)
- else:
- self.zipfile.write(src)
-
- def add_string(self, content, dest):
- info = zipfile.ZipInfo(dest,
- date_time=time.localtime(time.time()))
- info.compress_type = self.compression
- info.external_attr = 0o400 << long(16)
- self.zipfile.writestr(info, content)
-
- def open_file(self, name):
- try:
- self.zipfile.close()
- self.zipfile = zipfile.ZipFile(self.name(), mode="r")
- file_obj = self.zipfile.open(name)
- return file_obj
- finally:
- self.zipfile.close()
- self.zipfile = zipfile.ZipFile(self.name(), mode="a")
-
- def close(self):
- self.zipfile.close()
-
# vim: et ts=4 sw=4
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
index de4e241f..c778e4e5 100644
--- a/tests/archive_tests.py
+++ b/tests/archive_tests.py
@@ -7,92 +7,11 @@ import zipfile
import tempfile
import shutil
-from sos.archive import TarFileArchive, ZipFileArchive
+from sos.archive import TarFileArchive
# PYCOMPAT
import six
-class ZipFileArchiveTest(unittest.TestCase):
-
- def setUp(self):
- self.zf = ZipFileArchive('test')
-
- def tearDown(self):
- os.unlink('test.zip')
-
- def check_for_file(self, filename):
- zf = zipfile.ZipFile('test.zip', 'r')
- zf.getinfo(filename)
- zf.close()
-
- def test_create(self):
- self.zf.close()
-
- def test_add_file(self):
- self.zf.add_file('tests/ziptest')
- self.zf.close()
-
- self.check_for_file('tests/ziptest')
-
- def test_add_unicode_file(self):
- self.zf.add_file(six.u('tests/'))
- self.zf.close()
-
- self.check_for_file('tests/ziptest')
-
- def test_add_dir(self):
- self.zf.add_file('tests/')
- self.zf.close()
-
- self.check_for_file('tests/ziptest')
-
- def test_add_renamed(self):
- self.zf.add_file('tests/ziptest', dest='tests/ziptest_renamed')
- self.zf.close()
-
- self.check_for_file('tests/ziptest_renamed')
-
- def test_add_renamed_dir(self):
- self.zf.add_file('tests/', 'tests_renamed/')
- self.zf.close()
-
- self.check_for_file('tests_renamed/ziptest')
-
- def test_add_string(self):
- self.zf.add_string('this is content', 'tests/string_test.txt')
- self.zf.close()
-
- self.check_for_file('tests/string_test.txt')
-
- def test_get_file(self):
- self.zf.add_string('this is my content', 'tests/string_test.txt')
-
- afp = self.zf.open_file('tests/string_test.txt')
- self.assertEquals(six.b('this is my content'), afp.read())
-
- def test_overwrite_file(self):
- self.zf.add_string('this is my content', 'tests/string_test.txt')
- self.zf.add_string('this is my new content', 'tests/string_test.txt')
-
- afp = self.zf.open_file('tests/string_test.txt')
- self.assertEquals(six.b('this is my new content'), afp.read())
-
-# Disabled as new api doesnt provide a add_link routine
-# def test_make_link(self):
-# self.zf.add_file('tests/ziptest')
-# self.zf.add_link('tests/ziptest', 'link_name')
-#
-# self.zf.close()
-# try:
-# self.check_for_file('test/link_name')
-# self.fail("link should not exist")
-# except KeyError:
-# pass
-
-# Disabled as new api doesnt provide a compress routine
-# def test_compress(self):
-# self.assertEquals(self.zf.compress("zip"), self.zf.name())
-
class TarFileArchiveTest(unittest.TestCase):
diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py
index f73a003a..7364eff1 100644
--- a/tests/plugin_tests.py
+++ b/tests/plugin_tests.py
@@ -10,7 +10,7 @@ except:
from io import StringIO
from sos.plugins import Plugin, regex_findall, _mangle_command
-from sos.archive import TarFileArchive, ZipFileArchive
+from sos.archive import TarFileArchive
import sos.policies
PATH = os.path.dirname(__file__)