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


Python tarfile.DIRTYPE屬性代碼示例

本文整理匯總了Python中tarfile.DIRTYPE屬性的典型用法代碼示例。如果您正苦於以下問題:Python tarfile.DIRTYPE屬性的具體用法?Python tarfile.DIRTYPE怎麽用?Python tarfile.DIRTYPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在tarfile的用法示例。


在下文中一共展示了tarfile.DIRTYPE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _make_test_archive

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def _make_test_archive(filename_1, dirname_1, filename_2):
        # the file contents to write
        fobj = io.BytesIO(b"content")

        # create a tar file with a file, a directory, and a file within that
        #  directory. Assign various .uid/.gid values to them
        items = [(filename_1, 99, 98, tarfile.REGTYPE, fobj),
                 (dirname_1,  77, 76, tarfile.DIRTYPE, None),
                 (filename_2, 88, 87, tarfile.REGTYPE, fobj),
                 ]
        with tarfile.open(tmpname, 'w') as tarfl:
            for name, uid, gid, typ, contents in items:
                t = tarfile.TarInfo(name)
                t.uid = uid
                t.gid = gid
                t.uname = 'root'
                t.gname = 'root'
                t.type = typ
                tarfl.addfile(t, contents)

        # return the full pathname to the tar file
        return tmpname 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_tarfile.py

示例2: export_files_with_tar

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def export_files_with_tar(output_name, list_of_files, output_path="./"):
        if not output_name.endswith(".tar.gz"):
            output_name = output_name + ".tar.gz"
        tar = tarfile.open(output_path + output_name, "w:gz")
        for _file in list_of_files:
            try:
                logger.info("File {0} is added to {1}".format(_file, output_name))
                if len(_file) == 2:
                    # Create file
                    tar.add(_file[0], _file[1])
                else:
                    # Create directory
                    t = tarfile.TarInfo(_file[0])
                    t.type = tarfile.DIRTYPE
                    tar.addfile(t)
            except RuntimeError as _:
                logger.error("Error has occurred while compressing file {0}".format(_file[0]))
        tar.close() 
開發者ID:yakuza8,項目名稱:peniot,代碼行數:20,代碼來源:export_util.py

示例3: create_user_dirs

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def create_user_dirs(self, tar_handle):
        """
        Create root file system tree in tar archive.
        """
        tar_members = [
            ['dirs', tarfile.DIRTYPE],
            ['files', tarfile.REGTYPE],
        ]

        for user in self.rootfs_tree:
            for members, tar_type in tar_members:
                self.create_tar_members(
                    tar_handle,
                    self.rootfs_tree[user][members],
                    tar_type,
                    uid=self.rootfs_tree[user]['uid'],
                    gid=self.rootfs_tree[user]['gid']
                ) 
開發者ID:virt-manager,項目名稱:virt-bootstrap,代碼行數:20,代碼來源:__init__.py

示例4: test_v7_dirtype

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def test_v7_dirtype(self):
        # Test old style dirtype member (bug #1336623):
        # Old V7 tars create directory members using an AREGTYPE
        # header with a "/" appended to the filename field.
        tarinfo = self.tar.getmember("misc/dirtype-old-v7")
        self.assertTrue(tarinfo.type == tarfile.DIRTYPE,
                "v7 dirtype failed") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:test_tarfile.py

示例5: test_read_longname

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def test_read_longname(self):
        # Test reading of longname (bug #1471427).
        longname = self.subdir + "/" + "123/" * 125 + "longname"
        try:
            tarinfo = self.tar.getmember(longname)
        except KeyError:
            self.fail("longname not found")
        self.assertTrue(tarinfo.type != tarfile.DIRTYPE, "read longname as dirtype") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_tarfile.py

示例6: _git_interpret_archive

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def _git_interpret_archive(fd, toplevel):
    with tarfile.open(fileobj=fd, mode="r|*") as tf:
        git_files = set()
        git_dirs = {toplevel}
        for member in tf.getmembers():
            name = os.path.normcase(member.name).replace("/", os.path.sep)
            if member.type == tarfile.DIRTYPE:
                git_dirs.add(name)
            else:
                git_files.add(name)
        return git_files, git_dirs 
