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

Source Code for Module PyFoam.Applications.CommonCaseBuilder

 1  """ 
 2  Class that implements the common functionality for CaseBuilder-applications 
 3  """ 
 4   
 5  from optparse import OptionGroup 
 6  from os import path 
 7   
 8  from PyFoam import configuration as config 
 9  from .CaseBuilderBackend import CaseBuilderDescriptionList 
10  from PyFoam.Error import error 
11   
12  from PyFoam.ThirdParty.six import print_ 
13   
14 -class CommonCaseBuilder(object):
15 """ The class that implements common CaseBuilder-functionality 16 """ 17
18 - def addOptions(self):
19 cb=OptionGroup(self.parser, 20 "Casebuilder", 21 "Information related to the Casebuilder") 22 self.parser.add_option_group(cb) 23 24 cb.add_option("--list-of-desciptions", 25 action="store_true", 26 dest="listDescr", 27 default=False, 28 help="List the available case descriptions") 29 30 cb.add_option("--description-path", 31 action="store_true", 32 dest="descPath", 33 default=False, 34 help="Show the directories that are searched for case descriptions") 35 36 select=OptionGroup(self.parser, 37 "Selection", 38 "How the description file is chosen") 39 self.parser.add_option_group(select) 40 41 select.add_option("--search", 42 action="store_true", 43 dest="search", 44 default=False, 45 help="Search the description file in the path (and appends .pfcb to the given name")
46
47 - def pathInfo(self):
48 if self.opts.descPath: 49 print_() 50 print_("Directories that are searched for pfcb-files:") 51 print_() 52 for i,d in enumerate(config().get("CaseBuilder","descriptionpath")): 53 status="<not existing>" 54 if path.isdir(d): 55 status=" "*len(status) 56 print_("%2d: %s %s" %(i+1,status,d)) 57 return True 58 59 if self.opts.listDescr: 60 dl=CaseBuilderDescriptionList() 61 62 print_() 63 print_("Available description files:") 64 print_() 65 66 for i,d in enumerate(dl): 67 print_("%4d: %s" % (i+1,d[1])) 68 print_(" %s - %s" % (d[2],d[3])) 69 70 return True 71 72 return False
73
74 - def searchDescriptionFile(self,name):
75 if self.opts.search: 76 fName=None 77 for d in config().get("CaseBuilder","descriptionpath"): 78 if path.exists(path.join(d,name)): 79 fName=path.join(d,name) 80 break 81 if path.exists(path.join(d,name+".pfcb")): 82 fName=path.join(d,name+".pfcb") 83 break 84 if not fName: 85 error("Description",name,"does not exist in search path",config().get("CaseBuilder","descriptionpath")) 86 else: 87 print_("Found",fName) 88 else: 89 fName=name 90 if not path.exists(fName): 91 error("The description file",fName,"does not exist") 92 93 return fName
94 95 # Should work with Python3 and Python2 96