xcp.cpiofile¶
Read from and write to cpio format archives.
Of course: Only platforms with filesystems supporting hardlinks support extracting cpio files containing hardlinks, but Dom0 does.
Derived from Lars Gustäbel’s tarfile.py
- class xcp.cpiofile.CpioFile(name: str | None = None, mode: str = 'r', fileobj: IO[bytes] | GzipFile | _Stream | None = None)[source]¶
Bases:
object
The CpioFile Class provides an interface to cpio archives.
- OPEN_METH = {'bz2': 'bz2open', 'cpio': 'cpioopen', 'gz': 'gzopen', 'xz': 'xzopen'}¶
- add(name, arcname=None, recursive=True)[source]¶
Add the file name to the archive. name may be any type of file (directory, fifo, symbolic link, etc.). If given, arcname specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by setting recursive to False.
- addfile(cpioinfo, fileobj=None)[source]¶
Add the CpioInfo object cpioinfo to the archive. If fileobj is given, cpioinfo.size bytes are read from it and added to the archive. You can create CpioInfo objects using getcpioinfo(). On Windows platforms, fileobj should always be opened with mode ‘rb’ to avoid irritation about the file size.
- classmethod bz2open(name: str, mode: Literal['r', 'w'] = 'r', fileobj: IO[bytes] | None = None, compresslevel: int = 9) CpioFile [source]¶
Open bzip2 compressed cpio archive name for reading or writing, no appending
- classmethod cpioopen(name: str, mode: str = 'r', fileobj: GzipFile | IO[bytes] | None = None) CpioFile [source]¶
Open uncompressed cpio archive name for reading or writing.
- debug = 0¶
- dereference = False¶
- errorlevel = 0¶
- extract(member, path='')[source]¶
Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. member may be a filename or a CpioInfo object. You can specify a different directory using path.
- extractall(path='.', members=None)[source]¶
Extract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. path specifies a different directory to extract to. members is optional and must be a subset of the list returned by getmembers().
- extractfile(member: CpioInfo | str | bytes) ExFileObject | None [source]¶
Extract a member from the archive as a file object. member may be a filename or a CpioInfo object. If member is a regular file, a file-like object is returned. If member is a link, a file-like object is constructed from the link’s target. If member is none of the above, None is returned. The file-like object is read-only and provides the following methods: read(), readline(), readlines(), seek() and tell()
- fileobject¶
alias of
ExFileObject
- getcpioinfo(name=None, arcname=None, fileobj=None)[source]¶
Create a CpioInfo object for either the file name or the file object fileobj (using os.fstat on its file descriptor). You can modify some of the CpioInfo’s attributes before you add it using addfile(). If given, arcname specifies an alternative name for the file in the archive.
- getmember(name: str | bytes) CpioInfo [source]¶
Return a CpioInfo object for member name. If name can not be found in the archive, KeyError is raised. If a member occurs more than once in the archive, its last occurrence is assumed to be the most up-to-date version.
- getmembers() List[CpioInfo] [source]¶
Return the members of the archive as a list of CpioInfo objects. The list has the same order as the members in the archive.
- getnames()[source]¶
Return the members of the archive as a list of their names. It has the same order as the list returned by getmembers().
- classmethod gzopen(name, mode='r', fileobj=None, compresslevel=9)[source]¶
Open gzip compressed cpio archive name for reading or writing. Appending is not allowed.
- hardlinks = True¶
- list(verbose=True)[source]¶
Print a table of contents to sys.stdout. If verbose is False, only the names of the members are printed. If it is True, an ls -l-like output is produced.
- makelink(cpioinfo, targetpath)[source]¶
Make a (symbolic) link called targetpath. If it cannot be created (platform limitation), we try to make a copy of the referenced file instead of a link.
- classmethod open(name=None, mode='r', fileobj=None, bufsize=10240)[source]¶
Open a cpio archive for reading, writing or appending. Return an appropriate CpioFile class.
mode:
r
orr:*
open for reading with transparent compressionr:
open for reading exclusively uncompressedr:gz
open for reading with gzip compressionr:bz2
open for reading with bzip2 compressionr:xz
open for reading with xz compressiona
ora:
open for appendingw
orw:
open for writing without compressionw:gz
open for writing with gzip compressionw:bz2
open for writing with bzip2 compressionw:xz
open for writing with xz compressionr|*
open a stream of cpio blocks with transparent compressionr|
open an uncompressed stream of cpio blocks for readingr|gz
open a gzip compressed stream of cpio blocksr|bz2
open a bzip2 compressed stream of cpio blocksr|xz
open a xz compressed stream of cpio blocksw|
open an uncompressed stream for writingw|gz
open a gzip compressed stream for writingw|bz2
open a bzip2 compressed stream for writingw|xz
open a xz compressed stream for writing