summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2009-02-06 13:48:39 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2009-02-06 13:48:39 +0000
commit4fdcf8c4e7cf699ef9a016631c4d1d1434fd69ca (patch)
treedad752495dd0a0562bf3bb9685ff2cd012b1b703
parentb6fbfd52490da6dcb282f56d61aebaa830d6be45 (diff)
downloadATCD-4fdcf8c4e7cf699ef9a016631c4d1d1434fd69ca.tar.gz
ChangeLogTag: Fri Feb 6 13:44:54 UTC 2009 William R. Otte <wotte@dre.vanderbilt.edu>
-rw-r--r--flat/CIAO/ChangeLog21
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/__init__.py1
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/__init__.py46
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/_path.py0
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/artifact.py24
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_impl.py57
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_inst.py13
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/footer.py8
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/header.py13
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_impl.py57
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_inst.py13
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_impl.py13
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_inst.py24
-rwxr-xr-xflat/CIAO/DAnCE/bin/PythonDAnCE/generator/templet.py325
-rwxr-xr-xflat/CIAO/DAnCE/bin/generate_plan.py75
15 files changed, 690 insertions, 0 deletions
diff --git a/flat/CIAO/ChangeLog b/flat/CIAO/ChangeLog
index 01ba3e19397..48bf065f6f1 100644
--- a/flat/CIAO/ChangeLog
+++ b/flat/CIAO/ChangeLog
@@ -1,3 +1,24 @@
+Fri Feb 6 13:44:54 UTC 2009 William R. Otte <wotte@dre.vanderbilt.edu>
+
+ * DAnCE/bin/PythonDAnCE:
+ * DAnCE/bin/PythonDAnCE/__init__.py:
+ * DAnCE/bin/PythonDAnCE/generator:
+ * DAnCE/bin/PythonDAnCE/generator/__init__.py:
+ * DAnCE/bin/PythonDAnCE/generator/_path.py:
+ * DAnCE/bin/PythonDAnCE/generator/artifact.py:
+ * DAnCE/bin/PythonDAnCE/generator/comp_impl.py:
+ * DAnCE/bin/PythonDAnCE/generator/comp_inst.py:
+ * DAnCE/bin/PythonDAnCE/generator/footer.py:
+ * DAnCE/bin/PythonDAnCE/generator/header.py:
+ * DAnCE/bin/PythonDAnCE/generator/home_impl.py:
+ * DAnCE/bin/PythonDAnCE/generator/home_inst.py:
+ * DAnCE/bin/PythonDAnCE/generator/homed_comp_impl.py:
+ * DAnCE/bin/PythonDAnCE/generator/homed_comp_inst.py:
+ * DAnCE/bin/PythonDAnCE/generator/templet.py:
+ * DAnCE/bin/generate_plan.py:
+
+ First cut implementation of a very simple cdp generator.
+
Thu Feb 5 19:36:49 UTC 2009 William R. Otte <wotte@dre.vanderbilt.edu>
* ofccm/DAnCE_Scripts:
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/__init__.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/__init__.py
new file mode 100755
index 00000000000..0ebbdbeba93
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/__init__.py
@@ -0,0 +1 @@
+import generator
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/__init__.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/__init__.py
new file mode 100755
index 00000000000..641e463cdaa
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/__init__.py
@@ -0,0 +1,46 @@
+temp_path = ""
+
+
+# # The following is the initialization logic that is executed
+# # when the fuzz module is loaded
+# from os import listdir, chdir, getcwd
+# from sys import stderr, path
+# oldwd = getcwd ()
+
+# try:
+# # The following is a trick to get the directory THIS SCRIPT - note, not necessarily the CWD -
+# # is located. We use this path later to load all of the available templates
+# import _path
+# script_path = str (_path).split ()[3][1:-11]
+# if script_path == "":
+# script_path = "."
+
+# chdir (script_path + "/templates")
+
+# path.append (getcwd ())
+
+# files = listdir (".")
+
+# modules = list ()
+
+
+# for item in files:
+# if (item[0] != '_') and (item[-3:] == ".py"):
+# print "Registering " + item [:-3]
+# try:
+# __import__ (item[:-3])
+# except:
+# stderr.write ("ERROR: Unable to load the " + item[:-3] + " template\n")
+
+# finally:
+# chdir (oldwd)
+
+import header
+import comp_impl
+import comp_inst
+import footer
+import homed_comp_impl
+import homed_comp_inst
+import home_impl
+import home_inst
+import artifact
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/_path.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/_path.py
new file mode 100755
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/_path.py
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/artifact.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/artifact.py
new file mode 100755
index 00000000000..07b3e897448
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/artifact.py
@@ -0,0 +1,24 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name):
+ """
+ <artifact xmi:id="${component_name}ExecArtifact">
+ <name>${component_name}_exec</name>
+ <source/>
+ <node/>
+ <location>${component_name}_exec</location>
+ </artifact>
+ <artifact xmi:id="${component_name}SvntArtifact">
+ <name>${component_name}_svnt</name>
+ <source/>
+ <node/>
+ <location>${component_name}_svnt</location>
+ </artifact>
+ <artifact xmi:id="${component_name}StubArtifact">
+ <name>${component_name}_stub</name>
+ <source/>
+ <node/>
+ <location>${component_name}_stub</location>
+ </artifact>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_impl.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_impl.py
new file mode 100755
index 00000000000..eb709fb4e51
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_impl.py
@@ -0,0 +1,57 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name) :
+ """
+ <implementation xmi:id="${component_name}ComponentImplementation">
+ <name>${component_name}ComponentImplementation</name>
+ <source/>
+ <artifact xmi:idref="${component_name}_ExecArtifact" />
+ <artifact xmi:idref="${component_name}_SvntArtifact" />
+ <execParameter>
+ <!-- entrypoint as exec parameter (see 10.6.1) -->
+ <name>component factory</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>create_Simple_${component_name}_Impl</string>
+ </value>
+ </value>
+ </execParameter>
+ <execParameter>
+ <name>edu.vanderbilt.dre.CIAO.ServantEntrypoint</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>create_Simple_${component_name}_Servant</string>
+ </value>
+ </value>
+ </execParameter>
+ <execParameter>
+ <name>edu.vanderbilt.dre.CIAO.ServantArtifact</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>${component_name}_svnt</string>
+ </value>
+ </value>
+ </execParameter>
+ <execParameter>
+ <name>edu.vanderbilt.dre.CIAO.ExecutorArtifact</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>${component_name}_exec</string>
+ </value>
+ </value>
+ </execParameter>
+ </implementation>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_inst.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_inst.py
new file mode 100755
index 00000000000..7bacf681616
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/comp_inst.py
@@ -0,0 +1,13 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name) :
+ """
+ <instance xmi:id="${component_name}ComponentInstance">
+ <name>${component_name}Component</name>
+ <node>Node</node>
+ <!-- hostname -->
+ <source/>
+ <implementation xmi:idref="${component_name}ComponentImplementation" />
+ </instance>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/footer.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/footer.py
new file mode 100755
index 00000000000..687cfb78a02
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/footer.py
@@ -0,0 +1,8 @@
+from templet import stringfunction
+
+@stringfunction
+def template ():
+ """
+</Deployment:DeploymentPlan>
+"""
+
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/header.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/header.py
new file mode 100755
index 00000000000..60dc096dd83
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/header.py
@@ -0,0 +1,13 @@
+from templet import stringfunction
+
+@stringfunction
+def template (uuid):
+ """
+<Deployment:DeploymentPlan
+ xmlns:Deployment="http://www.omg.org/Deployment"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.omg.org/Deployment Deployment.xsd">
+ <label>${uuid}</label>
+ <UUID>${uuid}</UUID>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_impl.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_impl.py
new file mode 100755
index 00000000000..18da2fc27b3
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_impl.py
@@ -0,0 +1,57 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name) :
+ """
+ <implementation xmi:id="${component_name}HomeImplementation">
+ <name>${component_name}HomeImplementation</name>
+ <source/>
+ <artifact xmi:idref="${component_name}_ExecArtifact" />
+ <artifact xmi:idref="${component_name}_SvntArtifact" />
+ <execParameter>
+ <!-- entrypoint as exec parameter (see 10.6.1) -->
+ <name>home factory</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>create_Simple_${component_name}Home_Impl</string>
+ </value>
+ </value>
+ </execParameter>
+ <execParameter>
+ <name>edu.vanderbilt.dre.CIAO.ServantEntrypoint</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>create_Simple_${component_name}Home_Servant</string>
+ </value>
+ </value>
+ </execParameter>
+ <execParameter>
+ <name>edu.vanderbilt.dre.CIAO.ServantArtifact</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>${component_name}_svnt</string>
+ </value>
+ </value>
+ </execParameter>
+ <execParameter>
+ <name>edu.vanderbilt.dre.CIAO.ExecutorArtifact</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>${component_name}_exec</string>
+ </value>
+ </value>
+ </execParameter>
+ </implementation>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_inst.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_inst.py
new file mode 100755
index 00000000000..6d24a5c5986
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/home_inst.py
@@ -0,0 +1,13 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name) :
+ """
+ <instance xmi:id="${component_name}HomeInstance">
+ <name>${component_name}Home</name>
+ <node>NodeOne</node>
+ <!-- hostname -->
+ <source/>
+ <implementation xmi:idref="${component_name}HomeImplementation" />
+ </instance>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_impl.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_impl.py
new file mode 100755
index 00000000000..ab8a7ee9517
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_impl.py
@@ -0,0 +1,13 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name) :
+ """
+ <implementation xmi:id="${component_name}ComponentImplementation">
+ <name>${component_name}ComponentImplementation</name>
+ <source/>
+ <artifact xmi:idref="${component_name}_ExecArtifact" />
+ <artifact xmi:idref="${component_name}_SvntArtifact" />
+ <artifact xmi:idref="${component_name}_StubArtifact" />
+ </implementation>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_inst.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_inst.py
new file mode 100755
index 00000000000..ee1218d4539
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/homed_comp_inst.py
@@ -0,0 +1,24 @@
+from templet import stringfunction
+
+@stringfunction
+def template (component_name) :
+ """
+ <instance xmi:id="${component_name}ComponentInstance">
+ <name>${component_name}Component</name>
+ <node>NodeOne</node>
+ <!-- hostname -->
+ <source/>
+ <implementation xmi:idref="${component_name}ComponentImplementation" />
+ <configProperty>
+ <name>edu.vanderbilt.dre.DAnCE.ExplicitHome</name>
+ <value>
+ <type>
+ <kind>tk_string</kind>
+ </type>
+ <value>
+ <string>${component_name}Home</string>
+ </value>
+ </value>
+ </configProperty>
+ </instance>
+ """
diff --git a/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/templet.py b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/templet.py
new file mode 100755
index 00000000000..85cfb9f0389
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/PythonDAnCE/generator/templet.py
@@ -0,0 +1,325 @@
+"""A lightweight python templating engine. Templet version 2 beta.
+
+Supports two templating idioms:
+ 1. template functions using @stringfunction and @unicodefunction
+ 2. template classes inheriting from StringTemplate and UnicodeTemplate
+
+Each template function is marked with the attribute @stringfunction
+or @unicodefunction. Template functions will be rewritten to expand
+their document string as a template and return the string result.
+For example:
+
+ @stringtemplate
+ def myTemplate(animal, thing):
+ "the $animal jumped over the $thing."
+
+ print myTemplate('cow', 'moon')
+
+The template language understands the following forms:
+
+ $myvar - inserts the value of the variable 'myvar'
+ ${...} - evaluates the expression and inserts the result
+ ${{...}} - executes enclosed code; use 'out.append(text)' to insert text
+ $$ - an escape for a single $
+ $ (at the end of the line) - a line continuation
+
+Template functions are compiled into code that accumulates a list of
+strings in a local variable 'out', and then returns the concatenation
+of them. If you want do do complicated computation, you can append
+to 'out' directly inside a ${{...}} block.
+
+Another alternative is to use template classes.
+
+Each template class is a subclass of StringTemplate or UnicodeTemplate.
+Template classes should define a class attribute 'template' that
+contains the template code. Also, any class attribute ending with
+'_template' will be compiled into a template method.
+
+Use a template class by instantiating it with a dictionary or
+keyword arguments. Get the expansion by converting the instance
+to a string. For example:
+
+ class MyTemplate(templet.Template):
+ template = "the $animal jumped over the $thing."
+
+ print MyTemplate(animal='cow', thing='moon')
+
+Within a template class, the template language is similar to a template
+function, but 'self.write' should be used to build the string inside
+${{..}} blocks. Also, there is a shorthand for calling template methods:
+
+ $<sub_template> - shorthand for '${{self.sub_template(vars())}}'
+
+This idiom is helpful for decomposing a template and when subclassing.
+
+A longer example:
+
+ import cgi
+ class RecipeTemplate(templet.Template):
+ template = r'''
+ <html><head><title>$dish</title></head>
+ <body>
+ $<header_template>
+ $<body_template>
+ </body></html>
+ '''
+ header_template = r'''
+ <h1>${cgi.escape(dish)}</h1>
+ '''
+ body_template = r'''
+ <ol>
+ ${{
+ for item in ingredients:
+ self.write('<li>', item, '\n')
+ }}
+ </ol>
+ '''
+
+This template can be expanded as follows:
+
+ print RecipeTemplate(dish='burger', ingredients=['bun', 'beef', 'lettuce'])
+
+And it can be subclassed like this:
+
+ class RecipeWithPriceTemplate(RecipeTemplate):
+ header_template = "<h1>${cgi.escape(dish)} - $$$price</h1>\n"
+
+Templet is by David Bau and was inspired by Tomer Filiba's Templite class.
+For details, see http://davidbau.com/templet
+
+Templet is posted by David Bau under BSD-license terms.
+
+Copyright (c) 2007, David Bau
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of Templet nor the names of its contributors may
+ be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+"""
+
+import sys, re, inspect
+
+class _TemplateBuilder(object):
+ __pattern = re.compile(r"""\$( # Directives begin with a $
+ \$ | # $$ is an escape for $
+ [^\S\n]*\n | # $\n is a line continuation
+ [_a-z][_a-z0-9]* | # $simple Python identifier
+ \{(?!\{)[^\}]*\} | # ${...} expression to eval
+ \{\{.*?\}\} | # ${{...}} multiline code to exec
+ <[_a-z][_a-z0-9]*> | # $<sub_template> method call
+ )(?:(?:(?<=\}\})|(?<=>))[^\S\n]*\n)? # eat some trailing newlines
+ """, re.IGNORECASE | re.VERBOSE | re.DOTALL)
+
+ def __init__(self, constpat, emitpat, callpat=None):
+ self.constpat, self.emitpat, self.callpat = constpat, emitpat, callpat
+
+ def __realign(self, str, spaces=''):
+ """Removes any leading empty columns of spaces and an initial empty line"""
+ lines = str.splitlines();
+ if lines and not lines[0].strip(): del lines[0]
+ lspace = [len(l) - len(l.lstrip()) for l in lines if l.lstrip()]
+ margin = len(lspace) and min(lspace)
+ return '\n'.join((spaces + l[margin:]) for l in lines)
+
+ def build(self, template, filename, s=''):
+ code = []
+ for i, part in enumerate(self.__pattern.split(self.__realign(template))):
+ if i % 2 == 0:
+ if part: code.append(s + self.constpat % repr(part))
+ else:
+ if not part or (part.startswith('<') and self.callpat is None):
+ raise SyntaxError('Unescaped $ in ' + filename)
+ elif part.endswith('\n'): continue
+ elif part == '$': code.append(s + self.emitpat % '"$"')
+ elif part.startswith('{{'): code.append(self.__realign(part[2:-2], s))
+ elif part.startswith('{'): code.append(s + self.emitpat % part[1:-1])
+ elif part.startswith('<'): code.append(s + self.callpat % part[1:-1])
+ else: code.append(s + self.emitpat % part)
+ return '\n'.join(code)
+
+class _TemplateMetaClass(type):
+ __builder = _TemplateBuilder(
+ 'self.out.append(%s)', 'self.write(%s)', 'self.%s(vars())')
+
+ def __compile(cls, template, n):
+ globals = sys.modules[cls.__module__].__dict__
+ if '__file__' not in globals: filename = '<%s %s>' % (cls.__name__, n)
+ else: filename = '%s: <%s %s>' % (globals['__file__'], cls.__name__, n)
+ code = compile(cls.__builder.build(template, filename), filename, 'exec')
+ def expand(self, __dict = None, **kw):
+ if __dict: kw.update([i for i in __dict.iteritems() if i[0] not in kw])
+ kw['self'] = self
+ exec code in globals, kw
+ return expand
+
+ def __init__(cls, *args):
+ for attr, val in cls.__dict__.items():
+ if attr == 'template' or attr.endswith('_template'):
+ if isinstance(val, basestring):
+ setattr(cls, attr, cls.__compile(val, attr))
+ type.__init__(cls, *args)
+
+class StringTemplate(object):
+ """A base class for string template classes."""
+ __metaclass__ = _TemplateMetaClass
+
+ def __init__(self, *args, **kw):
+ self.out = []
+ self.template(*args, **kw)
+
+ def write(self, *args):
+ self.out.extend([str(a) for a in args])
+
+ def __str__(self):
+ return ''.join(self.out)
+
+# The original version of templet called StringTemplate "Template"
+Template = StringTemplate
+
+class UnicodeTemplate(object):
+ """A base class for unicode template classes."""
+ __metaclass__ = _TemplateMetaClass
+
+ def __init__(self, *args, **kw):
+ self.out = []
+ self.template(*args, **kw)
+
+ def write(self, *args):
+ self.out.extend([unicode(a) for a in args])
+
+ def __unicode__(self):
+ return u''.join(self.out)
+
+ def __str__(self):
+ return unicode(self).encode('utf-8')
+
+def _templatefunction(func, listname, stringtype):
+ globals, locals = sys.modules[func.__module__].__dict__, {}
+ if '__file__' not in globals: filename = '<%s>' % func.__name__
+ else: filename = '%s: <%s>' % (globals['__file__'], func.__name__)
+ builder = _TemplateBuilder('%s.append(%%s)' % listname,
+ '%s.append(%s(%%s))' % (listname, stringtype))
+ args = inspect.getargspec(func)
+ code = [
+ 'def %s%s:' % (func.__name__, inspect.formatargspec(*args)),
+ ' %s = []' % listname,
+ builder.build(func.__doc__, filename, ' '),
+ ' return "".join(%s)' % listname]
+ code = compile('\n'.join(code), filename, 'exec')
+ exec code in globals, locals
+ return locals[func.__name__]
+
+def stringfunction(func):
+ """Function attribute for string template functions"""
+ return _templatefunction(func, listname='out', stringtype='str')
+
+def unicodefunction(func):
+ """Function attribute for unicode template functions"""
+ return _templatefunction(func, listname='out', stringtype='unicode')
+
+# When executed as a script, run some testing code.
+if __name__ == '__main__':
+ ok = True
+ def expect(actual, expected):
+ global ok
+ if expected != actual:
+ print "error - got:\n%s" % repr(actual)
+ ok = False
+ class TestAll(Template):
+ """A test of all the $ forms"""
+ template = r"""
+ Bought: $count ${name}s$
+ at $$$price.
+ ${{
+ for i in xrange(count):
+ self.write(TestCalls(vars()), "\n") # inherit all the local $vars
+ }}
+ Total: $$${"%.2f" % (count * price)}
+ """
+ class TestCalls(Template):
+ """A recursive test"""
+ template = "$name$i ${*[TestCalls(name=name[0], i=n) for n in xrange(i)]}"
+ expect(
+ str(TestAll(count=5, name="template call", price=1.23)),
+ "Bought: 5 template calls at $1.23.\n"
+ "template call0 \n"
+ "template call1 t0 \n"
+ "template call2 t0 t1 t0 \n"
+ "template call3 t0 t1 t0 t2 t0 t1 t0 \n"
+ "template call4 t0 t1 t0 t2 t0 t1 t0 t3 t0 t1 t0 t2 t0 t1 t0 \n"
+ "Total: $6.15\n")
+ class TestBase(Template):
+ template = r"""
+ <head>$<head_template></head>
+ <body>$<body_template></body>
+ """
+ class TestDerived(TestBase):
+ head_template = "<title>$name</title>"
+ body_template = "${TestAll(vars())}"
+ expect(
+ str(TestDerived(count=4, name="template call", price=2.88)),
+ "<head><title>template call</title></head>\n"
+ "<body>"
+ "Bought: 4 template calls at $2.88.\n"
+ "template call0 \n"
+ "template call1 t0 \n"
+ "template call2 t0 t1 t0 \n"
+ "template call3 t0 t1 t0 t2 t0 t1 t0 \n"
+ "Total: $11.52\n"
+ "</body>\n")
+ class TestUnicode(UnicodeTemplate):
+ template = u"""
+ \N{Greek Small Letter Pi} = $pi
+ """
+ expect(
+ unicode(TestUnicode(pi = 3.14)),
+ u"\N{Greek Small Letter Pi} = 3.14\n")
+ goterror = False
+ try:
+ class TestError(Template):
+ template = 'Cost of an error: $0'
+ except SyntaxError:
+ goterror = True
+ if not goterror:
+ print 'TestError failed'
+ ok = False
+ @stringfunction
+ def testBasic(name):
+ "Hello $name."
+ expect(testBasic('Henry'), "Hello Henry.")
+ @stringfunction
+ def testReps(a, count=5): r"""
+ ${{ if count == 0: return '' }}
+ $a${testReps(a, count - 1)}"""
+ expect(
+ testReps('foo'),
+ "foofoofoofoofoo")
+ @unicodefunction
+ def testUnicode(count=4): u"""
+ ${{ if not count: return '' }}
+ \N{BLACK STAR}${testUnicode(count - 1)}"""
+ expect(
+ testUnicode(count=10),
+ u"\N{BLACK STAR}" * 10)
+ if ok: print "OK"
diff --git a/flat/CIAO/DAnCE/bin/generate_plan.py b/flat/CIAO/DAnCE/bin/generate_plan.py
new file mode 100755
index 00000000000..212c2ce61b0
--- /dev/null
+++ b/flat/CIAO/DAnCE/bin/generate_plan.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+
+def parse_args ():
+ from optparse import OptionParser
+
+ parser = OptionParser ("""usage %prog [options]
+ Note that this script is very simple. It assumes that the idl and mpc follow
+ canonical and predictable patterns.""")
+
+ parser.add_option ("-o", "--output", dest="output", action="store", type="string",
+ help="Output filename", default="Plan.cdp")
+ parser.add_option ("--home", dest="homes", action="append", type="string",
+ help="Home types to be included")
+ parser.add_option ("-c", "--component", dest="components", action="append",
+ type="string", help="Component types to be included")
+ parser.add_option ("--homed-component", dest="homed_components", action="append",
+ type="string", help="Homed component types to be included")
+ parser.add_option ("-u", "--uuid", dest="uuid", action="store",
+ type="string", help="UUID for the generated plan")
+
+ (options, arguments) = parser.parse_args ()
+
+ return (options, arguments)
+
+def main ():
+ (opts, args) = parse_args ()
+
+ # compset = set (opts.homes) | set (opts.components) | set (homed_components)
+
+ from PythonDAnCE import generator
+ retval = ""
+ retval += generator.header.template (opts.uuid)
+
+ artifacts = {}
+
+ #implementations
+
+ for item in opts.homes:
+ retval += generator.home_impl.template (item)
+ artifacts[item] = 1
+
+ for item in opts.homed_components:
+ retval += generator.homed_comp_impl.template (item)
+ artifacts[item] = 1
+
+ for item in opts.components:
+ retval += generator.comp_impl.template (item)
+ artifacts[item] = 1
+
+ #instances
+ for item in opts.homes:
+ retval += generator.home_inst.template (item)
+
+ for item in opts.homed_components:
+ retval += generator.homed_comp_inst.template (item)
+
+ for item in opts.components:
+ retval += generator.comp_inst.template (item)
+
+ #artifacts
+ for item in artifacts.keys():
+ retval += generator.artifact.template(item)
+
+ retval += generator.footer.template ()
+
+ outfile = open (opts.output, 'w')
+ outfile.write (retval)
+ outfile.close ()
+
+
+if __name__ == "__main__":
+ main ()
+
+
+