Skip to content

Commit 923aa03

Browse files
committed
added output-path for summary
1 parent 2ba21fd commit 923aa03

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

nodescraper/cli/cli.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,17 @@ def build_parser(
162162
)
163163

164164
summary_parser.add_argument(
165-
"--summary_path",
166-
dest="summary_path",
165+
"--search-path",
166+
dest="search_path",
167167
type=log_path_arg,
168-
help="Path to node-scraper results. Generates summary csv file in summary.csv.",
168+
help="Path to node-scraper previously generated results.",
169+
)
170+
171+
summary_parser.add_argument(
172+
"--output-path",
173+
dest="output_path",
174+
type=log_path_arg,
175+
help="Specifies path for summary.csv.",
169176
)
170177

171178
run_plugin_parser = subparsers.add_parser(
@@ -263,7 +270,7 @@ def setup_logger(log_level: str = "INFO", log_path: str | None = None) -> loggin
263270
handlers = [logging.StreamHandler(stream=sys.stdout)]
264271

265272
if log_path:
266-
log_file_name = os.path.join(log_path, "errorscraper.log")
273+
log_file_name = os.path.join(log_path, "nodescraper.log")
267274
handlers.append(
268275
logging.FileHandler(filename=log_file_name, mode="wt", encoding="utf-8"),
269276
)
@@ -358,7 +365,7 @@ def main(arg_input: Optional[list[str]] = None):
358365
logger.info("Log path: %s", log_path)
359366

360367
if parsed_args.subcmd == "summary":
361-
generate_summary(parsed_args.summary_path, logger)
368+
generate_summary(parsed_args.search_path, parsed_args.output_path, logger)
362369
sys.exit(0)
363370

364371
if parsed_args.subcmd == "describe":

nodescraper/cli/helper.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,23 +479,36 @@ def dump_to_csv(all_rows: list, filename: str, fieldnames: list[str], logger: lo
479479
logger.info("Data written to csv file: %s", filename)
480480

481481

482-
def generate_summary(base_path: str, logger: logging.Logger):
482+
def generate_summary(search_path: str, output_path: str, logger: logging.Logger):
483483
"""Concatenate csv files into 1 summary csv file
484484
485485
Args:
486-
base_path (str): base path to look for csv files
486+
search_path (str): base path to look for csv files
487487
logger (logging.Logger): instance of logger
488488
"""
489489
fieldnames = ["nodename", "plugin", "status", "timestamp", "message"]
490490
all_rows = []
491491

492-
pattern = os.path.join(base_path, "**", "nodescraper.csv")
493-
for filepath in glob.glob(pattern, recursive=True):
492+
pattern = os.path.join(search_path, "**", "nodescraper.csv")
493+
matched_files = glob.glob(pattern, recursive=True)
494+
495+
if not matched_files:
496+
logger.error(f"No nodescraper.csv files found under {search_path}")
497+
return
498+
499+
for filepath in matched_files:
494500
logger.info(f"Reading: {filepath}")
495501
with open(filepath, newline="") as f:
496502
reader = csv.DictReader(f)
497503
for row in reader:
498504
all_rows.append(row)
499505

500-
output_path = os.path.join(base_path, "summary.csv")
506+
if not all_rows:
507+
logger.error("No data rows found in matched CSV files.")
508+
return
509+
510+
if not output_path:
511+
output_path = os.getcwd()
512+
513+
output_path = os.path.join(output_path, "summary.csv")
501514
dump_to_csv(all_rows, output_path, fieldnames, logger)

test/unit/framework/test_cli_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_generate_summary(tmp_path):
250250
}
251251
)
252252

253-
generate_summary(str(tmp_path), logger)
253+
generate_summary(str(tmp_path), str(tmp_path), logger)
254254

255255
summary_path = tmp_path / "summary.csv"
256256
assert summary_path.exists()

0 commit comments

Comments
 (0)