agency Package

agency Package

agency

This agency.agency module provides the single manager instance used to store the Agent instances. This module also provides the AGENT_CATEGORIES. These categories are used to group agents of common functionality together. There is no rigid enforcement of which agent belongs where. They are only used as a convention. These categories are the strings that are used in the class field in the configuration.

agency.agency.AGENT_CATEGORIES
evasion.agency.get_log()[source]

agency Module

class evasion.agency.agency.Nodes[source]

Bases: object

This class manages the node and alias id string generation, based on the agent category currently found in agency.AGENT_CATEGORIES.

add(cat, cat_name, alias=None)[source]

Called to generate a node_id and alias_id for the given class recovered from the config file.

cat:
This must be a string as found in agency.AGENT_CATEGORIES. If not the ValueError will be raised.
cat_name:
This is the name of the config section as recovered from the agent configuration.
alias:

This is the user specific id recovered from the config file. The agency manager must make sure these are unique.

If this is not given then an alias will be auto-generated.

returned:

(node_id, alias_id)

E.g.
node_id = ‘/agent/swipe/testing/1’ alias_id = ‘/agent/swipe/1’

The node_id provides a specific id for addressing a particular agent. The alias_id is used when any instance of the agent maybe used.

get(cat)[source]

Called to return the current count for the allocated node ids.

cat:
This must be a string as found in agency.AGENT_CATEGORIES. If not the ValueError will be raised.
returned:
The amount of ids given out so far.
evasion.agency.agency.shutdown()[source]

Shutdown the agent manager, stopping and cleaning up all agents we manager.

agent Module

agency.agent

Platforms: Unix, MacOSX, Windows

This module implements the base agent interface that agents must inherit from and implement. The agent manager looks for this and if found uses it to create and run the agent.

class evasion.agency.agent.Base[source]

Bases: object

Base class agent entry.

setUp(config)[source]

Called to set up the agent and subscribe for any events it may be interested in.

start()[source]

Called to start any processing the agent may need to do.

This function maybe used to start any threads polling a agent for example.

stop()[source]

Called to stop any processing the agent may be doing.

The start function may be called to resume operation.

tearDown()[source]

Called to cleanup and release any resources the agent may be using.

This is usually done by the agent manager before the program using it exits.

config Module

evasion.agency.config

This module provides the Agent parsing, loading and configuration handling.

exception evasion.agency.config.ConfigError
class evasion.agency.config.Container[source]

This represents a configuration sections as recoverd from the agent configuration.

A config section can have the following options:

[name]
# The python path to agent to import e.g.
agent = 'agency.testing.fake'

# A ategoary from agency.AGENT_CATEGORIES
cat = 'general'

# OPTIONAL: a unique number which can be used instead of name
# to refer to this agent.
alias = 1

# OPTIONAL: disable the setup/tearDown/start/stop of the
# agent. It will still be loaded and created.
disabled = 'yes' | 'no'
check()[source]

Called to check that all the reserved fields have been provided.

If one or more aren’t provided then ConfigError will be raised to indicate so.

evasion.agency.config.load(config, check=None)[source]

Called to test and then load the agent configuration.

config:
This is a string representing the contents of the configuration file.
check:
If this is given the callback will be invoked and given the node and alias of the config object. The callback can then check if its unique. Its up to the user to determine what to do if they’re not.
returned:
This returns a list of config containers loaded with the entries recovered from the device’s section.
exception evasion.agency.config.ConfigError[source]

Bases: exceptions.Exception

This is raised for problems with loading and using the configuration.

class evasion.agency.config.Container[source]

Bases: object

This represents a configuration sections as recoverd from the agent configuration.

A config section can have the following options:

[name]
# The python path to agent to import e.g.
agent = 'agency.testing.fake'

# A ategoary from agency.AGENT_CATEGORIES
cat = 'general'

# OPTIONAL: a unique number which can be used instead of name
# to refer to this agent.
alias = 1

