def __make_path_name(fits, image_maker, save_format, file_name): file_path = dbformat( save_format, fits, file_name=file_name, extension=image_maker.extension, event_id=fits.event.event_id, ) return dbroot(file_path)
def test_singlerow(self): h = Hek_Event() h.x_min = 10 h.description = "Hello" h.hpc_x = 1.2 blank_format = "{x_min} {description} {hpc_x}" desired = "10 Hello 1.2" new = ut.dbformat(blank_format, h) self.assertEqual(new, desired)
def test_multirow(self): h = Hek_Event() v = Visual_File() h.x_min = 10 h.description = "Hello" h.hpc_x = 1.2 v.visual_generator = "TEST1" v.description = "TEST2" v.im_ll_x = 1.2 blank_format = ( "{x_min} {description} {hpc_x} {visual_generator} {description} {im_ll_x}" ) desired = "10 Hello 1.2 TEST1 Hello 1.2" new = ut.dbformat(blank_format, h, v) self.assertEqual(new, desired)
def __create_new_image( input_file: Any, visual_builder: Any, save_format: str = Config.storage_path.img, file_name_format: str = Config.file_storage.img, desc: str = "", overwrite=True, ): base_fits = input_file file_name = dbformat(file_name_format, base_fits, visual_builder) print(base_fits.file_name.stem) full_path = dbpathformat(file_name_format, save_format, base_fits, visual_builder, base_fits.event) im, exists = Visual_File.__try_create_visual(full_path, file_name, visual_builder, desc) source_path = base_fits.file_path if not Visual_File.__report_status("image", exists, overwrite): return None created = visual_builder.create(source_path) if not created: return None visual_builder.save_visual(base_fits, full_path) im.__assign_generated_parameters(visual_builder) im.save() join = Visual_File.__get_create_join(im, base_fits) join.save() im.get_hash() return im
def __create_new_video( input_files: Any, visual_builder: Any, save_format: str = Config.storage_path.img, file_name_format: str = Config.file_storage.img, desc: str = "", overwrite=True, base_fits=None, ): base_fits = base_fits if base_fits else input_files[0] file_name = dbformat(file_name_format, base_fits, visual_builder) full_path = dbpathformat(file_name_format, save_format, base_fits, visual_builder, base_fits.event) im, exists = Visual_File.__try_create_visual(full_path, file_name, visual_builder, desc) source_paths = [x.file_path for x in input_files] if not Visual_File.__report_status("video", exists, overwrite): return None created = visual_builder.create(source_paths) if not created: return None visual_builder.save_visual(base_fits, full_path) im.__assign_generated_parameters(visual_builder) im.set_visual_hash() im.save() joins = Visual_File.__get_joins(im, input_files) for j in joins: j.save() im.get_hash() return im
def rename(self, file_name_format=None, file_path_format=None, *args, **kwargs): """Function rename: Rename a file within the database, and move it to the new location The format strings may use any parameters, provided that they appear either in one of the dict-like object or classes passed to *args, or as one of the kwargs. file_path_format takes the special argument "ffilename" which is the result, after formatting, of file_name_format. :param file_name_format: The format to use for the name of the file, defaults to None :type file_name_format: str :param file_path_format: The format to use for the path, defaults to None :type file_path_format: str :param *args: List of dictionary-like objects :type *args: List[dict] :returns: None :type return: None """ if not file_name_format: file_name_format = self.file_name_format if not file_path_format: file_path_format = self.file_path_format old_path = self.file_path self.file_path = dbpathformat(file_name_format, file_path_format, *args, **kwargs) self.file_name = dbformat(file_name_format, *args, **kwargs) p = Path(self.file_path) p.parent.mkdir(parents=True, exist_ok=True) self.save() shutil.move(old_path, self.file_path)
def make_path(fits_model, default_format=Config.storage_path.fits, **kwargs): return dbroot(dbformat(default_format, fits_model, **kwargs))
def test_dict(self): blank_format = "{test1} {test2} {test3}" vals = {"test1": 20, "test2": "Hello", "test3": [1, 2, 3]} baseline = blank_format.format(**vals) new = ut.dbformat(blank_format, **vals) self.assertEqual(new, baseline)