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