diff --git a/csst_dfs_api_local/ifs/fits.py b/csst_dfs_api_local/ifs/fits.py index 0574c70e95ae851f9b9d6207e206eb588fdb12c9..838c8d7388faaa9fc705a9d8196f0b37232d5f46 100644 --- a/csst_dfs_api_local/ifs/fits.py +++ b/csst_dfs_api_local/ifs/fits.py @@ -66,9 +66,10 @@ class FitsApi(object): if file_name: sql = ["select * from ifs_rawfits where filename='" + file_name + "'"] - _, r = self.db.select_many("".join(sql)) - - return r + _, recs = self.db.select_many("".join(sql)) + for r in recs: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) + return recs def get(self, **kwargs): ''' @@ -80,6 +81,8 @@ class FitsApi(object): fits_id = get_parameter(kwargs, "fits_id", -1) r = self.db.select_one( "select * from ifs_rawfits where id=?", (fits_id,)) + if r: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) return r def read(self, **kwargs): diff --git a/csst_dfs_api_local/ifs/reffits.py b/csst_dfs_api_local/ifs/reffits.py index 18733a11735746041c729da3ea4eced34c7f3a1a..2fe7585c1ba7f2907c2ddfbd04c0616454d77ab2 100644 --- a/csst_dfs_api_local/ifs/reffits.py +++ b/csst_dfs_api_local/ifs/reffits.py @@ -67,9 +67,11 @@ class RefFitsApi(object): if file_name: sql = ["select * from ifs_ref_fits where filename='" + file_name + "'"] sql.append(" order by exp_time desc") - _, r = self.db.select_many("".join(sql)) + _, recs = self.db.select_many("".join(sql)) - return r + for r in recs: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) + return recs def get(self, **kwargs): '''query database, return a record as dict @@ -82,6 +84,8 @@ class RefFitsApi(object): fits_id = get_parameter(kwargs, "fits_id", -1) r = self.db.select_one( "select * from ifs_ref_fits where id=?", (fits_id,)) + if r: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) return r def read(self, **kwargs): diff --git a/csst_dfs_api_local/ifs/result0.py b/csst_dfs_api_local/ifs/result0.py index 40d2ff0a9004cd2007dd9b7f449f7483493a531a..4fd63cb8b4f11eeaa9b8c3f5f6fa54b1387fa888 100644 --- a/csst_dfs_api_local/ifs/result0.py +++ b/csst_dfs_api_local/ifs/result0.py @@ -47,9 +47,11 @@ class Result0Api(object): if file_name: sql = ["select * from ifs_result_0 where filename='" + file_name + "'"] - _, r = self.db.select_many("".join(sql)) + _, recs = self.db.select_many("".join(sql)) - return r + for r in recs: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) + return recs def get(self, **kwargs): ''' query database, return a record as dict @@ -62,6 +64,8 @@ class Result0Api(object): fits_id = get_parameter(kwargs, "fits_id", -1) r = self.db.select_one( "select * from ifs_result_0 where id=?", (fits_id,)) + if r: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) return r def read(self, **kwargs): diff --git a/csst_dfs_api_local/ifs/result1.py b/csst_dfs_api_local/ifs/result1.py index 8977a065b7d703e4b0f3c053961d16dbddce1cca..2a5924b9e95150a45036296b2939faed9f608398 100644 --- a/csst_dfs_api_local/ifs/result1.py +++ b/csst_dfs_api_local/ifs/result1.py @@ -39,9 +39,11 @@ class Result1Api(object): if file_name: sql = ["select * from ifs_result_1 where filename='" + file_name + "'"] - _, r = self.db.select_many("".join(sql)) + _, recs = self.db.select_many("".join(sql)) - return r + for r in recs: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) + return recs def get(self, **kwargs): ''' @@ -56,7 +58,8 @@ class Result1Api(object): _, result0s = self.db.select_many( "select result0_id, create_time from ifs_result_0_1 where result1_id=?", (fits_id,)) - + if r: + r['file_path'] = os.path.join(self.root_dir, r['file_path']) return r, result0s def read(self, **kwargs): diff --git a/tests/test_ifs_fits.py b/tests/test_ifs_fits.py index 7b8c40ae639de9f8f420d8107d8282f972e6e449..64ae1a58d3a52ce3ecefaef4b2447b870e704272 100644 --- a/tests/test_ifs_fits.py +++ b/tests/test_ifs_fits.py @@ -9,6 +9,13 @@ class IFSFitsTestCase(unittest.TestCase): def setUp(self): self.api = FitsApi() + def test_get(self): + r = self.api.get(fits_id=1111) + print('get:', r) + + r = self.api.get(fits_id=1) + print('get:', r) + def test_find(self): recs = self.api.find(file_name='CCD1_ObsTime_300_ObsNum_7.fits') print('find:', recs)