def test_write_mode(self): self.a.close() a = arfile.ArFile(self.a.name, mode='w') self.assertEqual(a.getmembers(), []) a.add('test_debfile.py') a2 = arfile.ArFile(self.a.name, mode='r') m2 = a2.getmember('test_debfile.py') a3 = arfile.ArFile('test2.ar', mode='w') a3.add('test_debfile.py') a3.close() a4 = arfile.ArFile('test2.ar', mode='r') self.assertEqual(len(a4.getmembers()), 1)
def setUp(self): os.system( "ar r test.ar test_debfile.py test_changelog test_deb822.py >/dev/null 2>&1" ) assert os.path.exists("test.ar") with os.popen("ar t test.ar") as ar: self.testmembers = [x.strip() for x in ar.readlines()] self.a = arfile.ArFile("test.ar")
def test_adding(self): self.a.add('test_debfile.py') m = self.a.getmember('test_debfile.py') self.assertEqual(m.name, 'test_debfile.py') self.assertEqual(self.a.getmembers()[-1], m) self.a2 = arfile.ArFile('test.ar', mode='r') m2 = self.a2.getmember('test_debfile.py')
def test_long_filenames(self): self.assertEqual(len(self.a.getmembers()), 3) # test presence of a file with long filename self.assertEqual( self.a.getmember('test_debian_support.py').name, 'test_debian_support.py') m = self.a.getmember('test_debian_support.py') f = open('test_debian_support.py', 'rb') self.assertEqual(m.read(), f.read()) f.close() self.a.close() a = arfile.ArFile(self.a.name, mode='w') a.add('test_debian_support.py') a2 = arfile.ArFile(self.a.name, mode='r') self.assertEqual(len(a2.getmembers()), 1)
def extract_deb_data(archive, extract_dir): """Extract archive to extract_dir.""" # We may not have python-debian installed on all platforms from debian import arfile # suppress(import-error) data_members = ["data.tar.gz", "data.tar.xz"] for data_mem in data_members: try: with closing(arfile.ArFile(archive).getmember(data_mem)) as member: with tarfile.open(fileobj=member, mode="r|*") as data_tar: data_tar.extractall(path=extract_dir) # Succeeded, break out here break except KeyError as error: if str(error) == "'{}'".format(data_mem): continue else: raise error
def setUp(self): os.system( "bsdtar -c --format ar -f testlong.ar test_debian_support.py test_deb822.py test_changelog_full_stops >/dev/null 2>&1" ) assert os.path.exists("testlong.ar") self.a = arfile.ArFile("testlong.ar", mode='a')