def _fill_in_old_browse_collection( db: BundleDB, changes_dict: ChangesDict, bundle_lidvid: LIDVID, data_collection_lidvid: LIDVID, ) -> None: bundle_segment = bundle_lidvid.lid().parts()[0] collection_segment = data_collection_lidvid.lid().parts()[1] browse_collection_lid = data_collection_lidvid.lid().to_browse_lid() browse_collection_segment = browse_collection_lid.collection_id browse_collection_vid = data_collection_lidvid.vid() browse_collection_lidvid = LIDVID.create_from_lid_and_vid( browse_collection_lid, browse_collection_vid) changes_dict.set(browse_collection_lid, browse_collection_vid, False) db.create_bundle_collection_link(str(bundle_lidvid), str(browse_collection_lidvid)) try: PDS_LOGGER.open("Fill in old browse collection") PDS_LOGGER.log( "info", f"Created link and change for {browse_collection_lidvid}") for product in db.get_collection_products( str(browse_collection_lidvid)): product_lidvid = LIDVID(product.lidvid) changes_dict.set(product_lidvid.lid(), product_lidvid.vid(), False) PDS_LOGGER.log("info", f"Created link and change for {product_lidvid}") except Exception as e: PDS_LOGGER.exception(e) finally: PDS_LOGGER.close()
def _create_context_collection(self, bundle: Bundle) -> None: context_products = bundle_db.get_context_products() if not context_products: return bundle_lidvid = str(bundle.lidvid) collection_lidvid = _extend_lidvid(bundle_lidvid, "context") bundle_db.create_context_collection(collection_lidvid, bundle_lidvid) clv = LIDVID(collection_lidvid) changes_dict.set(clv.lid(), clv.vid(), True) bundle_dir_path = _lidvid_to_dir(bundle_lidvid) context_coll_dir_path = fs.path.join(bundle_dir_path, "context$") label_deltas.makedir(context_coll_dir_path) # Create target lable if it doesn't exist in PDS page. self._create_context_target_label(context_coll_dir_path, collection_lidvid) # Create investigation label self._create_context_investigation_label(bundle_lidvid, context_coll_dir_path, collection_lidvid) collection = bundle_db.get_collection(collection_lidvid) self._post_visit_collection(collection)
def lidvid_path(lidvid: LIDVID) -> str: """ Return the directory path corresponding to this LIDVID. """ def vid_to_dir_part(vid: VID) -> str: """ Convert a VID to a directory name. """ return f"v${vid}" lid = lidvid.lid() dir = lid_path(lid) vid_bit = vid_to_dir_part(lidvid.vid()) return fs.path.join(dir, vid_bit)
def test_is_next_minor_lidvid_property(self, lidvid: LIDVID) -> None: self.assertEqual( LIDVID.create_from_lid_and_vid(lidvid.lid(), lidvid.vid().next_minor_vid()), lidvid.next_minor_lidvid(), )
def _extend_lidvid(lidvid_str: str, segment: str) -> str: lidvid = LIDVID(lidvid_str) lid = lidvid.lid().extend_lid(segment) new_lidvid = LIDVID.create_from_lid_and_vid(lid, lidvid.vid()) return str(new_lidvid)
def _build_browse_collection( db: BundleDB, changes_dict: ChangesDict, browse_deltas: COWFS, bundle_lidvid: LIDVID, data_collection_lidvid: LIDVID, bundle_path: str, ) -> None: bundle_segment = bundle_lidvid.lid().parts()[0] collection_segment = data_collection_lidvid.lid().parts()[1] browse_collection_lid = data_collection_lidvid.lid().to_browse_lid() collection_path = f"{bundle_path}{collection_segment}$/" browse_collection_segment = browse_collection_lid.collection_id browse_collection_path = f"{bundle_path}{browse_collection_segment}$/" browse_collection_vid = data_collection_lidvid.vid() browse_collection_lidvid = LIDVID.create_from_lid_and_vid( browse_collection_lid, browse_collection_vid) changes_dict.set(browse_collection_lid, browse_collection_vid, True) browse_deltas.makedirs(browse_collection_path, recreate=True) db.create_other_collection(str(browse_collection_lidvid), str(bundle_lidvid)) db.create_bundle_collection_link(str(bundle_lidvid), str(browse_collection_lidvid)) product_segments = [ str(prod[:-1]) for prod in browse_deltas.listdir(collection_path) if "$" in prod ] for product_segment in product_segments: # These product_segments are from the data_collection product_lid = LID.create_from_parts( [bundle_segment, collection_segment, product_segment]) product_vid = changes_dict.vid(product_lid) product_path = f"{collection_path}{product_segment}$/" browse_product_path = f"{browse_collection_path}{product_segment}$/" browse_product_lidvid = _extend_lidvid(browse_collection_lid, product_vid, product_segment) if changes_dict.changed(product_lid): fits_product_lidvid = _extend_lidvid( data_collection_lidvid.lid(), data_collection_lidvid.vid(), product_segment, ) bpl = LIDVID(browse_product_lidvid) changes_dict.set(bpl.lid(), bpl.vid(), True) browse_deltas.makedirs(browse_product_path, recreate=True) db.create_browse_product( browse_product_lidvid, fits_product_lidvid, str(browse_collection_lidvid), ) db.create_collection_product_link(str(browse_collection_lidvid), browse_product_lidvid) for fits_file in browse_deltas.listdir(product_path): fits_filepath = fs.path.join(product_path, fits_file) fits_os_filepath = browse_deltas.getsyspath(fits_filepath) browse_file = fs.path.splitext(fits_file)[0] + ".jpg" browse_filepath = fs.path.join(browse_product_path, browse_file) # In a COWFS, a directory does not have a # syspath, only files. So we write a stub # file into the directory, find its syspath # and its directory's syspath. Then we remove # the stub file. browse_deltas.touch(browse_filepath) browse_product_os_filepath = browse_deltas.getsyspath( browse_filepath) browse_deltas.remove(browse_filepath) browse_product_os_dirpath = fs.path.dirname( browse_product_os_filepath) # Picmaker expects a list of strings. If you give it # str, it'll index into it and complain about '/' # not being a file. So don't do that! try: picmaker.ImagesToPics( [str(fits_os_filepath)], browse_product_os_dirpath, filter="None", percentiles=(1, 99), ) except IndexError as e: tb = traceback.format_exc() message = f"File {fits_file}: {e}\n{tb}" raise Exception(message) browse_os_filepath = fs.path.join(browse_product_os_dirpath, browse_file) size = os.stat(browse_os_filepath).st_size db.create_browse_file(browse_os_filepath, browse_file, browse_product_lidvid, size) else: bpl = LIDVID(browse_product_lidvid) changes_dict.set(bpl.lid(), bpl.vid(), False) db.create_collection_product_link(str(browse_collection_lidvid), browse_product_lidvid)