開發者ID:pypa,項目名稱:setuptools_scm,代碼行數:13,代碼來源:file_finder_git.py

示例7: _git_ls_files_and_dirs

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def _git_ls_files_and_dirs(toplevel):
    # use git archive instead of git ls-file to honor
    # export-ignore git attribute
    cmd = ['git', 'archive', '--prefix', toplevel + os.path.sep, 'HEAD']
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=toplevel)
    tf = tarfile.open(fileobj=proc.stdout, mode='r|*')
    git_files = set()
    git_dirs = set([toplevel])
    for member in tf.getmembers():
        name = os.path.normcase(member.name).replace('/', os.path.sep)
        if member.type == tarfile.DIRTYPE:
            git_dirs.add(name)
        else:
            git_files.add(name)
    return git_files, git_dirs 
開發者ID:thomaxxl,項目名稱:safrs,代碼行數:17,代碼來源:file_finder_git.py

示例8: test_v7_dirtype

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def test_v7_dirtype(self):
        # Test old style dirtype member (bug #1336623):
        # Old V7 tars create directory members using an AREGTYPE
        # header with a "/" appended to the filename field.
        tarinfo = self.tar.getmember("misc/dirtype-old-v7")
        self.assertEqual(tarinfo.type, tarfile.DIRTYPE,
                "v7 dirtype failed") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test_tarfile.py

示例9: test_read_longname

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def test_read_longname(self):
        # Test reading of longname (bug #1471427).
        longname = self.subdir + "/" + "123/" * 125 + "longname"
        try:
            tarinfo = self.tar.getmember(longname)
        except KeyError:
            self.fail("longname not found")
        self.assertNotEqual(tarinfo.type, tarfile.DIRTYPE,
                "read longname as dirtype") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:test_tarfile.py

示例10: test_tar_wrapper

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def test_tar_wrapper(self):
        temp = tempfile.NamedTemporaryFile()
        tar = tarfile.open(mode='w', fileobj=temp)

        tinfo1 = tar.gettarinfo(fileobj=self.tempfile1,
                                arcname='/root/baz/foo.txt')
        tar.addfile(tinfo1, self.tempfile1)

        tinfo2 = tar.gettarinfo(fileobj=self.tempfile2,
                                arcname='/root/bar.txt')
        tar.addfile(tinfo2, self.tempfile2)

        fake_root = tarfile.TarInfo('root')
        fake_root.type = tarfile.DIRTYPE
        tar.addfile(fake_root)

        fake_baz = tarfile.TarInfo('root/baz')
        fake_baz.type = tarfile.DIRTYPE
        tar.addfile(fake_baz)

        tar.close()
        temp.seek(0)

        wrapped_tar = utils.TarWrapper(tarfile.open(mode='r', fileobj=temp))
        self.assertEqual(wrapped_tar.get_file('root/bar.txt').read(), 'bar')
        self.assertEqual(wrapped_tar.get_file('root/baz/foo.txt').read(), 'foo')
        with self.assertRaises(ValueError):
            wrapped_tar.get_file('root')

        files, dirs = wrapped_tar.list('root')
        self.assertEqual(files, ['bar.txt'])
        self.assertEqual(dirs, ['baz'])
        with self.assertRaises(ValueError):
            wrapped_tar.list('root/bar.txt') 
開發者ID:GoogleCloudPlatform,項目名稱:appstart,代碼行數:36,代碼來源:utils_test.py

示例11: _build_image_tar

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def _build_image_tar(self, target_path):
        with tarfile.open(target_path, "w:gz") as image_tar:
            for directory in [
                ["./", "var", "lib", "dpkg", "info"],
                ["./", "var", "log"],
            ]:
                info = TarInfo("./" + Path(*directory).as_posix())
                info.type = tarfile.DIRTYPE
                image_tar.addfile(info)

            for file in [["var", "log", "dpkg.log"]]:
                image_tar.addfile(TarInfo("./" + Path(*file).as_posix()))

            status_file = io.BytesIO()

            for deb_file in self.files:
                deb_file.unpack_into_tar(image_tar, status_file)

            status_info = TarInfo(
                "./" + Path("var", "lib", "dpkg", "status").as_posix()
            )
            status_info.size = status_file.getbuffer().nbytes
            status_file.seek(0)

            image_tar.addfile(status_info, status_file)

            status_file.close() 
