1 """Implements a trigger that removes the libs and/or function
2 entry from the controlDict"""
3
4 import re
5 from os import path
6 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
7 from PyFoam.Error import warning
8
10 """ The class that does the actual triggering
11 """
12
14 self.parser.add_option("--remove-libs",
15 action="store_true",
16 dest="removeLibs",
17 default=False,
18 help="Remove the libs entry from the controlDict for the duration of the application run")
19 self.parser.add_option("--remove-functions",
20 action="store_true",
21 dest="removeFunctions",
22 default=False,
23 help="Remove the functions entry from the controlDict for the duration of the application run")
24
30
31
34 self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=True)
35
36 self.fresh=False
37
38 try:
39 if libs and ("libs" in self.control):
40 warning("Temporarily removing the libs-entry from the controlDict")
41 del self.control["libs"]
42 self.fresh=True
43 if funs and ("functions" in self.control):
44 warning("Temporarily removing the functions-entry from the controlDict")
45 del self.control["functions"]
46 self.fresh=True
47
48 if self.fresh:
49 self.control.writeFile()
50 except Exception,e:
51 warning("Restoring defaults")
52 self.control.restore()
53 raise e
54
56 if self.fresh:
57 warning("Trigger called: Resetting controlDict")
58 self.control.restore()
59 self.fresh=False
60