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
18 from PyFoam.ThirdParty.six import print_
19
21 """This class knows how to detect old versions and how to upgrade them"""
23 self.case=None
24 self.enabled=True
25
28
31
34
38
53
59
63
65 return path.join("system","fvSolution")
66
68 if "solvers" not in content:
69 return False
70
71 for s in content["solvers"]:
72 if type(content["solvers"][s]) not in [dict,DictProxy]:
73 return True
74 return False
75
77 for s in content["solvers"]:
78 comment=self.makeComment(content["solvers"][s])
79 alg,rest=content["solvers"][s]
80 rest["solver"]=alg
81 content["solvers"][s]=rest
82 content["solvers"].addDecoration(s,comment)
83
85 - def __init__(self,
86 args=None,
87 description=None):
105
108
110 behaveGroup=OptionGroup(self.parser,
111 "Behaviour",
112 "General behaviour of the program")
113
114 behaveGroup.add_option("--apply-changes",
115 action="store_true",
116 dest="applyChanges",
117 default=False,
118 help="Apply changes to the dictionaries in question. Without this option only the results of the analysis will be shown")
119
120 behaveGroup.add_option("--print",
121 action="store_true",
122 dest="print_",
123 default=False,
124 help="Only print the modified dictionaries to the screen")
125
126 behaveGroup.add_option("--verbose",
127 action="store_true",
128 dest="verbose",
129 default=False,
130 help="Speak out aloud which decisions are made")
131
132 behaveGroup.add_option("--force",
133 action="store_true",
134 dest="force",
135 default=False,
136 help="Force even if backup-files exist")
137
138 self.parser.add_option_group(behaveGroup)
139
140 self.dictGroup=OptionGroup(self.parser,
141 "Dictionaries",
142 "Dictionaries that should be updated")
143
144 for d in self.dicts:
145 self.dictGroup.add_option("--disable-"+"-".join(reversed(d.location().split(path.sep))),
146 action="callback",
147 callback=d.disableCallback,
148 help="Disable the modification of "+d.location())
149
150 self.parser.add_option_group(self.dictGroup)
151
153 case=self.parser.getArgs()[0]
154 self.checkCase(case)
155
156 if self.opts.verbose:
157 print_("Working on case",case)
158
159 for d in self.dicts:
160 d.case=case
161 if self.opts.verbose:
162 print_(" Checking",d.location())
163
164 if not d.enabled:
165 if self.opts.verbose:
166 print_(" Disabled")
167 continue
168
169 if not path.exists(d.path()):
170 d.disable()
171 if self.opts.verbose:
172 print_(" Does not exist - disabling")
173 continue
174
175 if not d.needsUpgrade():
176 d.disable()
177 if self.opts.verbose:
178 print_(" Does not need an upgrade - disbling")
179 continue
180
181 print_(d.location(),"needs an upgrade")
182
183 if self.opts.applyChanges or self.opts.print_:
184 print_()
185 if self.opts.applyChanges:
186 print_("Doing the upgrades")
187 for d in self.dicts:
188 if d.enabled:
189 if self.opts.verbose:
190 print_("Upgrading",d.location())
191 d.upgrade(self.opts.force,self.opts.print_)
192
193
194