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 withmanageable()
. 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:
- static data_pathes(path)#
Return all potential data pathes.
- Parameters:
path (
pathlib.Path
) – Directory path.- Returns:
list
ofpathlib.Path
.
- classmethod destruct(manageable)#
Destructs manageable.
- Parameters:
manageable (
Manageable
) – Manageable to destruct.- Raises:
TypeError –
- classmethod from_directory(path)#
Returns keyword arguments to create
Manageable
object.- Parameters:
path (
pathlib.Path
) – Path to directory.- Returns:
Kwargs.
- Return type:
dict
- Raises:
TypeError –
- classmethod is_correct_directory(path)#
Returns
True
ifpath
may be a directory whereManageable
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:
- static meta_pathes(path)#
Return all potential meta pathes.
- Parameters:
path (
pathlib.Path
) – Directory path.- Returns:
list
ofpathlib.Path
.
- classmethod register(manageable, path)#
Registeres manageable by path.
- Parameters:
manageable (
Manageable
) – Manageable to register.path (
pathlib.Path
) – Path to use.
- Raises:
TypeError –
- class LoadHelper#
Bases:
object
Abstract load helper.
- static from_descriptor(path)#
Loads detected manageable from descriptor.
- Parameters:
path (
pathlib.Path
) – Path to descriptor.- Returns:
- Raises:
TypeError –
NotImplementedError –
- static from_directory_unknown(path)#
Loads registered manageable from directory.
- Parameters:
path (
pathlib.Path
) – Path to directory.- Returns:
- Raises:
TypeError –
NotImplementedError –
- 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. Emptydict
ifNone
.data (
Union[dict, pathlib.Path, None]
) – Data dictionary. Emptydict
ifNone
.metadata (
Union[dict, MetaData]
) –MetaData
object.mutable (
bool
) – Mutable flag.copy (
bool
) – Copy flag. IfTrue
, deepcopiesmeta
,data
andmetadata
.
Note
You can set meta and data or metadata flags at once
- Raises:
TypeError –
ValueError –
- property comment#
str
. Comment.- Raises:
KeyError –
- property finish_time#
Union[None, datetime.datetime]
. Finish time.- Raises:
TypeError –
- property id#
str
. ID.- Raises:
KeyError –
- property m_data#
dict
. Manageable data.
- property path#
pathlib.Path
. Path.- Raises:
TypeError –
- property prefered_suffix#
str
. Prefered suffix.- Raises:
TypeError –
- reset()#
Resets some values in case of restart.
- Raises:
- property start_time#
Union[None, datetime.datetime]
. Start time.- Raises:
TypeError –
- property type#
str
. Type.- Raises:
ValueError –
- destruct()#
Free all resources (filesystem too).
- Raises:
- static from_descriptor(path)#
Loads detected manageable from descriptor.
- Parameters:
path (
pathlib.Path
) – Path to descriptor.- Returns:
- Raises:
TypeError –
- classmethod from_directory(path)#
Loads registered manageable from directory.
- Parameters:
path (
pathlib.Path
) – Path to directory.- Returns:
- Raises:
TypeError –
- static from_directory_unknown(path)#
Loads registered manageable from directory.
- Parameters:
path (
pathlib.Path
) – Path to directory.- Returns:
- Raises:
TypeError –
- 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
ifmeta
anddata
may beManageable
’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:
- 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:
TypeError –
- abstract start()#
Starts this manageable.
- Raises:
- property state#
Manageable.MetaDataHelper
state of this manageable.
- abstract property status#
Status of manageable.
- Type:
- status_string(align=0)#
Returns status string of this manageable.
- Parameters:
align (
int
) – Align.
- abstract term()#
Terminate this manageable.
- Raises:
- 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:
TypeError –
- 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:
TypeError –
- get_registered_manageables()#
Returns list of registered manageables.
- Returns:
list
ofspmi.core.manageable.Manageable
.
- register(manageable)#
Registers a manageable.
- Parameters:
manageable (
spmi.core.manageable.Manageable
) – manageable to register.- Raises:
TypeError –
- find(pattern)#
Return list of manageables corresponding to pattern.
- Parameters:
pattern (
str
) – Pattern to find.- Returns:
list
ofspmi.core.manageable.Manageable
.
- property manageables#
list
ofManageable
. Copy of list with registered manageables.
- register(manageable)#
Registers a detected manageable.
- Parameters:
manageable (
spmi.core.manageable.Manageable
) – detected manageable to register.- Raises:
TypeError –
- exception spmi.core.pool.PoolException#
Bases:
SpmiException