Python tarfile.PAX_FORMAT Examples
The following are 30
code examples of tarfile.PAX_FORMAT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tarfile
, or try the search function
.
Example #1
Source File: utils.py From anchore-engine with Apache License 2.0 | 6 votes |
def java_prepdb_from_squashtar(unpackdir, squashtar, java_file_regexp): javatmpdir = os.path.join(unpackdir, "javatmp") if not os.path.exists(javatmpdir): try: os.makedirs(javatmpdir) except Exception as err: raise err ret = os.path.join(javatmpdir, "rootfs") javafilepatt = re.compile(java_file_regexp) if not os.path.exists(os.path.join(ret)): with tarfile.open(squashtar, mode='r', format=tarfile.PAX_FORMAT) as tfl: javamembers = [] for member in tfl.getmembers(): filename = member.name if javafilepatt.match(filename): #re.match(java_file_regexp, filename): javamembers.append(member) tfl.extractall(path=os.path.join(javatmpdir, "rootfs"), members=javamembers) ret = os.path.join(javatmpdir, "rootfs") return ret
Example #2
Source File: test_tarfile.py From BinderFilter with MIT License | 6 votes |
def test_unicode_filename_error(self): tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") tarinfo = tarfile.TarInfo() tarinfo.name = "���" if self.format == tarfile.PAX_FORMAT: self.assertRaises(UnicodeError, tar.addfile, tarinfo) else: tar.addfile(tarinfo) tarinfo.name = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo) tarinfo.name = "foo" tarinfo.uname = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo)
Example #3
Source File: test_tarfile.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_unicode_filename_error(self): tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") tarinfo = tarfile.TarInfo() tarinfo.name = "���" if self.format == tarfile.PAX_FORMAT: self.assertRaises(UnicodeError, tar.addfile, tarinfo) else: tar.addfile(tarinfo) tarinfo.name = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo) tarinfo.name = "foo" tarinfo.uname = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo)
Example #4
Source File: utils.py From anchore-engine with Apache License 2.0 | 6 votes |
def rpm_prepdb_from_squashtar(unpackdir, squashtar): rpmtmpdir = os.path.join(unpackdir, "rpmtmp") if not os.path.exists(rpmtmpdir): try: os.makedirs(rpmtmpdir) except Exception as err: raise err ret = os.path.join(rpmtmpdir, "rpmdbfinal") if not os.path.exists(os.path.join(ret, "var", "lib", "rpm")): with tarfile.open(squashtar, mode='r', format=tarfile.PAX_FORMAT) as tfl: rpmmembers = [] for member in tfl.getmembers(): filename = member.name filename = re.sub(r"^\./|^/", "", filename) if filename.startswith("var/lib/rpm"): rpmmembers.append(member) tfl.extractall(path=os.path.join(rpmtmpdir, "rootfs"), members=rpmmembers) rc = rpm_prepdb(rpmtmpdir) ret = os.path.join(rpmtmpdir, "rpmdbfinal") #, "var", "lib", "rpm") return ret
Example #5
Source File: utils.py From anchore-engine with Apache License 2.0 | 6 votes |
def apk_prepdb_from_squashtar(unpackdir, squashtar): apktmpdir = os.path.join(unpackdir, "apktmp") if not os.path.exists(apktmpdir): try: os.makedirs(apktmpdir) except Exception as err: raise err ret = os.path.join(apktmpdir, "rootfs") if not os.path.exists(os.path.join(ret, 'lib', 'apk', 'db', 'installed')): with tarfile.open(squashtar, mode='r', format=tarfile.PAX_FORMAT) as tfl: tarfilenames = tfl.getnames() apkdbfile = _search_tarfilenames_for_file(tarfilenames, "lib/apk/db/installed") apkmembers = [] apkmembers.append(tfl.getmember(apkdbfile)) tfl.extractall(path=os.path.join(apktmpdir, "rootfs"), members=apkmembers) ret = os.path.join(apktmpdir, "rootfs") return ret
Example #6
Source File: test_tarfile.py From BinderFilter with MIT License | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {u"path": u"foo", u"uid": u"123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") t = tarfile.TarInfo() t.name = u"���" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123)
Example #7
Source File: archive.py From bob with GNU General Public License v3.0 | 6 votes |
def _uploadPackage(self, buildId, suffix, audit, content): # Set default signal handler so that KeyboardInterrupt is raised. # Needed to gracefully handle ctrl+c. signal.signal(signal.SIGINT, signal.default_int_handler) try: with self._openUploadFile(buildId, suffix) as (name, fileobj): pax = { 'bob-archive-vsn' : "1" } with gzip.open(name or fileobj, 'wb', 6) as gzf: with tarfile.open(name, "w", fileobj=gzf, format=tarfile.PAX_FORMAT, pax_headers=pax) as tar: tar.add(audit, "meta/" + os.path.basename(audit)) tar.add(content, arcname="content") except ArtifactExistsError: return ("skipped ({} exists in archive)".format(content), SKIPPED) except (ArtifactUploadError, tarfile.TarError, OSError) as e: if self.__ignoreErrors: return ("error ("+str(e)+")", ERROR) else: raise BuildError("Cannot upload artifact: " + str(e)) finally: # Restore signals to default so that Ctrl+C kills process. Needed # to prevent ugly backtraces when user presses ctrl+c. signal.signal(signal.SIGINT, signal.SIG_DFL) return ("ok", EXECUTED)
Example #8
Source File: test_tarfile.py From BinderFilter with MIT License | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) tar.addfile(tarinfo) tar.close() tar = tarfile.open(tmpname) if link: l = tar.getmembers()[0].linkname self.assertTrue(link == l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertTrue(name == n, "PAX longname creation failed")
Example #9
Source File: test_tarfile.py From ironpython2 with Apache License 2.0 | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) try: tar.addfile(tarinfo) finally: tar.close() tar = tarfile.open(tmpname) try: if link: l = tar.getmembers()[0].linkname self.assertTrue(link == l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertTrue(name == n, "PAX longname creation failed") finally: tar.close()
Example #10
Source File: test_tarfile.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) tar.addfile(tarinfo) tar.close() tar = tarfile.open(tmpname) if link: l = tar.getmembers()[0].linkname self.assertTrue(link == l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertTrue(name == n, "PAX longname creation failed")
Example #11
Source File: test_tarfile.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {u"path": u"foo", u"uid": u"123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") try: t = tarfile.TarInfo() t.name = u"\xe4\xf6\xfc" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) finally: tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") try: t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123) finally: tar.close()
Example #12
Source File: test_tarfile.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_unicode_filename_error(self): tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") try: tarinfo = tarfile.TarInfo() tarinfo.name = "\xe4\xf6\xfc" if self.format == tarfile.PAX_FORMAT: self.assertRaises(UnicodeError, tar.addfile, tarinfo) else: tar.addfile(tarinfo) tarinfo.name = u"\xe4\xf6\xfc" self.assertRaises(UnicodeError, tar.addfile, tarinfo) tarinfo.name = "foo" tarinfo.uname = u"\xe4\xf6\xfc" self.assertRaises(UnicodeError, tar.addfile, tarinfo) finally: tar.close()
Example #13
Source File: test_tarfile.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {u"path": u"foo", u"uid": u"123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") t = tarfile.TarInfo() t.name = u"���" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123)
Example #14
Source File: test_tarfile.py From oss-ftp with MIT License | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {u"path": u"foo", u"uid": u"123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") t = tarfile.TarInfo() t.name = u"���" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123)
Example #15
Source File: test_tarfile.py From oss-ftp with MIT License | 6 votes |
def test_unicode_filename_error(self): tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") tarinfo = tarfile.TarInfo() tarinfo.name = "���" if self.format == tarfile.PAX_FORMAT: self.assertRaises(UnicodeError, tar.addfile, tarinfo) else: tar.addfile(tarinfo) tarinfo.name = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo) tarinfo.name = "foo" tarinfo.uname = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo)
Example #16
Source File: utils.py From anchore-engine with Apache License 2.0 | 6 votes |
def run_tarfile_member_function(tarfilename, *args, member_regexp=None, func=_default_member_function, **kwargs): if not os.path.exists(tarfilename): raise ValueError("input tarfile {} not found - exception: {}".format(tarfilename, err)) if member_regexp: memberpatt = re.compile(member_regexp) else: memberpatt = None ret = {} with tarfile.open(tarfilename, mode='r', format=tarfile.PAX_FORMAT) as tfl: memberhash = get_memberhash(tfl) kwargs['memberhash'] = memberhash #for member in tfl.getmembers(): for member in list(memberhash.values()): if not memberpatt or memberpatt.match(member.name): if ret.get(member.name): print("WARN: duplicate member name when preparing return from run_tarfile_member_function() - {}".format(member.name)) ret[member.name] = func(tfl, member, *args, **kwargs) return ret
Example #17
Source File: test_tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) try: tar.addfile(tarinfo) finally: tar.close() tar = tarfile.open(tmpname) try: if link: l = tar.getmembers()[0].linkname self.assertEqual(link, l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertEqual(name, n, "PAX longname creation failed") finally: tar.close()
Example #18
Source File: test_tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {"path": "foo", "uid": "123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") try: t = tarfile.TarInfo() t.name = "\xe4\xf6\xfc" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) finally: tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") try: t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123) finally: tar.close()
Example #19
Source File: anchore_image_db_fs.py From anchore with Apache License 2.0 | 6 votes |
def save_files(self, imageId, namespace, rootfsdir, files): def tarfilter(member): subber = re.sub("^/*", "", rootfsdir) subber = re.sub("/*$", "", subber) finalstr = '/'.join(['imageroot', re.sub("^"+re.escape(subber)+"/*", "", member.name)]) member.name = finalstr return(member) thedir = os.path.join(self.imagerootdir, imageId, "file_store", namespace) if not os.path.exists(thedir): os.makedirs(thedir) tar = tarfile.open('/'.join([thedir, 'stored_files.tar.gz']), mode='w:gz', format=tarfile.PAX_FORMAT) for thefile in files: if os.path.exists(thefile): print "INFO: storing file: " + str(thefile) tar.add(thefile, filter=tarfilter) else: print "WARN: could not find file ("+str(thefile)+") in image: skipping store" tar.close() return(True)
Example #20
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) try: tar.addfile(tarinfo) finally: tar.close() tar = tarfile.open(tmpname) try: if link: l = tar.getmembers()[0].linkname self.assertEqual(link, l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertEqual(name, n, "PAX longname creation failed") finally: tar.close()
Example #21
Source File: test_tarfile.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {"path": "foo", "uid": "123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") try: t = tarfile.TarInfo() t.name = "\xe4\xf6\xfc" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) finally: tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") try: t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123) finally: tar.close()
Example #22
Source File: isolateserver.py From luci-py with Apache License 2.0 | 6 votes |
def content(self): """Generates the tarfile content on the fly.""" obj = _ThreadFile() def _tar_thread(): try: t = tarfile.open( fileobj=obj, mode='w', format=tarfile.PAX_FORMAT, encoding='utf-8') for item in self._items: logging.info(' tarring %s', item.path) t.add(item.path) t.close() except Exception: logging.exception('Internal failure') finally: obj.close() t = threading.Thread(target=_tar_thread) t.start() try: for data in obj: yield data finally: t.join()
Example #23
Source File: test_tarfile.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_unicode_filename_error(self): tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") tarinfo = tarfile.TarInfo() tarinfo.name = "���" if self.format == tarfile.PAX_FORMAT: self.assertRaises(UnicodeError, tar.addfile, tarinfo) else: tar.addfile(tarinfo) tarinfo.name = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo) tarinfo.name = "foo" tarinfo.uname = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo)
Example #24
Source File: test_tarfile.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {u"path": u"foo", u"uid": u"123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") t = tarfile.TarInfo() t.name = u"���" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123)
Example #25
Source File: test_tarfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) tar.addfile(tarinfo) tar.close() tar = tarfile.open(tmpname) if link: l = tar.getmembers()[0].linkname self.assertTrue(link == l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertTrue(name == n, "PAX longname creation failed")
Example #26
Source File: test_tarfile.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) tar.addfile(tarinfo) tar.close() tar = tarfile.open(tmpname) if link: l = tar.getmembers()[0].linkname self.assertTrue(link == l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertTrue(name == n, "PAX longname creation failed")
Example #27
Source File: test_tarfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {u"path": u"foo", u"uid": u"123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") t = tarfile.TarInfo() t.name = u"���" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123)
Example #28
Source File: test_tarfile.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_unicode_filename_error(self): tar = tarfile.open(tmpname, "w", format=self.format, encoding="ascii", errors="strict") tarinfo = tarfile.TarInfo() tarinfo.name = "���" if self.format == tarfile.PAX_FORMAT: self.assertRaises(UnicodeError, tar.addfile, tarinfo) else: tar.addfile(tarinfo) tarinfo.name = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo) tarinfo.name = "foo" tarinfo.uname = u"���" self.assertRaises(UnicodeError, tar.addfile, tarinfo)
Example #29
Source File: test_tarfile.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def _test(self, name, link=None): # See GNUWriteTest. tarinfo = tarfile.TarInfo(name) if link: tarinfo.linkname = link tarinfo.type = tarfile.LNKTYPE tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT) try: tar.addfile(tarinfo) finally: tar.close() tar = tarfile.open(tmpname) try: if link: l = tar.getmembers()[0].linkname self.assertEqual(link, l, "PAX longlink creation failed") else: n = tar.getmembers()[0].name self.assertEqual(name, n, "PAX longname creation failed") finally: tar.close()
Example #30
Source File: test_tarfile.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_pax_extended_header(self): # The fields from the pax header have priority over the # TarInfo. pax_headers = {"path": "foo", "uid": "123"} tar = tarfile.open(tmpname, "w", format=tarfile.PAX_FORMAT, encoding="iso8859-1") try: t = tarfile.TarInfo() t.name = "\xe4\xf6\xfc" # non-ASCII t.uid = 8**8 # too large t.pax_headers = pax_headers tar.addfile(t) finally: tar.close() tar = tarfile.open(tmpname, encoding="iso8859-1") try: t = tar.getmembers()[0] self.assertEqual(t.pax_headers, pax_headers) self.assertEqual(t.name, "foo") self.assertEqual(t.uid, 123) finally: tar.close()