本文整理匯總了Python中tarfile.PAX_FORMAT屬性的典型用法代碼示例。如果您正苦於以下問題:Python tarfile.PAX_FORMAT屬性的具體用法?Python tarfile.PAX_FORMAT怎麽用?Python tarfile.PAX_FORMAT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類tarfile
的用法示例。
在下文中一共展示了tarfile.PAX_FORMAT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _uploadPackage
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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)
示例2: _test
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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()
示例3: test_pax_extended_header
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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()
示例4: test_unicode_filename_error
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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()
示例5: _test
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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")
示例6: test_pax_extended_header
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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)
示例7: test_unicode_filename_error
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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)
示例8: _test
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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()
示例9: test_pax_extended_header
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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()
示例10: content
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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()
示例11: save_files
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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)
示例12: run_tarfile_member_function
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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
示例13: java_prepdb_from_squashtar
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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
示例14: apk_prepdb_from_squashtar
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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
示例15: rpm_prepdb_from_squashtar
# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import PAX_FORMAT [as 別名]
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