# OPTIONAL: disable the setup/tearDown/start/stop of the
# agent. It will still be loaded and created.
disabled = 'yes' | 'no'
check()[source]

Called to check that all the reserved fields have been provided.

If one or more aren’t provided then ConfigError will be raised to indicate so.

evasion.agency.config.get_log()[source]
evasion.agency.config.load(config, check=None)[source]

Called to test and then load the agent configuration.

config:
This is a string representing the contents of the configuration file.
check:
If this is given the callback will be invoked and given the node and alias of the config object. The callback can then check if its unique. Its up to the user to determine what to do if they’re not.
returned:
This returns a list of config containers loaded with the entries recovered from the device’s section.

manager Module

manager – This supervises then agents under its control.

Platforms: Unix, MacOSX, Windows

This is the manager. It is reposible for managing the physical agents the application is using. The agent manager takes care of the loading and intialisation of each agent, using the configuration provided by the user.

exception evasion.agency.manager.ManagerError
class evasion.agency.manager.Manager[source]

The agent manager takes care of the load of agents and provides a central point to setUp, tearDown, start & stop all agent nodes under our care.

agent(alias, absolute=False)[source]

Called to recover a specific agent node.

alias:
This is the alias for a specific agent node stored in the agent manager.

If the alias is not found the ManagerError will be raised.

agents
formatError()[source]

Return a string representing the last traceback.

getAgentCount()[source]
load()[source]

Load the agent modules into the system wide configuration.

The system wide configuration needs to have been set up via the director.config functions.

The shutdown method must be called before recalling load. If this has not been done then ManagerError will be raised.

returned:
For testing purposes the loaded list of agents . This shouldn’t be used normally.
setUp()[source]

Called to initialise all agents in our care.

The load method must be called before this one. Otherwise ManagerError will be raised.

shutdown()[source]

Used to tearDown and reset the internal state of the agent manager ready for a new load command.

start()[source]

Start all agents under our management

The load method must be called before this one. Otherwise ManagerError will be raised.

stop()[source]

Start all agents under our management

The load method must be called before this one. Otherwise ManagerError will be raised.

tearDown()[source]

Called to tearDown all agents in our care.

Before calling a agents tearDown() its stop() method is called first.

The load method must be called before this one. Otherwise ManagerError will be raised.

class evasion.agency.manager.Manager[source]

Bases: object

The agent manager takes care of the load of agents and provides a central point to setUp, tearDown, start & stop all agent nodes under our care.

agent(alias, absolute=False)[source]

Called to recover a specific agent node.

alias:
This is the alias for a specific agent node stored in the agent manager.

If the alias is not found the ManagerError will be raised.

agents
formatError()[source]

Return a string representing the last traceback.

getAgentCount()[source]
load()[source]

Load the agent modules into the system wide configuration.

The system wide configuration needs to have been set up via the director.config functions.

The shutdown method must be called before recalling load. If this has not been done then ManagerError will be raised.

returned:
For testing purposes the loaded list of agents . This shouldn’t be used normally.
setUp()[source]

Called to initialise all agents in our care.

The load method must be called before this one. Otherwise ManagerError will be raised.

shutdown()[source]

Used to tearDown and reset the internal state of the agent manager ready for a new load command.

start()[source]

Start all agents under our management

The load method must be called before this one. Otherwise ManagerError will be raised.

stop()[source]

Start all agents under our management

The load method must be called before this one. Otherwise ManagerError will be raised.

tearDown()[source]

Called to tearDown all agents in our care.

Before calling a agents tearDown() its stop() method is called first.

The load method must be called before this one. Otherwise ManagerError will be raised.

exception evasion.agency.manager.ManagerError[source]

Bases: exceptions.Exception

Raised for problems occuring in the agent manager.

evasion.agency.manager.get_log()[source]

utils Module

evasion.agency.utils.log_init(level)[source]

Used mainly in testing to create a default catch all logging set up

This set up catches all channels regardless of whether they are in other projects or in our own project.