當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。