1 """
2 Class that implements common functionality for collecting plot-lines
3 """
4
5 from os import path
6 from optparse import OptionGroup
7
8 from PyFoam.Error import error,warning
9 from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer
10
12 """ This class collects the lines that should be plotted
13 """
14
17
20
22 """Add a single line"""
23
24 if self.lines_==None:
25 self.lines_=[line]
26 else:
27 if type(line)==str:
28 self.lines_.append(line)
29 else:
30 error(line,"is not a string, but",type(line))
31
42
44 """Adds the lines from a file to the custom regular expressions
45 @param fName: The name of the file"""
46 f=open(fName)
47
48 for l in f.readlines():
49 l=l.strip()
50 if len(l)==0:
51 continue
52 if l[0]=='"' and l[-1]=='"':
53 l=l[1:-1]
54 if len(l)>0:
55 self.addPlotLine(l)
56
57 f.close()
58
60 grp=OptionGroup(self.parser,
61 "Regular expression",
62 "Where regular expressions for custom plots are found")
63
64 grp.add_option("--custom-regexp",
65 action="append",
66 default=None,
67 dest="customRegex",
68 help="Add a custom regular expression to be plotted (can be used more than once)")
69
70 grp.add_option("--regexp-file",
71 action="append",
72 default=None,
73 dest="regexpFile",
74 help="A file with regulare expressions that are treated like the expressions given with --custom-regexp")
75
76 grp.add_option("--no-auto-customRegexp",
77 action="store_false",
78 default=True,
79 dest="autoCustom",
80 help="Do not automatically load the expressions from the file customRegexp")
81 self.parser.add_option_group(grp)
82
84 """Process the options that have to do with plot-lines"""
85
86 self.addPlotLines(self.opts.customRegex)
87
88 if self.opts.regexpFile!=None:
89 for f in self.opts.regexpFile:
90 print " Reading regular expressions from",f
91 self.addFileRegexps(f)
92
93
94 if autoPath!=None and self.opts.autoCustom:
95 autoFile=path.join(autoPath,"customRegexp")
96 if path.exists(autoFile):
97 print " Reading regular expressions from",autoFile
98 self.addFileRegexps(autoFile)
99
105