[cig-commits] r11238 - cs/pythia/trunk/pyre/inventory
leif at geodynamics.org
leif at geodynamics.org
Mon Feb 25 18:20:50 PST 2008
Author: leif
Date: 2008-02-25 18:20:50 -0800 (Mon, 25 Feb 2008)
New Revision: 11238
Added:
cs/pythia/trunk/pyre/inventory/FacilityArrayFacility.py
Modified:
cs/pythia/trunk/pyre/inventory/__init__.py
Log:
Issue141: dynamic arrays of components.
Added: cs/pythia/trunk/pyre/inventory/FacilityArrayFacility.py
===================================================================
--- cs/pythia/trunk/pyre/inventory/FacilityArrayFacility.py (rev 0)
+++ cs/pythia/trunk/pyre/inventory/FacilityArrayFacility.py 2008-02-26 02:20:50 UTC (rev 11238)
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+# California Institute of Technology
+# (C) 2008 All Rights Reserved
+#
+# {LicenseText}
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+
+from pyre.inventory.Facility import Facility
+
+
+class FacilityArrayFacility(Facility):
+
+
+ def __init__(self, name, itemFactory, **kwds):
+ Facility.__init__(self, name=name, **kwds)
+ self.itemFactory = itemFactory
+ return
+
+
+ def _retrieveComponent(self, instance, componentName):
+ facilityNames = self._cast(componentName)
+
+ dict = {}
+ for facilityName in facilityNames:
+ facility = self.itemFactory(facilityName)
+ dict[facility] = facility
+
+ from Inventory import Inventory
+ from pyre.components.Component import Component
+
+ Inventory = Inventory.__metaclass__("FacilityArray.Inventory", (Component.Inventory,), dict)
+
+ dict = {'Inventory': Inventory}
+ FacilityArray = Component.__metaclass__("FacilityArray", (Component,), dict)
+ fa = FacilityArray(self.name)
+
+ import pyre.parsing.locators
+ locator = pyre.parsing.locators.builtIn()
+
+ return fa, locator
+
+
+ def _cast(self, text):
+ if isinstance(text, basestring):
+ if text and text[0] in '[({':
+ text = text[1:]
+ if text and text[-1] in '])}':
+ text = text[:-1]
+
+ value = text.split(",")
+
+ # allow trailing comma
+ if len(value) and not value[-1]:
+ value.pop()
+ else:
+ value = text
+
+ if isinstance(value, list):
+ return value
+
+ raise TypeError("facility '%s': could not convert '%s' to a list" % (self.name, text))
+
+
+
+# end of file
Modified: cs/pythia/trunk/pyre/inventory/__init__.py
===================================================================
--- cs/pythia/trunk/pyre/inventory/__init__.py 2008-02-26 02:08:43 UTC (rev 11237)
+++ cs/pythia/trunk/pyre/inventory/__init__.py 2008-02-26 02:20:50 UTC (rev 11238)
@@ -18,6 +18,11 @@
return Facility(name, **kwds)
+def facilityArray(name, **kwds):
+ from FacilityArrayFacility import FacilityArrayFacility
+ return FacilityArrayFacility(name, **kwds)
+
+
def curator(name):
from odb.Curator import Curator
return Curator(name)
More information about the cig-commits
mailing list