|
| 1 | +import logging |
1 | 2 | import tempfile |
2 | 3 | import shutil |
3 | 4 | import inspect |
@@ -148,9 +149,14 @@ def pin_meta(self, name, version: str = None) -> Meta: |
148 | 149 | components = [pin_name, selected_version.version] |
149 | 150 | meta_name = self.meta_factory.get_meta_name(*components) |
150 | 151 |
|
151 | | - path_version = self.construct_path([*components, meta_name]) |
152 | | - f = self.fs.open(path_version) |
153 | | - return self.meta_factory.read_pin_yaml(f, pin_name, selected_version) |
| 152 | + path_meta = self.construct_path([*components, meta_name]) |
| 153 | + f = self.fs.open(path_meta) |
| 154 | + |
| 155 | + meta = self.meta_factory.read_pin_yaml(f, pin_name, selected_version) |
| 156 | + |
| 157 | + self._touch_cache(path_meta) |
| 158 | + |
| 159 | + return meta |
154 | 160 |
|
155 | 161 | def pin_list(self): |
156 | 162 | """List names of all pins in a board. |
@@ -385,9 +391,9 @@ def pin_versions_prune( |
385 | 391 | # TODO(question): how to pin_inform? Log or warning? |
386 | 392 | if to_delete: |
387 | 393 | str_vers = ", ".join([v.version for v in to_delete]) |
388 | | - print(f"Deleting versions: {str_vers}.") |
| 394 | + logging.info(f"Deleting versions: {str_vers}.") |
389 | 395 | if not to_delete: |
390 | | - print("No old versions to delete") |
| 396 | + logging.info("No old versions to delete") |
391 | 397 |
|
392 | 398 | for version in to_delete: |
393 | 399 | self.pin_version_delete(name, version.version) |
@@ -561,6 +567,23 @@ def _extract_search_meta(self, meta): |
561 | 567 | d["meta"] = meta |
562 | 568 | return d |
563 | 569 |
|
| 570 | + def _get_cache_path(self, pin_name, version): |
| 571 | + p_version = self.construct_path([self.path_to_pin(pin_name), version]) |
| 572 | + hash = self.fs.hash_name(p_version, True) |
| 573 | + return str(Path(self.fs.storage[-1]) / hash) |
| 574 | + |
| 575 | + def _touch_cache(self, path): |
| 576 | + from pins.cache import touch_access_time |
| 577 | + |
| 578 | + # TODO: assumes same_name set to True. Let's require this be set to |
| 579 | + # instantiate a pins cache. |
| 580 | + if not hasattr(self.fs, "cached_files"): |
| 581 | + return |
| 582 | + |
| 583 | + hash = self.fs.hash_name(path, True) |
| 584 | + path_to_hashed = Path(self.fs.storage[-1]) / hash |
| 585 | + return touch_access_time(path_to_hashed) |
| 586 | + |
564 | 587 |
|
565 | 588 | class BoardManual(BaseBoard): |
566 | 589 | """Simple board that accepts a dictionary of form pin_name: path. |
@@ -614,7 +637,9 @@ def pin_meta(self, name, version=None): |
614 | 637 |
|
615 | 638 | path_meta = self.construct_path([pin_name, meta_name]) |
616 | 639 | f = self.fs.open(path_meta) |
617 | | - return self.meta_factory.read_pin_yaml(f, pin_name, VersionRaw("")) |
| 640 | + meta = self.meta_factory.read_pin_yaml(f, pin_name, VersionRaw("")) |
| 641 | + |
| 642 | + return meta |
618 | 643 |
|
619 | 644 | def pin_download(self, name, version=None, hash=None) -> Sequence[str]: |
620 | 645 | meta = self.pin_meta(name, version) |
@@ -692,12 +717,13 @@ def pin_search(self, search=None, as_df=True): |
692 | 717 |
|
693 | 718 | paged_res = self.fs.api.misc_get_applications("content_type:pin", search=search) |
694 | 719 | results = paged_res.results |
695 | | - names = [f"{cont['owner_username']}/{cont['name']}" for cont in results] |
696 | 720 |
|
697 | 721 | res = [] |
698 | | - for pin_name in names: |
| 722 | + for content in results: |
| 723 | + pin_name = f"{content['owner_username']}/{content['name']}" |
| 724 | + version = str(content["bundle_id"]) |
699 | 725 | try: |
700 | | - meta = self.pin_meta(pin_name) |
| 726 | + meta = self.pin_meta(pin_name, version) |
701 | 727 | res.append(meta) |
702 | 728 |
|
703 | 729 | except RsConnectApiRequestError as e: |
|
0 commit comments