woger package

Module contents

class woger.Workspace(data)[source]

Bases: object

Wrapper interface to store path and data

id

int or str

root

str

path

BasePathStructure

data

BaseData

Examples

Basic workspace

Workspace with chained loaders

classmethod construct(root, path_structure_cls=None, data_cls=None)[source]

Creates a Workspace object

Convinient alternative constructor

id

Workspace id

Id is used to sort workspaces from oldest to latest

path

Bound path structure object

root

Workspace root

track(action: str) → woger.action_tracker.ActionTracker[source]

Creates an ActionTracker object to manage action action

It’s a shortcut to avoid creating ActionTracker directly

action

str – Action to track

class woger.WorkspaceState(path: str)[source]

Bases: object

Manages workspace state

State is written to file each time anything changes

path

str – Path of the file to store the state in

class woger.WorkspaceStorage(workspaces: typing.Union[typing.Iterable[woger.workspace.Workspace], NoneType] = None, limit: typing.Union[int, NoneType] = None)[source]

Bases: object

Stores workspaces

add(workspace: woger.workspace.Workspace)[source]

Add a workspace

Parameters:workspace (Workspace) – Workspace to be added
at(index) → typing.Union[woger.workspace.Workspace, NoneType][source]

Gets workspace from storage by index

To get the oldest workspace use index 0 To get the latest workspace use index -1

items()[source]
keys()[source]
classmethod load_from_directory(root, *, path_structure_cls=None, data_cls=None, workspace_cls=None)[source]

Creates a workspaces instance and loads all the workspaces from the root path

root

str – Storage root path

path_structure_cls

BasePathStructure class object

data_cls

BaseData class object

workspace_cls

Workspace class object

values() → typing.List[woger.workspace.Workspace][source]
class woger.WorkspaceManager(root, path_structure_cls=None, data_cls=None, workspace_cls=None)[source]

Bases: object

Manages workspaces

Allows you to - create workspaces - load workspaces from directory - manage current, target and latest workspaces - search for workspaces with finished actions

Examples

Workspace management

Manager with data bindings

create(ws_id) → woger.workspace.Workspace[source]

Creates a Workspace

Parameters:ws_id (str or int) – Workspace id
current() → typing.Union[woger.workspace.Workspace, NoneType][source]

Returns current workspace

current_ws_id

Returns current workspace id

find_latest_finished(action) → typing.Union[woger.workspace.Workspace, NoneType][source]

Searches for latest workspace with finished action action

latest() → woger.workspace.Workspace[source]

Returns latest workspace

target() → woger.workspace.Workspace[source]

Returns target workspace

target_latest()[source]

Sets the target id equal to the latest id

target_ws_id

Returns target workspace id

update()[source]

Migrates from current workspace to target one

Sets the current workspace id equal to the target workspace id

class woger.ActionTracker(action: str, state_path: str, path=None)[source]

Bases: object

Manages and monitors actions

failed()[source]

Returns True if the action has failed

finished()[source]

Returns True if the action has finished

started()[source]

Returns True if the action has started and is pending

state

WorkspaceState object linked to self.state_path

status()[source]

Returns a string representation of the current action status

undefined()[source]

Returns True if the action state is not defined

class woger.ActionStatus[source]

Bases: enum.Enum

List of action statuses

failed = 'failed'
finished = 'finished'
started = 'started'
undefined = None
class woger.BasePathStructure(root: str, *, data=None)[source]

Bases: object

Base class for the path structure

track(action: str) → woger.action_tracker.ActionTracker[source]

Creates an ActionTracker object and targets action action

It’s a shortcut which creates an ActionTracker for you

..code-block:: python

>>> from woger import BasePathStructure
>>>
>>> class PathStructure(BasePathStructure):
...     json = 'json'
>>>
>>> ps = PathStructure('root')
>>>
>>> # WRONG
>>> tracker = ActionTracker('load_json', 'root/state.json', ps.json)
>>>
>>> # RIGHT
>>> tracker = ps.track(ps.json.action())
Parameters:action (str) – Action to track
Returns:
Return type:ActionTracker instance
class woger.BaseData(path_structure=None)[source]

Bases: object

Base class for the data

Examples

Basic data loader

Pass data loader args

Chained data loaders

class woger.Bind(path: str, loader=None)[source]

Bases: str

String wrapper class to hold a loader attribute

path

str

loader

function

action()[source]

Construct an action name from a Bind object

classmethod from_action(action)[source]

Construct a Bind object from an action name