Package PyFoam :: Package Applications :: Module CommonTemplateBehaviour
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.CommonTemplateBehaviour

 1  #  ICE Revision: $Id$ 
 2  """ 
 3  Common class with options that describe the behaviour of the template parser 
 4  """ 
 5   
 6  from optparse import OptionGroup 
 7   
 8  from os import path 
 9   
10 -class CommonTemplateBehaviour(object):
11 - def addOptions(self):
12 behaviour=OptionGroup(self.parser, 13 "Behaviour", 14 "The behaviour of the parser") 15 self.parser.add_option_group(behaviour) 16 behaviour.add_option("--tolerant-expression-evaluation", 17 action="store_true", 18 default=False, 19 dest="tolerantRender", 20 help="Instead of failing when encountering a problem during an evaluation a string with the error message is inserted into the output") 21 behaviour.add_option("--allow-exec-instead-of-assignment", 22 action="store_true", 23 default=False, 24 dest="allowExec", 25 help="Allows exectution of non-assignments in $$-lines. This is potentially unsafe as it allows 'import' and calling of external programs") 26 behaviour.add_option("--add-assignment-debug", 27 action="store_true", 28 default=False, 29 dest="addAssignmentDebug", 30 help="Adds a commented out line for each assignment with the name of the variable and the used value")
31
32 - def pickAssignmentDebug(self,fName):
33 """Pick the correct comment prefix according to the file extension. 34 Fall back to // for no/unknown extension (assuming foam-file)""" 35 if not self.opts.addAssignmentDebug: 36 return None 37 ext=path.splitext(fName) 38 if ext!="": 39 ext=ext[1:] 40 if ext in ["sh","py"]: 41 return "#" 42 else: 43 return "//"
44 45 # Should work with Python3 and Python2 46