当前位置: 首页>>代码示例>>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;未经允许,请勿转载。