Skip to content

Commit 24bfbce

Browse files
committed
feat(cli): Add compression flag to json database configuration
1 parent bae657d commit 24bfbce

4 files changed

Lines changed: 16 additions & 8 deletions

src/powerapi/cli/common_cli_parsing_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(self):
159159
subparser_json_input.add_argument("n", "name", help_text="Name of the puller", default_value="puller_json")
160160
subparser_json_input.add_argument("m", "model", help_text="Expected report type")
161161
subparser_json_input.add_argument("f", "filepath", help_text="Input file path")
162+
subparser_json_input.add_argument("c", "compression", default_value='auto', help_text="Compression type")
162163
self.add_subgroup_parser("input", subparser_json_input)
163164

164165
subparser_mongo_output = SubgroupConfigParsingManager("mongodb")
@@ -252,6 +253,7 @@ def __init__(self):
252253
subparser_json_output.add_argument("n", "name", help_text="Name of the pusher", default_value="pusher_json")
253254
subparser_json_output.add_argument("m", "model", help_text="Report type to be exported")
254255
subparser_json_output.add_argument("f", "filepath", help_text="Output file path")
256+
subparser_json_output.add_argument("c", "compression", default_value="auto", help_text="Compression type")
255257
self.add_subgroup_parser("output", subparser_json_output)
256258

257259
subparser_opentsdb_output = SubgroupConfigParsingManager("opentsdb")

src/powerapi/cli/generator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ def generate(self, main_config: dict) -> dict[str, Actor]:
9090
Generate an actor class and actor start message from config dict
9191
"""
9292
if self.component_group_name not in main_config:
93-
raise PowerAPIException('Configuration error : no ' + self.component_group_name + ' specified')
93+
raise PowerAPIException(f'Configuration error : Component {self.component_group_name} group is unknown')
9494

9595
actors = {}
9696
for component_name, component_config in main_config[self.component_group_name].items():
9797
try:
9898
actors[component_name] = self._gen_actor(component_config, main_config, component_name)
9999
except KeyError as exn:
100-
raise PowerAPIException('Configuration error: Missing "%s" argument for %s component', exn.args[0], component_name) from exn
100+
raise PowerAPIException(f'Configuration error: Missing "{exn.args[0]}" argument for {component_name} component') from exn
101+
except ValueError as exn:
102+
raise PowerAPIException(f'Configuration error: Invalid parameter for {component_name} component: {exn.args[0]}') from exn
101103

102104
return actors
103105

@@ -227,7 +229,7 @@ def _json_input_database_factory(conf: dict) -> ReadableDatabase:
227229
JSON Input database factory method.
228230
"""
229231
from powerapi.database.json import JsonInput
230-
return JsonInput(conf['model'], conf['filepath'])
232+
return JsonInput(conf['model'], conf['filepath'], conf['compression'])
231233

232234
@staticmethod
233235
def _socket_database_factory(conf: dict) -> ReadableDatabase:
@@ -291,7 +293,7 @@ def _json_output_database_factory(conf: dict) -> WritableDatabase:
291293
JSON Output database factory method.
292294
"""
293295
from powerapi.database.json import JsonOutput
294-
return JsonOutput(conf['model'], conf['filepath'])
296+
return JsonOutput(conf['model'], conf['filepath'], conf['compression'])
295297

296298
@staticmethod
297299
def _mongodb_database_factory(conf: dict) -> WritableDatabase:

tests/utils/cli/several_inputs_outputs_stream_mode_enabled_configuration.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"puller4": {
1919
"model": "HWPCReport",
2020
"type": "json",
21-
"filepath": "/tmp/pytest-powerapi.jsonl"
21+
"filepath": "/tmp/pytest-powerapi.jsonl",
22+
"compression": "none"
2223
}
2324
},
2425
"output": {
@@ -30,7 +31,8 @@
3031
"seventh_pusher": {
3132
"type": "json",
3233
"model": "FormulaReport",
33-
"filepath": "my_output_filepath"
34+
"filepath": "my_output_filepath",
35+
"compression": "none"
3436
}
3537
}
3638
}

tests/utils/cli/single_input_multiple_outputs_with_different_report_type_configuration.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"powerrep1": {
1414
"type": "json",
1515
"model": "PowerReport",
16-
"filepath": "/tmp/pytest-powerrep.jsonl"
16+
"filepath": "/tmp/pytest-powerrep.jsonl",
17+
"compression": "none"
1718
},
1819
"powerrep2": {
1920
"type": "csv",
@@ -23,7 +24,8 @@
2324
"formularep": {
2425
"type": "json",
2526
"model": "FormulaReport",
26-
"filepath": "/tmp/pytest-formularep.jsonl"
27+
"filepath": "/tmp/pytest-formularep.jsonl",
28+
"compression": "none"
2729
}
2830
}
2931
}

0 commit comments

Comments
 (0)