開發者ID:ThomasKluiters,項目名稱:fetchy,代碼行數:29,代碼來源:debian.py

示例12: install_tar

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def install_tar(f, prefix):
    meta = {}
    for info in f:
        #print(info)
        fname = info.name
        try:
            fname = fname[fname.index("/") + 1:]
        except ValueError:
            fname = ""

        save = True
        for p in ("setup.", "PKG-INFO", "README"):
            #print(fname, p)
            if fname.startswith(p) or ".egg-info" in fname:
                if fname.endswith("/requires.txt"):
                    meta["deps"] = f.extractfile(info).read()
                save = False
                if debug:
                    print("Skipping", fname)
                break

        if save:
            outfname = prefix + fname
            if info.type != tarfile.DIRTYPE:
                if debug:
                    print("Extracting " + outfname)
                _makedirs(outfname)
                subf = f.extractfile(info)
                with open(outfname, "wb") as outf:
                    outf.write(subf.read())
    return meta 
開發者ID:peterhinch,項目名稱:micropython-samples,代碼行數:33,代碼來源:micropip.py

示例13: test_put_archive

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def test_put_archive(docker, image_name):
    skip_windows()

    config = {
        "Cmd": ["python", "-c", "print(open('tmp/bar/foo.txt').read())"],
        "Image": image_name,
        "AttachStdin": False,
        "AttachStdout": False,
        "AttachStderr": False,
        "Tty": False,
        "OpenStdin": False,
    }

    file_data = b"hello world"
    file_like_object = io.BytesIO()
    tar = tarfile.open(fileobj=file_like_object, mode="w")

    info = tarfile.TarInfo(name="bar")
    info.type = tarfile.DIRTYPE
    info.mode = 0o755
    info.mtime = time.time()
    tar.addfile(tarinfo=info)

    tarinfo = tarfile.TarInfo(name="bar/foo.txt")
    tarinfo.size = len(file_data)
    tar.addfile(tarinfo, io.BytesIO(file_data))
    tar.list()
    tar.close()

    container = await docker.containers.create_or_replace(
        config=config, name="aiodocker-testing-archive"
    )
    await container.put_archive(path="tmp", data=file_like_object.getvalue())
    await container.start()
    await container.wait(timeout=5)

    output = await container.log(stdout=True, stderr=True)
    assert output[0] == "hello world\n", output
    await container.delete(force=True) 
開發者ID:aio-libs,項目名稱:aiodocker,代碼行數:41,代碼來源:test_integration.py

示例14: tar_folder

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def tar_folder(self, name, mtime=None):
        """
        Returns tar file header data for a folder with the given name.
        """
        info = tarfile.TarInfo(name=name)
        info.type = tarfile.DIRTYPE

        if mtime is not None:
            info.mtime = mtime

        # allow the directory to be readable by non-root users
        info.mode = 0o755
        return info.tobuf() 
開發者ID:quay,項目名稱:quay,代碼行數:15,代碼來源:common.py

示例15: _convertFileType

# 需要導入模塊: import tarfile [as 別名]
# 或者: from tarfile import DIRTYPE [as 別名]
def _convertFileType(type):
 return {
  tarfile.REGTYPE: S_IFREG,
  tarfile.LNKTYPE: S_IFLNK,
  tarfile.SYMTYPE: S_IFLNK,
  tarfile.CHRTYPE: S_IFCHR,
  tarfile.BLKTYPE: S_IFBLK,
  tarfile.DIRTYPE: S_IFDIR,
  tarfile.FIFOTYPE: S_IFIFO,
 }.get(type, S_IFREG) 
開發者ID:ma1co,項目名稱:fwtool.py,代碼行數:12,代碼來源:tar.py


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