Author: tmckay
Date: 2011-07-18 16:29:58 +0000 (Mon, 18 Jul 2011)
New Revision: 4876
Added:
trunk/sage/python/sage/catalog.py
Removed:
trunk/sage/python/sage/remoteoperations.py
Modified:
trunk/cumin/python/cumin/main.py
trunk/sage/python/sage/qmf/qmfoperations.py
Log:
Change name of RemoteOperations to Catalog.
Modified: trunk/cumin/python/cumin/main.py
===================================================================
--- trunk/cumin/python/cumin/main.py 2011-07-15 20:23:00 UTC (rev 4875)
+++ trunk/cumin/python/cumin/main.py 2011-07-18 16:29:58 UTC (rev 4876)
@@ -21,7 +21,7 @@
from user import *
from util import *
from widgets import *
-from sage.remoteoperations import RemoteOperations
+from sage.catalog import Catalog
from sage.qmf.qmfoperations import QmfOperations
from wooly import Session
from cumin.stat import PieChartPage
@@ -158,7 +158,7 @@
# Create RPC interfaces for QMF and aviary.
# Aviary takes precedence if added
- self.remote = RemoteOperations()
+ self.remote = Catalog()
ops = [QmfOperations("qmf", self.session)]
if self.use_aviary:
from sage.aviary.aviaryoperations import AviaryOperations
Copied: trunk/sage/python/sage/catalog.py (from rev 4875,
trunk/sage/python/sage/remoteoperations.py)
===================================================================
--- trunk/sage/python/sage/catalog.py (rev 0)
+++ trunk/sage/python/sage/catalog.py 2011-07-18 16:29:58 UTC (rev 4876)
@@ -0,0 +1,56 @@
+class Catalog(object):
+ '''
+ Wrapper class that allows multiple interface classes to be grouped
+ together and referenced through a single object. Details of which
+ class provides the implementation of a method can be ignored by the
+ caller. See add_mechanisms comments below.
+ '''
+ def __init__(self):
+ self.mechanisms = []
+
+ def add_mechanisms(self, mechs):
+ '''
+ Add an item or items to the list of supported mechanisms.
+ A mechanism is expected to be an instance of a class containing
+ "public" methods that implement some interface.
+ When attribute access is done on an instance of Catalog,
+ the mechanism list is searched in order for a class which contains
+ a method of the given name (assuming the attribute is not contained
+ directly in the Catalog instance itself). This allows methods
+ on mechanism objects to be called as if they are attributes of
+ Catalog, without the caller having knowledge of which mechanism
+ ultimately provides the method.
+ If a mechanism object has an attribute called 'name', a reference to the
+ object is added as an attribute of Catalog named 'name'. This
+ allows a specific mechamism to be used if desired (for example,
+ the hold_job method might be invoked as catalog.qmf.hold_job(), ensuring
+ that the QMF version is used, rather than catalog.hold_job() which will
+ use the first hold_job method located in the mechanism list).
+ '''
+
+ # Allow mechanism to be specifially chosen by name
+ # rather than determined by precedence order
+ # catalog.qmf.Op() vs catalog.Op(), for example
+ def make_mech_attr(m):
+ if hasattr(m, "name"):
+ setattr(self, m.name, m)
+
+ if type(mechs) in (tuple, list):
+ for m in mechs:
+ self.mechanisms.append(m)
+ make_mech_attr(m)
+ else:
+ self.mechanisms.append(mechs)
+ make_mech_attr(mechs)
+
+ def __getattr__(self, name):
+ # Reminder, __getattr__ is called when an attribute
+ # cannot be found in the object.
+ for m in self.mechanisms:
+ if hasattr(m, name):
+ a = getattr(m, name)
+ if callable(a):
+ return a
+ raise AttributeError("No mechanism has callable %s" % name)
+
+
Modified: trunk/sage/python/sage/qmf/qmfoperations.py
===================================================================
--- trunk/sage/python/sage/qmf/qmfoperations.py 2011-07-15 20:23:00 UTC (rev 4875)
+++ trunk/sage/python/sage/qmf/qmfoperations.py 2011-07-18 16:29:58 UTC (rev 4876)
@@ -22,7 +22,7 @@
def __init__(self, name, session):
'''
- If this object is added to a RemoteOperations object as a mechanism,
+ If this object is added to a Catalog object as a mechanism,
the 'name' parameter will be used to create an attribute which points
to this object.
The 'session' parameter is expected to be an object that defines the
Deleted: trunk/sage/python/sage/remoteoperations.py
===================================================================
--- trunk/sage/python/sage/remoteoperations.py 2011-07-15 20:23:00 UTC (rev 4875)
+++ trunk/sage/python/sage/remoteoperations.py 2011-07-18 16:29:58 UTC (rev 4876)
@@ -1,51 +0,0 @@
-class RemoteOperations(object):
-
- def __init__(self):
- self.mechanisms = []
-
- def add_mechanisms(self, mechs):
- '''
- Add an item or items to the list of supported mechanisms.
- A mechanism is expected to be an instance of a class containing
- methods that implement remote procedure calls.
- When attribute access is done on an instance of RemoteOperations,
- the mechanism list is searched in order for a class which contains
- a method of the given name (assuming the attribute is not contained
- directly in the RemoteOperations instance itself). This allows methods
- on mechanism objects to be called as if they are attributes of
- RemoteOperations, without the caller having knowledge of which mechanism
- ultimately provides the method.
- If a mechanism object has an attribute called 'name', a reference to the
- object is added as an attribute of RemoteOperations named 'name'. This
- allows a specific mechamism to be used if desired (for example,
- the hold_job method might be invoked as remote.qmf.hold_job(), ensuring
- that the QMF version is used, rather than remote.hold_job() which will
- use the first hold_job method located in the mechanism list).
- '''
-
- # Allow mechanism to be specifially chosen by name
- # rather than determined by precedence order
- # remote.qmf.Op() vs remote.Op(), for example
- def make_mech_attr(m):
- if hasattr(m, "name"):
- setattr(self, m.name, m)
-
- if type(mechs) in (tuple, list):
- for m in mechs:
- self.mechanisms.append(m)
- make_mech_attr(m)
- else:
- self.mechanisms.append(mechs)
- make_mech_attr(mechs)
-
- def __getattr__(self, name):
- # Reminder, __getattr__ is called when an attribute
- # cannot be found in the object.
- for m in self.mechanisms:
- if hasattr(m, name):
- a = getattr(m, name)
- if callable(a):
- return a
- raise AttributeError("No mechanism has callable %s" % name)
-
-