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