1
2 """
3 Application class that implements pyFoamUpgradeDictionariesTo17
4 """
5
6 import sys,re
7 from optparse import OptionGroup
8 from os import path
9
10 from PyFoamApplication import PyFoamApplication
11
12 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
13 from PyFoam.Basics.Utilities import copyfile
14 from PyFoam.Basics.DataStructures import DictProxy
15 from PyFoam.Basics.FoamFileGenerator import makeString
16 from PyFoam.Error import error
17
19 """This class knows how to detect old versions and how to upgrade them"""
21 self.case=None
22 self.enabled=True
23
26
29
32
36
51
57
61
63 return path.join("system","fvSolution")
64
66 if "solvers" not in content:
67 return False
68
69 for s in content["solvers"]:
70 if type(content["solvers"][s]) not in [dict,DictProxy]:
71 return True
72 return False
73
75 for s in content["solvers"]:
76 comment=self.makeComment(content["solvers"][s])
77 alg,rest=content["solvers"][s]
78 rest["solver"]=alg
79 content["solvers"][s]=rest
80 content["solvers"].addDecoration(s,comment)
81
83 - def __init__(self,
84 args=None,
85 description=None):
103
106
108 behaveGroup=OptionGroup(self.parser,
109 "Behaviour",
110 "General behaviour of the program")
111
112 behaveGroup.add_option("--apply-changes",
113 action="store_true",
114 dest="applyChanges",
115 default=False,
116 help="Apply changes to the dictionaries in question. Without this option only the results of the analysis will be shown")
117
118 behaveGroup.add_option("--print",
119 action="store_true",
120 dest="print_",
121 default=False,
122 help="Only print the modified dictionaries to the screen")
123
124 behaveGroup.add_option("--verbose",
125 action="store_true",
126 dest="verbose",
127 default=False,
128 help="Speak out aloud which decisions are made")
129
130 behaveGroup.add_option("--force",
131 action="store_true",
132 dest="force",
133 default=False,
134 help="Force even if backup-files exist")
135
136 self.parser.add_option_group(behaveGroup)
137
138 self.dictGroup=OptionGroup(self.parser,
139 "Dictionaries",
140 "Dictionaries that should be updated")
141
142 for d in self.dicts:
143 self.dictGroup.add_option("--disable-"+"-".join(reversed(d.location().split(path.sep))),
144 action="callback",
145 callback=d.disableCallback,
146 help="Disable the modification of "+d.location())
147
148 self.parser.add_option_group(self.dictGroup)
149
151 case=self.parser.getArgs()[0]
152 self.checkCase(case)
153
154 if self.opts.verbose:
155 print "Working on case",case
156
157 for d in self.dicts:
158 d.case=case
159 if self.opts.verbose:
160 print " Checking",d.location()
161
162 if not d.enabled:
163 if self.opts.verbose:
164 print " Disabled"
165 continue
166
167 if not path.exists(d.path()):
168 d.disable()
169 if self.opts.verbose:
170 print " Does not exist - disabling"
171 continue
172
173 if not d.needsUpgrade():
174 d.disable()
175 if self.opts.verbose:
176 print " Does not need an upgrade - disbling"
177 continue
178
179 print d.location(),"needs an upgrade"
180
181 if self.opts.applyChanges or self.opts.print_:
182 print
183 if self.opts.applyChanges:
184 print "Doing the upgrades"
185 for d in self.dicts:
186 if d.enabled:
187 if self.opts.verbose:
188 print "Upgrading",d.location()
189 d.upgrade(self.opts.force,self.opts.print_)
190