Blame SOURCES/0023-archive-remove-ZipArchive.patch

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