Skip to content
This repository has been archived by the owner on Aug 4, 2019. It is now read-only.

Commit

Permalink
working on fixes for 1.1.4 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Oisin Mulvihill committed Dec 8, 2011
1 parent db37046 commit 545f698
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 367 deletions.
File renamed without changes.
30 changes: 13 additions & 17 deletions lib/evasion/agency/__init__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
"""
:mod:`agency`
:mod:`agency`
==============
.. module:: 'agency'
.. moduleauthor:: Oisin Mulvihill <oisin.mulvihill@gmail.com>
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
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.
.. data:: agency.agency.AGENT_CATEGORIES
.. autoclass:: agency.agency.Nodes
:members:
:undoc-members:
.. autofunction:: agency.agency.shutdown()
.. autofunction:: agency.agency.shutdown()
.. automodule:: agency.agency
.. automodule:: agency.agent
.. automodule:: agency.agents
.. automodule:: agency.config
.. automodule:: agency.manager
"""
"""
import logging

import agent
import agency
import config
import agents
import manager
from agency import *
from config import ConfigError
from manager import ManagerError


Expand Down
57 changes: 27 additions & 30 deletions lib/evasion/agency/agency.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
import logging
import itertools

import agent
import config
import agents
import manager
from config import ConfigError
from manager import ManagerError
from evasion.director.config import ConfigError


__all__ = ['AGENT_CATEGORIES', 'Nodes', 'shutdown', 'node', 'manager']
Expand All @@ -16,10 +13,10 @@ def get_log():


AGENT_CATEGORIES = {
'display' : 'This is the category for message output to some kind of physical display.',
'cashdrawer' : 'This is the category for cash drawer access.',
'printer' : 'This is the category for output to paper and other printed media.',
'sale' : 'This is the category for point of sale agents fit under to process card/chip and pin payments.',
'display' : 'This is the category for message output to some kind of physical display.',
'cashdrawer' : 'This is the category for cash drawer access.',
'printer' : 'This is the category for output to paper and other printed media.',
'sale' : 'This is the category for point of sale agents fit under to process card/chip and pin payments.',
'swipe' : 'This is the category for magnetic card swipe agents.',
'websale' : 'This is the category for web-based sale agents.',
'service' : 'This represent some web or other type of networked service',
Expand All @@ -28,15 +25,15 @@ def get_log():


class Nodes(object):
"""This class manages the node and alias id string generation, based
"""This class manages the node and alias id string generation, based
on the agent category currently found in agency.AGENT_CATEGORIES.
"""
def __init__(self):
self.counters = {}
self._aliasGen = None # setup by reset.
self._reset()


def _reset(self):
"""Used in unittesting to reset the internal counts.
Expand All @@ -50,68 +47,68 @@ def _reset(self):
def add(self, cat, cat_name, alias=None):
"""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.
"""
if cat not in AGENT_CATEGORIES:
raise ValueError("Unknown agent class '%s'. Is this a missing one?" % cat)

if not alias:
alias = self._aliasGen.next()

self.counters[cat] += 1
node_id = "/agent/%s/%s/%d" % (cat, cat_name, self.counters[cat])
try:
alias = int(alias)
except TypeError,e:
except TypeError:
raise ConfigError("The alias must be an integer not '%s'." % alias)

alias_id = "/agent/%s/%d" % (cat, alias)

return node_id, alias_id


def get(self, cat):
"""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.
"""
if cat not in AGENT_CATEGORIES:
raise ValueError("Unknown agent category '%s'. Is this a missing one?" % cat)

return self.counters[cat]
# Singleton instances:

# Singleton instances:
#
node = Nodes()
manager = manager.Manager()
Expand Down
35 changes: 20 additions & 15 deletions lib/evasion/agency/agent.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
# -*- coding: utf-8 -*-
"""
:mod:`agency.agent`
:mod:`agency.agent`
====================
.. module:: 'agency.agent'
:platform: Unix, MacOSX, Windows
:synopsis: This provides the base agent interface.
.. moduleauthor:: Oisin Mulvihill <oisin.mulvihill@gmail.com>
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.
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.
.. autoclass:: agency.agent.Base
:members:
:undoc-members:
"""
import logging


class Base(object):
"""Base class agent entry.
"""
_log = logging.getLogger("evasion.agency.agent.Base")


def setUp(self, config):
"""Called to set up the agent and subscribe for any events
it may be interested in.
"""


def tearDown(self):
"""Called to cleanup and release any resources the agent
may be using.
This is usually done by the agent manager before the
"""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.
"""


def start(self):
"""Called to start any processing the agent may need to do.
This function maybe used to start any threads polling a
agent for example.
"""


def stop(self):
"""Called to stop any processing the agent may be doing.
"""Called to stop any processing the agent may be doing.
The start function may be called to resume operation.
"""


Expand Down
28 changes: 15 additions & 13 deletions lib/evasion/agency/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""
:mod:`agency.agents`
=====================
.. module:: 'agency.agents'
.. moduleauthor:: Oisin Mulvihill <oisin.mulvihill@gmail.com>
# -*- coding: utf-8 -*-
"""
:mod:`agency.agents`
=====================
.. module:: 'agency.agents'
.. moduleauthor:: Oisin Mulvihill <oisin.mulvihill@gmail.com>
This module provides a basic of agents which can be built on or used as an
example. The `agency.agents.base` provides some handy base Agent which can be
extended further. The `agency.agents.testing` is used for example purposes and
for unit testing the agency.
This module provides a basic of agents which can be built on or used as an example. The
`agency.agents.base` provides some handy base Agent which can be extended further. The
`agency.agents.testing` is used for example purposes and for unit testing the agency.
.. automodule:: agency.agents.base
.. automodule:: agency.agents.testing
.. automodule:: agency.agents.testing
"""
import base
import testing
13 changes: 3 additions & 10 deletions lib/evasion/agency/agents/base/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
:mod:`agency.agents.base.service`
==================================
Expand All @@ -15,24 +16,16 @@
:undoc-members:
"""
import uuid
import time
import json
import pprint
import socket
import thread
import urllib2
import logging
import urlparse
import datetime
import xmlrpclib
import SocketServer
import SimpleHTTPServer
import SimpleXMLRPCServer


from evasion.agency import agent
from pydispatch import dispatcher



Expand Down Expand Up @@ -213,7 +206,7 @@ def _start(data=0):
self.log.info("XML-RPC Service URI 'http://%s:%s'" % (i,p))
try:
self.server.serve_forever()
except TypeError,e:
except TypeError:
# caused by ctrl-c. Its ok
pass

Expand Down Expand Up @@ -377,7 +370,7 @@ def _start(data=0):
self.log.info("Web Service URI 'http://%s:%s'" % (i,p))
try:
self.server.serve_forever()
except TypeError,e:
except TypeError:
# caused by ctrl-c. Its ok
pass

Expand Down
9 changes: 5 additions & 4 deletions lib/evasion/agency/agents/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
:mod:`agency.agents.testing` -- These are agents used for testing purposes or as usage examples
=================================================================================================
Expand All @@ -7,7 +8,7 @@
.. automodule:: agency.agents.testing.fake
"""
import fake


"""
import fake

0 comments on commit 545f698

Please sign in to comment.