mailr9417 - /1.3/prompt/base_class.py


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

Header


Content

Posted by edward on August 31, 2009 - 19:07:
Author: bugman
Date: Mon Aug 31 19:07:18 2009
New Revision: 9417

URL: http://svn.gna.org/viewcvs/relax?rev=9417&view=rev
Log:
Added __description__ strings to the user function class relax help strings.

The __strip_lead() method has been added to User_fn_class to remove leading 
whitespace from the
__description__ strings.


Modified:
    1.3/prompt/base_class.py

Modified: 1.3/prompt/base_class.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/base_class.py?rev=9417&r1=9416&r2=9417&view=diff
==============================================================================
--- 1.3/prompt/base_class.py (original)
+++ 1.3/prompt/base_class.py Mon Aug 31 19:07:18 2009
@@ -25,6 +25,7 @@
 
 # relax module imports.
 import help
+from string import split, strip
 
 
 
@@ -53,3 +54,45 @@
 
         # Place relax in the class namespace.
         self.__relax__ = relax
+
+        # Add a description to the help string.
+        if hasattr(self, '__description__'):
+            self.__relax_help__ = self.__relax_help__ + "\n\n" + 
self.__strip_lead(self.__description__)
+
+
+    def __strip_lead(self, text):
+        """Strip the leading whitespace from the given text.
+
+        @param text:    The text to strip the leading whitespace from.
+        @type text:     str
+        @return:        The text with leading whitespace removed.
+        @rtype:         str
+        """
+
+        # Split by newline.
+        lines = split(text, '\n')
+
+        # Find the minimum whitespace.
+        min_white = 1000
+        for line in lines:
+            # Empty lines.
+            if strip(line) == '':
+                continue
+
+            # Count the whitespace for the current line.
+            num_white = 0
+            for i in range(len(line)):
+                if line[i] != ' ':
+                    break
+                num_white = num_white + 1
+
+            # The min value.
+            min_white = min(min_white, num_white)
+
+        # Strip the whitespace.
+        new_text = ''
+        for line in lines:
+            new_text = new_text + line[min_white:] + '\n'
+
+        # Return the new text.
+        return new_text




Related Messages


Powered by MHonArc, Updated Wed Sep 02 21:20:10 2009