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