1 """
2 Class that implements the common functionality for treatment of the standard output
3 """
4
5 from optparse import OptionGroup
6 from os import path
7
9 """ The class that defines options for standard output
10 """
11
13 grp=OptionGroup(self.parser,
14 "Standard Output",
15 "Treatment of the standard output that is captured from the OpenFOAM-application")
16 grp.add_option("--progress",
17 action="store_true",
18 default=False,
19 dest="progress",
20 help="Only prints the progress of the simulation, but swallows all the other output")
21 grp.add_option("--silent",
22 action="store_true",
23 default=False,
24 dest="silent",
25 help="Do not print any output")
26 grp.add_option("--echo-command-prefix",
27 action="store",
28 default=None,
29 dest="echoCommandPrefix",
30 help="Do not print any output")
31 grp.add_option("--logname",
32 dest="logname",
33 default=logname,
34 help="Name of the logfile")
35 grp.add_option("--compress",
36 action="store_true",
37 dest="compress",
38 default=False,
39 help="Compress the logfile into a gzip file. Possible loss of data if the run fails")
40 grp.add_option("--no-log",
41 action="store_true",
42 dest="noLog",
43 default=False,
44 help="Do not output a log-file")
45 grp.add_option("--log-tail",
46 action="store",
47 dest="logTail",
48 default=None,
49 type="int",
50 help="Only write the last N lines to the logfile. Too small values might cause performance problems")
51
52 self.parser.add_option_group(grp)
53
54 inf=OptionGroup(self.parser,
55 "Run Info",
56 "Additional information about the run")
57 inf.add_option("--remark",
58 dest="remark",
59 default=None,
60 help="Text string with a remark about the run")
61 inf.add_option("--job-id",
62 dest="jobId",
63 default=None,
64 help="Text string with the job-ID of the queuing system (usually unused)")
65 inf.add_option("--parameter",
66 dest="runParameters",
67 default=[],
68 action="append",
69 help="Parameter that is being added to the runInfo. Of the form <key>:<value>. Can be specified more than once")
70 self.parser.add_option_group(inf)
71
73 """Return a dictionary with the parameters"""
74 parameters={}
75 for p in self.opts.runParameters:
76 try:
77 k,v=p.split(":",1)
78 try:
79 v=int(v)
80 except ValueError:
81 try:
82 v=float(v)
83 except ValueError:
84 pass
85
86 parameters[k]=v
87 except ValueError:
88 parameters[k]=p
89 return parameters
90
91 - def setLogname(self,
92 default="PyFoamRunner",
93 useApplication=True,
94 force=False):
95 """Builds a logfile-name
96 @param default: Default value if no prefix for the logfile-has been defined
97 @param useApplication: append the name of the application to the prefix"""
98
99 if self.opts.logname==None or force:
100 self.opts.logname=default
101 if useApplication:
102 self.opts.logname+="."+path.basename(self.parser.getArgs()[0])
103