mailr15942 - in /branches/uf_redesign/prompt: interpreter.py objects.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 03, 2012 - 23:07:
Author: bugman
Date: Thu May  3 23:07:49 2012
New Revision: 15942

URL: http://svn.gna.org/viewcvs/relax?rev=15942&view=rev
Log:
The documentation for the auto-generated user functions is now being created.

This is stored in the __relax_help__ string, and mimics the old system, 
reusing many of the base
functions.  All the user function data required for the prompt interface is 
now being passed in to
the object.


Modified:
    branches/uf_redesign/prompt/interpreter.py
    branches/uf_redesign/prompt/objects.py

Modified: branches/uf_redesign/prompt/interpreter.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/prompt/interpreter.py?rev=15942&r1=15941&r2=15942&view=diff
==============================================================================
--- branches/uf_redesign/prompt/interpreter.py (original)
+++ branches/uf_redesign/prompt/interpreter.py Thu May  3 23:07:49 2012
@@ -170,7 +170,7 @@
             class_name, uf_name = split(name, '.')
 
             # Generate a new container.
-            obj = Uf_object(name)
+            obj = Uf_object(name, title=data.title, kargs=data.kargs, 
desc=data.desc, examples=data.prompt_examples)
 
             # Get the class object.
             class_obj = self._locals[class_name]

Modified: branches/uf_redesign/prompt/objects.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/uf_redesign/prompt/objects.py?rev=15942&r1=15941&r2=15942&view=diff
==============================================================================
--- branches/uf_redesign/prompt/objects.py (original)
+++ branches/uf_redesign/prompt/objects.py Thu May  3 23:07:49 2012
@@ -24,8 +24,9 @@
 """Module containing the special objects for auto-generating the user 
functions and classes."""
 
 # relax module imports.
-from prompt.base_class import _strip_lead
+from prompt.base_class import _build_subtitle, _format_text, _strip_lead
 from prompt.help import relax_class_help
+from relax_errors import RelaxError
 
 
 class Class_container(object):
@@ -63,7 +64,7 @@
 class Uf_object(object):
     """The object for auto-generating the user functions."""
 
-    def __init__(self, name):
+    def __init__(self, name, title=None, kargs=None, desc=None, 
examples=None, additional=None):
         """Set up the object.
 
         @param name:    The name of the user function.
@@ -72,6 +73,18 @@
 
         # Store the args.
         self._name = name
+        self._title = title
+        self._kargs = kargs
+        self._desc = desc
+        self._examples = examples
+        self._additional = additional
+
+        # Check the args.
+        if title == None:
+            raise RelaxError("The title must be given.")
+
+        # Build the user function documentation.
+        self._build_doc()
 
 
     def __repr__(self):
@@ -79,3 +92,43 @@
 
         # Return a description.
         return "<The %s user function>" % self._name
+
+
+    def _build_doc(self):
+        """Create the user function documentation."""
+
+        # Initialise.
+        self.__relax_help__ = ""
+
+        # Add the title.
+        self.__relax_help__ = "%s%s\n" % (self.__relax_help__, self._title)
+
+        # Add the keyword args.
+        if self._kargs != None:
+            self.__relax_help__ += _build_subtitle("Keyword Arguments")
+            for i in range(len(self._kargs)):
+                # The text.
+                text = "%s:  %s" % (self._kargs[i]['name'], 
self._kargs[i]['desc'])
+
+                # Format.
+                text = _format_text(text)
+
+                # Add to the docstring.
+                self.__relax_help__ = "%s%s\n" % (self.__relax_help__, text)
+
+        # Add the description.
+        if self._desc != None:
+            self.__relax_help__ += _build_subtitle("Description")
+            self.__relax_help__ += _format_text(self._desc)
+
+        # Add the examples.
+        if self._examples != None:
+            self.__relax_help__ += '\n%s' % _build_subtitle("Examples")
+            self.__relax_help__ += _format_text(self._examples)
+
+        # Add the additional sections.
+        if self._additional != None:
+            # Loop over each section.
+            for i in range(len(self._additional)):
+                self.__relax_help__ += '\n%s' % 
_build_subtitle(self._additional[i][0])
+                self.__relax_help__ += _format_text(self._additional[i][1])




Related Messages


Powered by MHonArc, Updated Thu May 03 23:40:01 2012