1 """
2 Application-class that implements pyFoamDumpRunDatabaseToCSV.py
3 """
4 from optparse import OptionGroup
5
6 from .PyFoamApplication import PyFoamApplication
7 from PyFoam.Basics.RunDatabase import RunDatabase
8
9 from PyFoam.ThirdParty.six import print_
10
13 description="""\
14 Dump the contents of a SQLite database that holds run information to
15 a CSV-file
16 """
17 PyFoamApplication.__init__(self,
18 args=args,
19 description=description,
20 usage="%prog <database.db> <dump.csv>",
21 interspersed=True,
22 changeVersion=False,
23 nr=2,
24 exactNr=True)
25
27 how=OptionGroup(self.parser,
28 "Behavior",
29 "How the application should behave")
30 self.parser.add_option_group(how)
31
32 how.add_option("--verbose",
33 action="store_true",
34 dest="verbose",
35 default=False,
36 help="Tell about the data dumped")
37 how.add_option("--pandas-print",
38 action="store_true",
39 dest="pandas",
40 default=False,
41 help="Print the pandas-dataframe that is collected")
42 how.add_option("--excel-file",
43 action="store_true",
44 dest="excel",
45 default=False,
46 help="Write to Excel-file instead of plain CSV. Onle works with the python-libraries pandas and xlwt")
47 how.add_option("--no-write",
48 action="store_true",
49 dest="noWrite",
50 default=False,
51 help="Do not write the CSV-file (just do terminal-output)")
52 how.add_option("--use-numpy-instead-of-pandas",
53 action="store_false",
54 dest="usePandasFormat",
55 default=True,
56 help="For internal passing of data use numpy instead of pandas")
57
58 what=OptionGroup(self.parser,
59 "What",
60 "Which information should be dumped")
61 self.parser.add_option_group(what)
62
63 what.add_option("--selection",
64 action="append",
65 dest="selection",
66 default=[],
67 help="""Regular expression (more than one can be
68 specified) to select data with (all the basic
69 run-data will be dumped anyway)""")
70
71 what.add_option("--disable-run-data",
72 action="append",
73 dest="disableRunData",
74 default=[],
75 help="""Regular expression (more than one can be
76 specified) to select fields from the standard run-data
77 which should be disabled (use with care)""")
78
79
80
82 source=self.parser.getArgs()[0]
83 dest=self.parser.getArgs()[1]
84 if self.opts.noWrite:
85 dest=None
86
87 db=RunDatabase(source,
88 verbose=self.opts.verbose)
89
90 selections=[]
91 if self.opts.selection:
92 selections=self.opts.selection
93
94 dump=db.dumpToCSV(dest,
95 selection=selections,
96 disableRunData=self.opts.disableRunData,
97 pandasFormat=self.opts.usePandasFormat,
98 excel=self.opts.excel)
99
100 if self.opts.pandas:
101 if not dump:
102 print_("No data. Seems that pandas is not installed")
103 else:
104 print_("Pandas data:\n",dump)
105
106 self.setData({
107 "database" : db ,
108 "dump" : dump
109 })
110
111
112