Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions nodescraper/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,17 @@ def build_parser(
)

summary_parser.add_argument(
"--summary_path",
dest="summary_path",
"--search-path",
dest="search_path",
type=log_path_arg,
help="Path to node-scraper results. Generates summary csv file in summary.csv.",
help="Path to node-scraper previously generated results.",
)

summary_parser.add_argument(
"--output-path",
dest="output_path",
type=log_path_arg,
help="Specifies path for summary.csv.",
)
Comment on lines +164 to +176

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have separate args for search path vs output path.

  • Search path would be the location of the result files to process
  • output path would be where the summary is written to (default as cwd)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexandraBara what do you think of this suggested approach?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, ill update


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

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

if parsed_args.subcmd == "summary":
generate_summary(parsed_args.summary_path, logger)
generate_summary(parsed_args.search_path, parsed_args.output_path, logger)
sys.exit(0)

if parsed_args.subcmd == "describe":
Expand Down
23 changes: 18 additions & 5 deletions nodescraper/cli/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,23 +479,36 @@ def dump_to_csv(all_rows: list, filename: str, fieldnames: list[str], logger: lo
logger.info("Data written to csv file: %s", filename)


def generate_summary(base_path: str, logger: logging.Logger):
def generate_summary(search_path: str, output_path: str, logger: logging.Logger):
"""Concatenate csv files into 1 summary csv file

Args:
base_path (str): base path to look for csv files
search_path (str): base path to look for csv files
logger (logging.Logger): instance of logger
"""
fieldnames = ["nodename", "plugin", "status", "timestamp", "message"]
all_rows = []

pattern = os.path.join(base_path, "**", "nodescraper.csv")
for filepath in glob.glob(pattern, recursive=True):
pattern = os.path.join(search_path, "**", "nodescraper.csv")
matched_files = glob.glob(pattern, recursive=True)

if not matched_files:
logger.error(f"No nodescraper.csv files found under {search_path}")
return

for filepath in matched_files:
logger.info(f"Reading: {filepath}")
with open(filepath, newline="") as f:
reader = csv.DictReader(f)
for row in reader:
all_rows.append(row)

output_path = os.path.join(base_path, "summary.csv")
if not all_rows:
logger.error("No data rows found in matched CSV files.")
return

if not output_path:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If output path can be None, the type hint should be updated accordingly to Optional[output_path]

output_path = os.getcwd()

output_path = os.path.join(output_path, "summary.csv")
dump_to_csv(all_rows, output_path, fieldnames, logger)
2 changes: 1 addition & 1 deletion test/unit/framework/test_cli_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_generate_summary(tmp_path):
}
)

generate_summary(str(tmp_path), logger)
generate_summary(str(tmp_path), str(tmp_path), logger)

summary_path = tmp_path / "summary.csv"
assert summary_path.exists()
Expand Down