当前位置: 首页>>代码示例>>Python>>正文


Python tarfile.REGTYPE属性代码示例

本文整理汇总了Python中tarfile.REGTYPE属性的典型用法代码示例。如果您正苦于以下问题:Python tarfile.REGTYPE属性的具体用法?Python tarfile.REGTYPE怎么用?Python tarfile.REGTYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在tarfile的用法示例。


在下文中一共展示了tarfile.REGTYPE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _add_file

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def _add_file(self, tar, name, contents, mode=DEFAULT_FILE_MODE):
        """
        Adds a single file in tarfile instance.

        :param tar: tarfile instance
        :param name: string representing filename or path
        :param contents: string representing file contents
        :param mode: string representing file mode, defaults to 644
        :returns: None
        """
        byte_contents = BytesIO(contents.encode('utf8'))
        info = tarfile.TarInfo(name=name)
        info.size = len(contents)
        # mtime must be 0 or any checksum operation
        # will return a different digest even when content is the same
        info.mtime = 0
        info.type = tarfile.REGTYPE
        info.mode = int(mode, 8)  # permissions converted to decimal notation
        tar.addfile(tarinfo=info, fileobj=byte_contents) 
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:21,代码来源:backend.py

示例2: __init__

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def __init__(self, name="", sparsemap=None):
        super(TarSparseInfo, self).__init__(name)
        if sparsemap is not None:
            self.type = tarfile.REGTYPE
            self.sparsemap = sparsemap
            self.sparsemap_buf = self.format_sparse_map()
            # compact size
            self.size = functools.reduce(lambda x, y: x+y[1], sparsemap,
                0) + len(self.sparsemap_buf)
            self.pax_headers['GNU.sparse.major'] = '1'
            self.pax_headers['GNU.sparse.minor'] = '0'
            self.pax_headers['GNU.sparse.name'] = name
            self.pax_headers['GNU.sparse.realsize'] = str(self.realsize)
            self.name = '{}/GNUSparseFile.{}/{}'.format(
                os.path.dirname(name), os.getpid(), os.path.basename(name))
        else:
            self.sparsemap = []
            self.sparsemap_buf = b'' 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:20,代码来源:tarwriter.py

示例3: _make_test_archive

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [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

示例4: WriteFromFD

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def WriteFromFD(self, src_fd, arcname=None, st=None):
    """Write an archive member from a file like object.

    Args:
      src_fd: A file like object, must support seek(), tell(), read().
      arcname: The name in the archive this should take.
      st: A stat object to be used for setting headers.

    Raises:
      ValueError: If st is omitted.
    """

    if st is None:
      raise ValueError("Stat object can't be None.")

    info = self.tar_fd.tarinfo()
    info.tarfile = self.tar_fd
    info.type = tarfile.REGTYPE
    info.name = SmartStr(arcname)
    info.size = st.st_size
    info.mode = st.st_mode
    info.mtime = st.st_mtime or time.time()

    self.tar_fd.addfile(info, src_fd) 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:26,代码来源:grr_utils.py

示例5: create_user_dirs

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [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

示例6: test_add_twice

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def test_add_twice(self):
        # The same name will be added as a REGTYPE every
        # time regardless of st_nlink.
        tarinfo = self.tar.gettarinfo(self.foo)
        self.assertTrue(tarinfo.type == tarfile.REGTYPE,
                "add file as regular failed") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_tarfile.py

示例7: test_dereference_hardlink

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def test_dereference_hardlink(self):
        self.tar.dereference = True
        tarinfo = self.tar.gettarinfo(self.bar)
        self.assertTrue(tarinfo.type == tarfile.REGTYPE,
                "dereferencing hardlink failed") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_tarfile.py

示例8: test_add_twice

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def test_add_twice(self):
        # The same name will be added as a REGTYPE every
        # time regardless of st_nlink.
        tarinfo = self.tar.gettarinfo(self.foo)
        self.assertEqual(tarinfo.type, tarfile.REGTYPE,
                "add file as regular failed") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_tarfile.py

示例9: test_dereference_hardlink

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def test_dereference_hardlink(self):
        self.tar.dereference = True
        tarinfo = self.tar.gettarinfo(self.bar)
        self.assertEqual(tarinfo.type, tarfile.REGTYPE,
                "dereferencing hardlink failed") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_tarfile.py

示例10: valid_tar_gz

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def valid_tar_gz(contents):
    assert isinstance(contents, bytes)
    with closing(BytesIO()) as layer_data:
        with closing(tarfile.open(fileobj=layer_data, mode="w|gz")) as tar_file:
            tar_file_info = tarfile.TarInfo(name="somefile")
            tar_file_info.type = tarfile.REGTYPE
            tar_file_info.size = len(contents)
            tar_file_info.mtime = 1
            tar_file.addfile(tar_file_info, BytesIO(contents))

        layer_bytes = layer_data.getvalue()
    return layer_bytes 
开发者ID:quay,项目名称:quay,代码行数:14,代码来源:test_blobuploader.py

示例11: layer_bytes_for_contents

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def layer_bytes_for_contents(contents, mode="|gz", other_files=None, empty=False):
    if empty:
        return EMPTY_LAYER_BYTES

    layer_data = BytesIO()
    tar_file = tarfile.open(fileobj=layer_data, mode="w" + mode)

    def add_file(name, contents):
        tar_file_info = tarfile.TarInfo(name=name)
        tar_file_info.type = tarfile.REGTYPE
        tar_file_info.size = len(contents)
        tar_file_info.mtime = 1

        tar_file.addfile(tar_file_info, BytesIO(contents))

    add_file("contents", contents)

    if other_files is not None:
        for file_name, file_contents in other_files.items():
            add_file(file_name, file_contents)

    tar_file.close()

    layer_bytes = layer_data.getvalue()
    layer_data.close()
    return layer_bytes 
开发者ID:quay,项目名称:quay,代码行数:28,代码来源:protocols.py

示例12: tar_file_header

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def tar_file_header(self, name, file_size, mtime=None):
        """
        Returns tar file header data for a file with the given name and size.
        """
        info = tarfile.TarInfo(name=name)
        info.type = tarfile.REGTYPE
        info.size = file_size

        if mtime is not None:
            info.mtime = mtime
        return info.tobuf() 
开发者ID:quay,项目名称:quay,代码行数:13,代码来源:common.py

示例13: _WriteHeader

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def _WriteHeader(self, name, size, mode):
    info = tarfile.TarInfo(name)
    info.size = size
    info.mode = mode
    info.type = tarfile.REGTYPE
    info.uid = info.gid = 0
    info.uname = info.gname = 'root'
    self._Write(info.tobuf()) 
开发者ID:google,项目名称:catnip,代码行数:10,代码来源:protocol.py

示例14: _convertFileType

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [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

示例15: test_readlines

# 需要导入模块: import tarfile [as 别名]
# 或者: from tarfile import REGTYPE [as 别名]
def test_readlines(self):
        """Test readlines() method of _FileObject.
        """
        if self.sep != "|":
            filename = "0-REGTYPE-TEXT"
            self.tar.extract(filename, dirname())
            f = open(os.path.join(dirname(), filename), "rU")
            lines1 = f.readlines()
            f.close()
            lines2 = self.tar.extractfile(filename).readlines()
            self.assert_(lines1 == lines2,
                         "_FileObject.readline() does not work correctly") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:14,代码来源:test_tarfile.py


注:本文中的tarfile.REGTYPE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。