Package PyFoam :: Package Applications :: Module CommonPlotLines
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.CommonPlotLines

  1   
  2  """ 
  3  Class that implements common functionality for collecting plot-lines 
  4  """ 
  5   
  6  import sys 
  7  from os import path 
  8  from optparse import OptionGroup 
  9   
 10  from PyFoam.Error import error,warning 
 11  from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer 
 12   
 13  from PyFoam.Basics.CustomPlotInfo import readCustomPlotInfo 
 14   
15 -class CommonPlotLines(object):
16 """ This class collects the lines that should be plotted 17 """ 18
19 - def __init__(self):
20 self.lines_=[]
21
22 - def plotLines(self):
23 return self.lines_
24
25 - def addPlotLine(self,line):
26 """Add a single line""" 27 self.lines_+=readCustomPlotInfo(line)
28
29 - def addPlotLines(self,lines):
30 """Adds a list of lines""" 31 if lines: 32 for l in lines: 33 self.lines_+=readCustomPlotInfo(l)
34
35 - def addFileRegexps(self,fName):
36 """Adds the lines from a file to the custom regular expressions 37 @param fName: The name of the file""" 38 f=open(fName) 39 txt=f.read() 40 f.close() 41 self.lines_+=readCustomPlotInfo(txt)
42
43 - def addOptions(self):
44 grp=OptionGroup(self.parser, 45 "Regular expression", 46 "Where regular expressions for custom plots are found") 47 48 grp.add_option("--custom-regexp", 49 action="append", 50 default=None, 51 dest="customRegex", 52 help="Add a custom regular expression to be plotted (can be used more than once)") 53 54 grp.add_option("--regexp-file", 55 action="append", 56 default=None, 57 dest="regexpFile", 58 help="A file with regulare expressions that are treated like the expressions given with --custom-regexp") 59 60 grp.add_option("--no-auto-customRegexp", 61 action="store_false", 62 default=True, 63 dest="autoCustom", 64 help="Do not automatically load the expressions from the file customRegexp") 65 66 grp.add_option("--dump-custom-regegexp", 67 action="store_true", 68 default=False, 69 dest="dumpCustomRegexp", 70 help="Dump the used regular expressions in a format suitable to put into a customRegexp-file and finish the program") 71 self.parser.add_option_group(grp) 72 73 grp2=OptionGroup(self.parser, 74 "Data files", 75 "How data files are written") 76 grp2.add_option("--single-data-files-only", 77 action="store_true", 78 default=False, 79 dest="singleDataFilesOnly", 80 help="Don't create consecutive data files 'value', 'value_2', 'value_3' etc but put all the data into a single file") 81 82 self.parser.add_option_group(grp2)
83
84 - def processPlotLineOptions(self,autoPath=None):
85 """Process the options that have to do with plot-lines""" 86 87 self.addPlotLines(self.opts.customRegex) 88 89 if self.opts.regexpFile!=None: 90 for f in self.opts.regexpFile: 91 print " Reading regular expressions from",f 92 self.addFileRegexps(f) 93 94 95 if autoPath!=None and self.opts.autoCustom: 96 autoFile=path.join(autoPath,"customRegexp") 97 if path.exists(autoFile): 98 print " Reading regular expressions from",autoFile 99 self.addFileRegexps(autoFile) 100 101 if self.opts.dumpCustomRegexp: 102 print "\nDumping customRegexp:\n" 103 for l in self.lines_: 104 print l 105 sys.exit(-1)
106