diff --git a/csst_dfs_api_local/ifs/__init__.py b/csst_dfs_api_local/ifs/__init__.py index edcd27952cea6efd8159ef20021440bf814841c2..d554c8095abd71ed5702ebbb8a289617fccaeb61 100644 --- a/csst_dfs_api_local/ifs/__init__.py +++ b/csst_dfs_api_local/ifs/__init__.py @@ -27,11 +27,14 @@ def ingest(): elif 'sky' in filename.lower(): file_type = 'sky' + file_path = file_full_path.replace(root_dir, '') + if file_path.index("/") == 0: + file_path = file_path[1:] if file_type in ['obs']: - fitsApi.import2db(file_path = file_full_path.replace(root_dir, '')[1:]) + fitsApi.import2db(file_path = file_path) print("%s [type:%s] imported" %(file_full_path, file_type)) if file_type in ['flat', 'bias', 'arc','hgar', 'sky']: - refApi.import2db(file_path = file_full_path.replace(root_dir, '')[1:]) + refApi.import2db(file_path = file_path) print("%s [type:%s] imported" %(file_full_path, file_type)) return paths diff --git a/csst_dfs_api_local/ifs/fits.py b/csst_dfs_api_local/ifs/fits.py index 598e700acd5d0d8015ee3f6bc3cbe75f41fdf88f..0574c70e95ae851f9b9d6207e206eb588fdb12c9 100644 --- a/csst_dfs_api_local/ifs/fits.py +++ b/csst_dfs_api_local/ifs/fits.py @@ -27,10 +27,6 @@ class FitsApi(object): log.info("using [%s] as root directory", self.root_dir) if not os.path.exists(os.path.join(self.root_dir, "fits")): os.mkdir(os.path.join(self.root_dir, "fits")) - if not os.path.exists(os.path.join(self.root_dir, "refs")): - os.mkdir(os.path.join(self.root_dir, "refs")) - if not os.path.exists(os.path.join(self.root_dir, "results")): - os.mkdir(os.path.join(self.root_dir, "results")) def find(self, **kwargs): ''' @@ -216,4 +212,8 @@ class FitsApi(object): new_file_path = os.path.join(new_file_dir, file_basename) shutil.copyfile(file_path, new_file_path) - self.import2db(file_path = new_file_path.replace(self.root_dir, '')[1:]) \ No newline at end of file + file_path = new_file_path.replace(self.root_dir, '') + if file_path.index("/") == 0: + file_path = file_path[1:] + + self.import2db(file_path = file_path) \ No newline at end of file diff --git a/csst_dfs_api_local/ifs/reffits.py b/csst_dfs_api_local/ifs/reffits.py index d4599640bbbe4eb42dea4b00c78a690e3b785907..18733a11735746041c729da3ea4eced34c7f3a1a 100644 --- a/csst_dfs_api_local/ifs/reffits.py +++ b/csst_dfs_api_local/ifs/reffits.py @@ -208,7 +208,11 @@ class RefFitsApi(object): new_file_path = os.path.join(new_file_dir, file_basename) shutil.copyfile(file_path, new_file_path) - self.import2db(file_path = new_file_path.replace(self.root_dir, '')[1:]) + file_path = new_file_path.replace(self.root_dir, '') + if file_path.index("/") == 0: + file_path = file_path[1:] + + self.import2db(file_path = file_path) def associate_raw(self, **kwargs): diff --git a/csst_dfs_api_local/ifs/result0.py b/csst_dfs_api_local/ifs/result0.py index fbb9fd857c1fb7d52175561a615e34728a70ffd7..40d2ff0a9004cd2007dd9b7f449f7483493a531a 100644 --- a/csst_dfs_api_local/ifs/result0.py +++ b/csst_dfs_api_local/ifs/result0.py @@ -114,10 +114,14 @@ class Result0Api(object): new_file_path = os.path.join(new_file_dir, file_basename) shutil.copyfile(file_path, new_file_path) + file_path = new_file_path.replace(self.root_dir, '') + if file_path.index("/") == 0: + file_path = file_path[1:] + self.db.execute( 'INSERT INTO ifs_result_0 (filename, file_path, raw_id, proc_type, create_time) \ VALUES(?,?,?,?,?)', - (file_basename, new_file_path.replace(self.root_dir, '')[1:], raw_id, proc_type, format_time_ms(time.time())) + (file_basename, file_path, raw_id, proc_type, format_time_ms(time.time())) ) self.db.end() diff --git a/csst_dfs_api_local/ifs/result1.py b/csst_dfs_api_local/ifs/result1.py index d32ca600377c57b7aee4e63e20e6483dace147c0..8977a065b7d703e4b0f3c053961d16dbddce1cca 100644 --- a/csst_dfs_api_local/ifs/result1.py +++ b/csst_dfs_api_local/ifs/result1.py @@ -110,10 +110,14 @@ class Result1Api(object): shutil.copyfile(file_path, new_file_path) + file_path = new_file_path.replace(self.root_dir, '') + if file_path.index("/") == 0: + file_path = file_path[1:] + self.db.execute( 'INSERT INTO ifs_result_1 (filename, file_path, proc_type, create_time) \ VALUES(?,?,?,?)', - (file_basename, new_file_path.replace(self.root_dir, '')[1:], proc_type, format_time_ms(time.time()),) + (file_basename, file_path, proc_type, format_time_ms(time.time()),) ) self.db.end() result1_id = 1