Exemplo n.º 1
0
    def test_bz2_add_fo(self):
        marfile = os.path.join(self.tmpdir, 'test.mar')
        with BZ2MarFile(None, fileobj=open(marfile, "wb")) as m:
            m.add(__file__)

        with BZ2MarFile(None, fileobj=open(marfile, "rb")) as m:
            self.assertEquals(len(m.members), 1)
            extracted = m.extract(m.members[0], self.tmpdir)
            self.assertEquals(
                open(extracted, 'rb').read(),
                open(__file__, 'rb').read())
Exemplo n.º 2
0
    def test_bz2_add_dir_fo(self):
        marfile = os.path.join(self.tmpdir, 'test.mar')
        dirname = os.path.dirname(__file__)
        with BZ2MarFile(None, fileobj=open(marfile, "wb")) as m:
            m.add(dirname)

        # List out the files in dirname so we can compare
        my_files = []
        for root, dirs, files in os.walk(dirname):
            for f in files:
                my_files.append(os.path.join(root, f))

        with BZ2MarFile(None, fileobj=open(marfile, "rb")) as m:
            self.assertEquals(len(m.members), len(my_files))
            for member in m.members:
                self.assertTrue(member.name in my_files)
                self.assertEquals(member.flags,
                                  os.stat(member.name).st_mode & 0o777)

                extracted = m.extract(member, self.tmpdir)
                self.assertNotEquals(extracted, member.name)
                self.assertEquals(
                    open(extracted, 'rb').read(),
                    open(member.name, 'rb').read())
Exemplo n.º 3
0
def extractMar(filename, tempdir):
    m = BZ2MarFile(filename)
    m.extractall(path=tempdir)
Exemplo n.º 4
0
 def test_list_fo_bz(self):
     self.check_list(BZ2MarFile(None, fileobj=open(TEST_MAR, 'rb')))
Exemplo n.º 5
0
 def test_list_name_bz(self):
     self.check_list(BZ2MarFile(TEST_MAR))
Exemplo n.º 6
0
 def test_extract_bz2_fo(self):
     self.check_extract_bz2(BZ2MarFile(None, fileobj=open(TEST_MAR, "rb")))
Exemplo n.º 7
0
 def test_extract_bz2(self):
     self.check_extract_bz2(BZ2MarFile(TEST_MAR))