Skip to content

Commit ea45e65

Browse files
committed
Refactor ModelComponent to use a MC-standard image cache progress object
1 parent 4817cba commit ea45e65

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

src/firewheel/control/model_component.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class ModelComponent:
2424
This class defines a Model Component which is the building block
2525
for FIREWHEEL experiments.
2626
"""
27+
image_cache_progress = Progress(
28+
TextColumn("[yellow]{task.description} This may take a while."),
29+
SpinnerColumn(spinner_name="line"),
30+
TimeElapsedColumn(),
31+
)
2732

2833
def __init__(
2934
self,
@@ -567,38 +572,31 @@ def _upload_images(self):
567572
# the image in the FileStore, then we should check the MD5 sums. If the
568573
# MD5 sums differ, than we need to re-upload the image.
569574
if upload_date is None:
570-
with Progress(
571-
TextColumn(
572-
f"[yellow]Adding {end_path} to cache. This may take a while."
573-
),
574-
SpinnerColumn(spinner_name="line"),
575-
TimeElapsedColumn(),
576-
) as progress:
577-
progress.add_task(description="upload_image")
578-
self.image_store.add_image_file(path)
575+
self._add_image_to_store(
576+
path, description=f"Adding {end_path} to cache."
577+
)
579578
ret_val.append("no_date")
580579
elif last_modified_date != upload_date:
581580
# If date is different then hash it
582581
disk_hash = hash_file(path)
583582
store_hash = self.image_store.get_file_hash(os.path.basename(path))
584583
# If hashes differ upload new image
585584
if disk_hash != store_hash:
586-
with Progress(
587-
TextColumn(
588-
f"[yellow]Updating {end_path} in cache. This may take a while."
589-
),
590-
SpinnerColumn(spinner_name="line"),
591-
TimeElapsedColumn(),
592-
) as progress:
593-
progress.add_task(description="upload_image")
594-
self.image_store.add_image_file(path)
585+
self._add_image_to_store(
586+
path, description=f"Updating {end_path} in cache."
587+
)
595588
ret_val.append("new_hash")
596589
else:
597590
ret_val.append("same_hash")
598591
else:
599592
ret_val.append(False)
600593
return ret_val
601594

595+
def _add_image_to_store(self, path, description):
596+
with self.image_cache_progress as progress:
597+
update_cache = progress.add_task(description=description)
598+
self.image_store.add_image_file(path)
599+
602600
def set_dependency_graph_id(self, new_id):
603601
"""
604602
Set the dependency graph ID.

0 commit comments

Comments
 (0)