pyfstab package

Module contents

pyfstab.fstab module

class pyfstab.fstab.Fstab

Bases: object

Handles reading, parsing, formatting and writing of fstab files.

Variables:
  • entries – (list[Entry]) - List of entries. When writing to a file, entries are listed from this list.
  • entries_by_device – (dict[str, list[Entry]]) - Fstab entries by device.
  • entry_by_dir – (dict[str, Entry]) - Fstab entry by directory.
  • entries_by_type – (dict[str, list[Entry]]) - Fstab entries by type.
read_file(handle, only_valid=False)

Parses entries from a file

Parameters:
  • handle (file) – File handle
  • only_valid (bool) – Skip the entries that do not actually mount. For example, if device A is mounted to directory X and later device B is mounted to directory X, the A mount to X is undone by the system.
Returns:

self

Return type:

Fstab

read_string(data, only_valid=False)

Parses entries from a data string

Parameters:
  • data (str) – Contents of the fstab file
  • only_valid (bool) – Skip the entries that do not actually mount. For example, if device A is mounted to directory X and later device B is mounted to directory X, the A mount to X is undone by the system.
Returns:

self

Return type:

Fstab

write_file(handle)

Parses entries in data string

Parameters:path (file) – File handle
Returns:self
Return type:Fstab
write_string()

Formats entries into a string.

Returns:Formatted fstab file.
Return type:str
Raises:InvalidEntry – A string cannot be generated because one of the entries is invalid.

pyfstab.entry module

class pyfstab.entry.Entry(_device=None, _dir=None, _type=None, _options=None, _dump=None, _fsck=None)

Bases: object

Handles parsing and formatting fstab line entries.

Variables:
  • device – (str or None) - Fstab device (1st parameter in the fstab entry)
  • dir – (str or None) - Fstab device (2nd parameter in the fstab entry)
  • type – (str or None) - Fstab device (3rd parameter in the fstab entry)
  • options – (str or None) - Fstab device (4th parameter in the fstab entry)
  • dump – (int or None) - Fstab device (5th parameter in the fstab entry)
  • fsck – (int or None) - Fstab device (6th parameter in the fstab entry)
  • valid – (bool) - Whether the Entry is valid or not. Can be checked with “if entry:”.
__init__(_device=None, _dir=None, _type=None, _options=None, _dump=None, _fsck=None)
Parameters:
  • _device (Union[str, tuple, list]) – Fstab device (1st parameter in the fstab entry). Tuple/list in form of (type, value) is also accepted (e.g. (“UUID”, “1234567890”))
  • _dir (str) – Fstab device (2nd parameter in the fstab entry)
  • _type (str) – Fstab device (3rd parameter in the fstab entry)
  • _options (str) – Fstab device (4th parameter in the fstab entry)
  • _dump (int) – Fstab device (5th parameter in the fstab entry)
  • _fsck (int) – Fstab device (6th parameter in the fstab entry)
device
Returns:device part string (e.g. “UUID=1234”)
device_tag_type
Returns:device tag’s type part string (e.g. “UUID” in “UUID=1234”)
device_tag_value
Returns:device tag’s value part string (e.g. “1234” in “UUID=1234”)
read_string(line)

Parses an entry from a string

Parameters:line (str) – Fstab entry line.
Returns:self
Return type:Entry
Raises:InvalidEntry – If the data in the string cannot be parsed.
write_string()

Formats the Entry into fstab entry line.

Returns:Fstab entry line.
Return type:str
Raises:InvalidEntry – A string cannot be generated because the entry is invalid.
exception pyfstab.entry.InvalidEntry

Bases: Exception

Raised when a string cannot be generated because of the Entry is invalid.

exception pyfstab.entry.InvalidFstabLine

Bases: Exception

Raised when a line is invalid in fstab. This doesn’t just mean that the Entry will be invalid but also that the system can not process the fstab file fully either.