def _set_archive(self): if self.opts.compression_type not in ('auto', 'zip', 'bzip2', 'gzip', 'xz'): raise Exception("Invalid compression type specified. Options are: auto, zip, bzip2, gzip and xz") archive_name = os.path.join(self.opts.tmp_dir,self.policy.get_archive_name()) if self.opts.compression_type == 'auto': auto_archive = self.policy.preferred_archive_name() self.archive = auto_archive(archive_name) elif self.opts.compression_type == 'zip': self.archive = ZipFileArchive(archive_name) else: self.archive = TarFileArchive(archive_name)
def _set_archive(self): archive_name = os.path.join(self.tmpdir, self.policy.get_archive_name()) if self.opts.compression_type == 'auto': auto_archive = self.policy.get_preferred_archive() self.archive = auto_archive(archive_name, self.tmpdir) elif self.opts.compression_type == 'zip': self.archive = ZipFileArchive(archive_name, self.tmpdir) else: self.archive = TarFileArchive(archive_name, self.tmpdir) self.archive.set_debug(True if self.opts.debug else False)
def setUp(self): self.zf = ZipFileArchive('test')
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(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())
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('test/tests/ziptest') def test_add_unicode_file(self): self.zf.add_file(u'tests/') self.zf.close() self.check_for_file('test/tests/ziptest') def test_add_dir(self): self.zf.add_file('tests/') self.zf.close() self.check_for_file('test/tests/ziptest') def test_add_renamed(self): self.zf.add_file('tests/ziptest', dest='tests/ziptest_renamed') self.zf.close() self.check_for_file('test/tests/ziptest_renamed') def test_add_renamed_dir(self): self.zf.add_file('tests/', 'tests_renamed/') self.zf.close() self.check_for_file('test/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('test/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('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('this is my new content', afp.read()) 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 def test_compress(self): self.assertEquals(self.zf.compress("zip"), self.zf.name())
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(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('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('this is my new content', afp.read())