1 """Implements a trigger that removes the libs and/or function
2 entry from the controlDict"""
3
4 import sys
5
6 from os import path
7 from optparse import OptionGroup
8 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
9 from PyFoam.Error import warning
10
12 """ The class that does the actual triggering
13 """
14
16 grp=OptionGroup(self.parser,
17 "Manipulating controlDict",
18 "Temporarily remove entries from the controlDict that are incompatible with some applications")
19
20 grp.add_option("--remove-libs",
21 action="store_true",
22 dest="removeLibs",
23 default=False,
24 help="Remove the libs entry from the controlDict for the duration of the application run")
25 grp.add_option("--remove-functions",
26 action="store_true",
27 dest="removeFunctions",
28 default=False,
29 help="Remove the functions entry from the controlDict for the duration of the application run")
30 self.parser.add_option_group(grp)
31
37
38
41 self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),
42 backup=True,
43 doMacroExpansion=True)
44
45 self.fresh=False
46
47 try:
48 if libs and ("libs" in self.control):
49 warning("Temporarily removing the libs-entry from the controlDict")
50 del self.control["libs"]
51 self.fresh=True
52 if funs and ("functions" in self.control):
53 warning("Temporarily removing the functions-entry from the controlDict")
54 del self.control["functions"]
55 self.fresh=True
56
57 if self.fresh:
58 self.control.writeFile()
59 else:
60 self.control.restore()
61
62 except Exception:
63 e = sys.exc_info()[1]
64 warning("Restoring defaults")
65 self.control.restore()
66 raise e
67
69 if self.fresh:
70 warning("Trigger called: Resetting controlDict")
71 self.control.restore()
72 self.fresh=False
73
74
75