parted.util module

Utilities for parted

Author: Adolfo Gómez, dkmaster at dkmon dot com

class parted.util.OpenContext(object: Any)[source]

Bases: object

Context manager for opening and closing after use

parted.util.cache_del(obj: Any, attr: str) None[source]

Cleans cache of a method or property on an specific class attribute

Parameters:
  • obj (Any) – Object to clean cache on

  • attr (str) – Attribute to clean

parted.util.cache_on(attr: str) Callable[source]

Decorator to cache result of a method or property on an specific class attribute

Parameters:

attr (str) – Attribute to cache on

Returns:

Decorator

Return type:

Callable

parted.util.cache_set(obj: Any, attr: str, value: Any) None[source]

Updates cache of a method or property on an specific class attribute

Parameters:
  • obj (Any) – Object to clean cache on

  • attr (str) – Attribute to clean

  • value (Any) – Value to set

parted.util.ensure_obj(func: Callable) Callable
parted.util.ensure_obj_or_default(default: Any) Callable

Decorator similar to ensure_valid, but returns a default value instead of raising an exception

Parameters:
  • attr (str) – Attribute to check

  • default (Any) – Default value to return if attr is not valid

Returns:

Decorator

Return type:

Callable

parted.util.ensure_root(func: Callable) Callable[source]

Decorator that ensures effective process user is root

Parameters:

func (Callable) – Function to decorate

Raises:

exceptions.PartedException – If effective user is not root

Returns:

_description_

Return type:

Callable

parted.util.ensure_valid(attr: str) Callable[source]

Ensures the attribute “attr” is present and it’s bool evaluates to “True” before calling the method.

If the attribute is not present or it’s bool evaluates to “False”, an exceptions.InvalidObjectException is raised.

Parameters:

attr (str) – _description_

Returns:

_description_

Return type:

Callable

parted.util.ensure_valid_or_default(attr: str, default: Any) Callable[source]

Decorator similar to ensure_valid, but returns a default value instead of raising an exception

Parameters:
  • attr (str) – Attribute to check

  • default (Any) – Default value to return if attr is not valid

Returns:

Decorator

Return type:

Callable

parted.util.make_destroyable(obj: T) T[source]

Checks if a object has a “_destroyable” attribute and sets it to True

Parameters:

obj (T) – Object to check

Returns:

The same object

Return type:

T