spmi.core package

Contents

spmi.core package#

Subpackages#

Submodules#

spmi.core.manageable module#

Provides Manageable.

class spmi.core.manageable.Manageable(*args, data=None, meta=None, **kwargs)#

Bases: object

This class describes object which can be managed by SPMI.

Any realisation should be defined in spmi.core.manageables package in own file and decorated with manageable(). Its name should be written in PascalCase and ended with “Manageable”.

class FileSystemHelper#

Bases: object

Contains methods to work with filesystem.

DATA_FILENAME = 'data'#

name of data file (without extention)

Type:

str

META_FILENAME = 'meta'#

name of meta file (without extention)

Type:

str

static data_path(path)#

Returns path to data file.

Parameters:

path (pathlib.Path) – Directory path.

Returns:

pathlib.Path.

Raises:

ManageableException

static data_pathes(path)#

Return all potential data pathes.

Parameters:

path (pathlib.Path) – Directory path.

Returns:

list of pathlib.Path.

classmethod destruct(manageable)#

Destructs manageable.

Parameters:

manageable (Manageable) – Manageable to destruct.

Raises:
classmethod from_directory(path)#

Returns keyword arguments to create Manageable object.

Parameters:

path (pathlib.Path) – Path to directory.

Returns:

Kwargs.

Return type:

dict

Raises:
classmethod is_correct_directory(path)#

Returns True if path may be a directory where Manageable registered.

Parameters:

path (pathlib.Path) – Path to directory.

Returns:

bool.

Raises:

TypeError

static meta_path(path)#

Returns path to meta file.

Parameters:

path (pathlib.Path) – Directory path.

Returns:

pathlib.Path.

Raises:

ManageableException

static meta_pathes(path)#

Return all potential meta pathes.

Parameters:

path (pathlib.Path) – Directory path.

Returns:

list of pathlib.Path.

classmethod register(manageable, path)#

Registeres manageable by path.

Parameters:
  • manageable (Manageable) – Manageable to register.

  • path (pathlib.Path) – Path to use.

Raises:
class LoadHelper#

Bases: object

Abstract load helper.

static from_descriptor(path)#

Loads detected manageable from descriptor.

Parameters:

path (pathlib.Path) – Path to descriptor.

Returns:

Manageable.

Raises:
static from_directory_unknown(path)#

Loads registered manageable from directory.

Parameters:

path (pathlib.Path) – Path to directory.

Returns:

Manageable.

Raises:
static load_manageable_class(name)#

Loads manageable class by name.

Parameters:

name (str) – Classname.

Returns:

class.

Raises:
  • TypeError

  • NotImplementedError

class MetaDataHelper(data=None, meta=None, mutable=True, metadata=None, copy=True)#

Bases: MetaData

Parameters:
  • meta (Union[dict, pathlib.Path, None]) – Meta dictionary. Empty dict if None.

  • data (Union[dict, pathlib.Path, None]) – Data dictionary. Empty dict if None.

  • metadata (Union[dict, MetaData]) – MetaData object.

  • mutable (bool) – Mutable flag.

  • copy (bool) – Copy flag. If True, deepcopies meta, data and metadata.

Note

You can set meta and data or metadata flags at once

Raises:
property comment#

str. Comment.

Raises:

KeyError

property finish_time#

Union[None, datetime.datetime]. Finish time.

Raises:
property id#

str. ID.

Raises:

KeyError

property m_data#

dict. Manageable data.

property path#

pathlib.Path. Path.

Raises:
property prefered_suffix#

str. Prefered suffix.

Raises:
reset()#

Resets some values in case of restart.

Raises:

MetaDataError

property start_time#

Union[None, datetime.datetime]. Start time.

Raises:
property type#

str. Type.

Raises:

ValueError

destruct()#

Free all resources (filesystem too).

Raises:

ManageableException

static from_descriptor(path)#

Loads detected manageable from descriptor.

Parameters:

path (pathlib.Path) – Path to descriptor.

Returns:

Manageable.

Raises:
classmethod from_directory(path)#

Loads registered manageable from directory.

Parameters:

path (pathlib.Path) – Path to directory.

Returns:

Manageable.

Raises:
static from_directory_unknown(path)#

Loads registered manageable from directory.

Parameters:

path (pathlib.Path) – Path to directory.

Returns:

Manageable.

Raises:
classmethod is_correct_directory(path)#

Returns True if this manageable is registered.

Parameters:

path (pathlib.Path) – Path to directory.

Returns:

bool.

Raises:

TypeError

classmethod is_correct_meta_data(data, meta=None)#

Returns True if meta and data may be Manageable’s meta and data.

Parameters:
  • data (Union[dict, pathlib.Path]) – Data.

  • meta (Uinon[dict, pathlib.Path, None]) – Meta.

Returns:

bool.

Raises:

TypeError

abstract kill()#

Kill this manageable.

Raises:

ManageableException

register(path)#

Registers by path.

To register a Manageable means to create directory and save there meta and data files.

Parameters:

path (pathlib.Path) – Path where manageable should be registered.

Raises:
abstract start()#

Starts this manageable.

Raises:

ManageableException

property state#

Manageable.MetaDataHelper state of this manageable.

abstract property status#

Status of manageable.

Type:

ManageableStatus

status_string(align=0)#

Returns status string of this manageable.

Parameters:

align (int) – Align.

abstract term()#

Terminate this manageable.

Raises:

ManageableException

exception spmi.core.manageable.ManageableException#

Bases: SpmiException

class spmi.core.manageable.ManageableStatus(value)#

Bases: str, Enum

An enumeration.

ACTIVE = 'active'#
INACTIVE = 'inactive'#
UNTRACKED = 'untracked'#
spmi.core.manageable.manageable(cls)#

All manageables should be decorated with it.

Note

Sets __old_init__ attribute of class and _metadata and _metadata._outer_object of object.

Raises:

AttributeError

spmi.core.pool module#

Provides Pool.

class spmi.core.pool.Pool(path, pm)#

Bases: object

A class which helps to manage Manageables.

Parameters:

path (pathlib.Path) – Path of pool root.

Raises:
class FileSystemHelper(path)#

Bases: object

Provides several methods to work with filesystem.

Parameters:

path (pathlib.Path) – Path where directory of manageables is placed.

Note

path should exist and be a directory.

Raises:
get_registered_manageables()#

Returns list of registered manageables.

Returns:

list of spmi.core.manageable.Manageable.

register(manageable)#

Registers a manageable.

Parameters:

manageable (spmi.core.manageable.Manageable) – manageable to register.

Raises:
find(pattern)#

Return list of manageables corresponding to pattern.

Parameters:

pattern (str) – Pattern to find.

Returns:

list of spmi.core.manageable.Manageable.

property manageables#

list of Manageable. Copy of list with registered manageables.

register(manageable)#

Registers a detected manageable.

Parameters:

manageable (spmi.core.manageable.Manageable) – detected manageable to register.

Raises:
exception spmi.core.pool.PoolException#

Bases: SpmiException

Module contents#