當前位置: 首頁>>代碼示例>>Python>>正文


Python tarfile.PAX_FORMAT屬性代碼示例

本文整理匯總了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) 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:27,代碼來源:archive.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_tarfile.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_tarfile.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_tarfile.py

示例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") 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:20,代碼來源:test_tarfile.py

示例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) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:20,代碼來源:test_tarfile.py

示例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) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:18,代碼來源:test_tarfile.py

示例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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,代碼來源:test_tarfile.py

示例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() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:26,代碼來源:test_tarfile.py

示例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() 
開發者ID:luci,項目名稱:luci-py,代碼行數:25,代碼來源:isolateserver.py

示例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) 
開發者ID:anchore,項目名稱:anchore,代碼行數:23,代碼來源:anchore_image_db_fs.py

示例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 
開發者ID:anchore,項目名稱:anchore-engine,代碼行數:24,代碼來源:utils.py

示例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 
開發者ID:anchore,項目名稱:anchore-engine,代碼行數:25,代碼來源:utils.py

示例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 
開發者ID:anchore,項目名稱:anchore-engine,代碼行數:23,代碼來源:utils.py

示例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 
開發者ID:anchore,項目名稱:anchore-engine,代碼行數:27,代碼來源:utils.py


注:本文中的tarfile.PAX_FORMAT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。