4. item
Module providing the Item class for files in the initramfs
Each file type of the initramfs has an Item subclass. Those classes
provide methods used by Initramfs generation methods.
- class cmkinitramfs.item.Item[source]
Bases:
abc.ABCAn object within the initramfs
- Return type
- __contains__(path)[source]
Check if this item is present at the given path in the initramfs
This method should be overriden by subclasses which add files to the initramfs.
- __iter__()[source]
Get the paths of this item within the initramfs
This method should be overriden by subclasses which add files to the initramfs.
- static build_from_cpio_list(data)[source]
Build an Item from a string
This string should respect the format of
gen_init_cpio.- Parameters
data (str) – String to parse
- Returns
Item corresponding to
data- Raises
ValueError – Invalid string
- Return type
- abstract build_to_cpio_list()[source]
String representing the item
The string is formatted to be compatible with the
gen_init_cpiotool from the Linux kernel. This method has to be defined by subclasses.- Return type
- abstract build_to_directory(base_dir)[source]
Add this item to a real filesystem
This will copy or create a file on a real filesystem. This method has to be defined by subclasses.
- is_mergeable(other)[source]
Check if two items can be merged together
By default, two items can only be merged if they are equal.
- Parameters
other (cmkinitramfs.item.Item) –
Itemto merge intoself- Returns
- Return type
- merge(other)[source]
Merge two items together
Default merge is just a no-op. Subclasses can override this as done by
Fileto handle hardlink of identical files.- Parameters
other (cmkinitramfs.item.Item) –
Itemto merge intoself- Raises
MergeError – Cannot merge the items
- Return type
- class cmkinitramfs.item.File(mode, user, group, dests, src, data_hash, chunk_size=65536)[source]
Bases:
cmkinitramfs.item.ItemNormal file within the initramfs
- Parameters
mode (int) – Permissions (e.g. 0o644)
user (int) – Owner user (UID)
group (int) – Owner group (GID)
dests (Set[str]) – Paths in the initramfs (hard-linked)
src (str) – Source file to copy (not unique to the file)
data_hash (bytes) – Hash of the file (can be obtained with
hash_file())chunk_size (int) – Chunk size to use when copying the file
- Return type
- class cmkinitramfs.item.Directory(mode, user, group, dest)[source]
Bases:
cmkinitramfs.item.ItemDirectory within the initramfs
- class cmkinitramfs.item.Node(mode, user, group, dest, nodetype, major, minor)[source]
Bases:
cmkinitramfs.item.ItemSpecial file within the initramfs
- Parameters
- Return type
- class cmkinitramfs.item.Symlink(mode, user, group, dest, target)[source]
Bases:
cmkinitramfs.item.ItemSymlinks within the initramfs
- class cmkinitramfs.item.Pipe(mode, user, group, dest)[source]
Bases:
cmkinitramfs.item.ItemNamed pipe (FIFO) within the initramfs