From 72b9e80fddf9c98c797953f2510e9ce56c5bbb01 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Mon, 26 Feb 2024 00:15:33 +0100 Subject: [PATCH] standardize helper methods name (vendor<>task) --- src/sc_crawler/cli.py | 4 ++-- src/sc_crawler/logger.py | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/sc_crawler/cli.py b/src/sc_crawler/cli.py index 6192fe4b..18e6ea45 100644 --- a/src/sc_crawler/cli.py +++ b/src/sc_crawler/cli.py @@ -170,7 +170,7 @@ def custom_serializer(x): vendor.progress_tracker = VendorProgressTracker( vendor=vendor, progress_panel=pbars ) - vendor.progress_tracker.vendor_start(n=len(update_table)) + vendor.progress_tracker.start_vendor(n=len(update_table)) if Tables.compliance_frameworks in update_table: vendor.inventory_compliance_frameworks() if Tables.datacenters in update_table: @@ -190,7 +190,7 @@ def custom_serializer(x): if Tables.ipv4_prices in update_table: vendor.inventory_ipv4_prices() # reset current step name - vendor.progress_tracker.vendor_update(step="") + vendor.progress_tracker.update_vendor(step="") session.merge(vendor) session.commit() diff --git a/src/sc_crawler/logger.py b/src/sc_crawler/logger.py index b406db1f..8637cede 100644 --- a/src/sc_crawler/logger.py +++ b/src/sc_crawler/logger.py @@ -40,7 +40,7 @@ def wrap(*args, **kwargs): # update Vendor's progress bar with the step name try: - self.progress_tracker.vendor_update( + self.progress_tracker.update_vendor( # drop `inventory_` prefix and prettify step=func.__name__[10:].replace("_", " ") ) @@ -51,7 +51,7 @@ def wrap(*args, **kwargs): result = func(*args, **kwargs) # increment Vendor's progress bar - self.progress_tracker.vendor_update(advance=1) + self.progress_tracker.advance_vendor() # log end of the step and return logger.debug("Finished %s", fname) @@ -159,7 +159,7 @@ def __init__(self, vendor: Vendor, progress_panel: ProgressPanel): self.tasks = progress_panel.tasks self.metadata = progress_panel.metadata - def vendor_start(self, n: int) -> TaskID: + def start_vendor(self, n: int) -> TaskID: """Starts a progress bar for the Vendor's steps. Args: @@ -170,11 +170,15 @@ def vendor_start(self, n: int) -> TaskID: """ return self.vendors.add_task(self.vendor.name, total=n, step="") - def vendor_steps_advance(self, by: int = 1): - """Increment the number of finished steps.""" + def advance_vendor(self, by: int = 1) -> None: + """Increment the number of finished steps. + + Args: + by: Number of steps to advance. + """ self.vendors.update(self.vendors.task_ids[0], advance=by) - def vendor_update(self, **kwargs): + def update_vendor(self, **kwargs) -> None: """Update the vendor's progress bar. Useful fields: @@ -183,7 +187,7 @@ def vendor_update(self, **kwargs): self.vendors.update(self.vendors.task_ids[0], **kwargs) def start_task(self, name: str, n: int) -> TaskID: - """Starts a progress bar for the Vendor's steps. + """Starts a progress bar in the list of current jobs. Args: name: Name to show in front of the progress bar. Will be prefixed by Vendor's name. @@ -195,7 +199,18 @@ def start_task(self, name: str, n: int) -> TaskID: return self.tasks.add_task(self.vendor.name + ": " + name, total=n) def advance_task(self, task_id: TaskID, by: int = 1): + """Increment the number of finished steps. + + Args: + task_id: The progress bar's identifier returned by `start_task`. + by: Number of steps to advance. + """ self.tasks.update(task_id, advance=by) def hide_task(self, task_id: TaskID): + """Hide a task from the list of progress bars. + + Args: + task_id: The progress bar's identifier returned by `start_task`. + """ self.tasks.update(task_id, visible=False)