def get_objects_to_retrieve()

in pantri/scripts/lib/pantri.py [0:0]


    def get_objects_to_retrieve(self):
        if "pitem" in self.options:
            if os.path.exists(self.options["pitem"]):
                try:
                    with open(self.options["pitem"]) as json_file:
                        item = json.load(json_file)
                    uploaded_objects = item
                    dl_path = os.path.join(self.paths["repo_root"], "shelves")
                    self.options["dest_sync"] = dl_path
                except Exception:
                    self.logger.error("Not a .pitem")
                    raise Exception("Did not specify a proper .pitem during retrieval")
            else:
                self.logger.error("Path to retrieval item does not exist.")
                raise OSError("Retrieval path doesn't exist.")
        else:
            uploaded_objects = self.get_uploaded_objects()
        objects_on_disk = self.get_objects_on_disk()

        # Compare upload object and objects on disk. Download missing files
        objects_to_retrieve = {}
        for obj in uploaded_objects:
            if obj not in objects_on_disk:
                self.logger.info("Download Object: %s (Object not present)" % obj)
                # Build dictionary of objects to download
                objects_to_retrieve.update({obj: uploaded_objects[obj]})
                continue

            # Compare sha1 hashes if checksum is enabled
            if (
                self.options["checksum"]
                and objects_on_disk[obj]["sha1_hash"]
                == uploaded_objects[obj]["sha1_hash"]
            ):

                self.logger.info("Skip Object: %s (matching hash)" % obj)
                continue

            # Check file size and modified times
            if (
                objects_on_disk[obj]["file_size"] == uploaded_objects[obj]["file_size"]
                and objects_on_disk[obj]["modified_time"]
                == uploaded_objects[obj]["modified_time"]
            ):

                self.logger.info(
                    "Skip Object: %s (matching file size and modified time.)" % obj
                )
                continue

            # Build dictionary of objects to download
            self.logger.info("Download Object: %s (object different)" % obj)
            objects_to_retrieve.update({obj: uploaded_objects[obj]})

        return objects_to_retrieve