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