Anonymous avatar Anonymous committed 46235cb

added class BoolArg

Comments (0)

Files changed (2)

+16-03-2006 Martin Woudstra
+	python/basic_trfarg.py: added class BoolArg
 14-03-2006 Martin Woudstra
 	cmt/requirements:
 	    - pattern declare_jobtransforms now uses standard paths

python/basic_trfarg.py

 defined in this file, and should override the member function isFullArgument(self),
 which should return True."""
     
-    def __init__(self,help,name):
+    def __init__(self,help,name='default'):
         """help    : short help string to help user fill in the argument
        name    : name of the argument (string)."""
         if help == 'default': help = self.defaultHelp()
     
 class IntegerArg( Argument ):
     """Basic argument type. Any integer. Only type is checked before running"""
-    def __init__(self,help,name):
+    def __init__(self,help,name='default'):
          Argument.__init__(self,help,name)
 
 
 
 class FloatArg( Argument ):
     """Basic argument type. Any float. Only type is checked before running"""
-    def __init__(self,help,name):
+    def __init__(self,help,name='default'):
         Argument.__init__(self,help,name)
 
 
 
 class StringArg( Argument ):
     """Basic argument type. Any string."""
-    def __init__(self,help,name):
+    def __init__(self,help,name='default'):
         Argument.__init__(self,help,name)
 
 
         return 'string'
 
 
+class BoolArg( Argument ):
+    """Basic argument type. A boolean. Recognised input (string) values:
+    '0' 'False' 'F' 'false' 'f'  : False (represented by int 0)
+    '1' 'True' 'T' 'true; 't'    : True  (represented by int 1)"""
+    
+    _falseValues = ( '0', 'F', 'f', 'False', 'false' )
+    _trueValues  = ( '1', 'T', 't', 'True' , 'true'  )
+
+    def __init__(self,help,name='default'):
+        Argument.__init__(self,help,name)
+
+
+    def basicType(self):
+        return 'bool'
+
+
+    def type(self):
+        return 'plain'
+
+
+    def typeFormat(self):
+        return 'd'  #python does not have a bool type. It uses int (0 or 1) instead.
+
+
+    def toPython(self,val):
+        if type(val) == type(True): return val != False
+        if type(val) == type(''):
+            if val in BoolArg._falseValues: return False
+            if val in BoolArg._trueValues:  return True
+            raise TransformArgumentError( '%s=%r is not one of %s' % \
+                                          (self.name(), val,
+                                           ','.join( BoolArg._falseValues + BoolArg._trueValues )) )
+        else:
+            raise TransformArgumentError( '%s=%r is not of type %s' % \
+                                          (self.name(), val, self.basicType()) )
+
+
+    def metaType(self):
+        return 'bool'
+
+
 
 class FileListArg( Argument ):
     """List of filenames coded with the following syntax:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.