Commit 1abe728d authored by Wei Shoulin's avatar Wei Shoulin
Browse files

fill file_path

parent c66fb6d8
...@@ -66,9 +66,10 @@ class FitsApi(object): ...@@ -66,9 +66,10 @@ class FitsApi(object):
if file_name: if file_name:
sql = ["select * from ifs_rawfits where filename='" + file_name + "'"] sql = ["select * from ifs_rawfits where filename='" + file_name + "'"]
_, r = self.db.select_many("".join(sql)) _, recs = self.db.select_many("".join(sql))
for r in recs:
return r r['file_path'] = os.path.join(self.root_dir, r['file_path'])
return recs
def get(self, **kwargs): def get(self, **kwargs):
''' '''
...@@ -80,6 +81,8 @@ class FitsApi(object): ...@@ -80,6 +81,8 @@ class FitsApi(object):
fits_id = get_parameter(kwargs, "fits_id", -1) fits_id = get_parameter(kwargs, "fits_id", -1)
r = self.db.select_one( r = self.db.select_one(
"select * from ifs_rawfits where id=?", (fits_id,)) "select * from ifs_rawfits where id=?", (fits_id,))
if r:
r['file_path'] = os.path.join(self.root_dir, r['file_path'])
return r return r
def read(self, **kwargs): def read(self, **kwargs):
......
...@@ -67,9 +67,11 @@ class RefFitsApi(object): ...@@ -67,9 +67,11 @@ class RefFitsApi(object):
if file_name: if file_name:
sql = ["select * from ifs_ref_fits where filename='" + file_name + "'"] sql = ["select * from ifs_ref_fits where filename='" + file_name + "'"]
sql.append(" order by exp_time desc") 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): def get(self, **kwargs):
'''query database, return a record as dict '''query database, return a record as dict
...@@ -82,6 +84,8 @@ class RefFitsApi(object): ...@@ -82,6 +84,8 @@ class RefFitsApi(object):
fits_id = get_parameter(kwargs, "fits_id", -1) fits_id = get_parameter(kwargs, "fits_id", -1)
r = self.db.select_one( r = self.db.select_one(
"select * from ifs_ref_fits where id=?", (fits_id,)) "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 return r
def read(self, **kwargs): def read(self, **kwargs):
......
...@@ -47,9 +47,11 @@ class Result0Api(object): ...@@ -47,9 +47,11 @@ class Result0Api(object):
if file_name: if file_name:
sql = ["select * from ifs_result_0 where filename='" + 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): def get(self, **kwargs):
''' query database, return a record as dict ''' query database, return a record as dict
...@@ -62,6 +64,8 @@ class Result0Api(object): ...@@ -62,6 +64,8 @@ class Result0Api(object):
fits_id = get_parameter(kwargs, "fits_id", -1) fits_id = get_parameter(kwargs, "fits_id", -1)
r = self.db.select_one( r = self.db.select_one(
"select * from ifs_result_0 where id=?", (fits_id,)) "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 return r
def read(self, **kwargs): def read(self, **kwargs):
......
...@@ -39,9 +39,11 @@ class Result1Api(object): ...@@ -39,9 +39,11 @@ class Result1Api(object):
if file_name: if file_name:
sql = ["select * from ifs_result_1 where filename='" + 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): def get(self, **kwargs):
''' '''
...@@ -56,7 +58,8 @@ class Result1Api(object): ...@@ -56,7 +58,8 @@ class Result1Api(object):
_, result0s = self.db.select_many( _, result0s = self.db.select_many(
"select result0_id, create_time from ifs_result_0_1 where result1_id=?", (fits_id,)) "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 return r, result0s
def read(self, **kwargs): def read(self, **kwargs):
......
...@@ -9,6 +9,13 @@ class IFSFitsTestCase(unittest.TestCase): ...@@ -9,6 +9,13 @@ class IFSFitsTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.api = FitsApi() 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): def test_find(self):
recs = self.api.find(file_name='CCD1_ObsTime_300_ObsNum_7.fits') recs = self.api.find(file_name='CCD1_ObsTime_300_ObsNum_7.fits')
print('find:', recs) print('find:', recs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment