本文整理汇总了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