fix when files are unlocked or saved
This commit is contained in:
parent
a9cc2b3f48
commit
96731baeb9
1 changed files with 11 additions and 6 deletions
|
|
@ -34,22 +34,28 @@ def write_measurement(path: str, ensemble: str, measurement: dict[str, dict[str,
|
||||||
"""
|
"""
|
||||||
db_file = get_db_file(path)
|
db_file = get_db_file(path)
|
||||||
db = os.path.join(path, db_file)
|
db = os.path.join(path, db_file)
|
||||||
|
|
||||||
|
files_to_save = []
|
||||||
|
|
||||||
get(path, db_file)
|
get(path, db_file)
|
||||||
unlock(path, db_file)
|
unlock(path, db_file)
|
||||||
|
files_to_save.append(db_file)
|
||||||
|
|
||||||
conn = sqlite3.connect(db)
|
conn = sqlite3.connect(db)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
files = []
|
|
||||||
for corr in measurement.keys():
|
for corr in measurement.keys():
|
||||||
file_in_archive = os.path.join('.', 'archive', ensemble, corr, uuid + '.json.gz')
|
file_in_archive = os.path.join('.', 'archive', ensemble, corr, uuid + '.json.gz')
|
||||||
file = os.path.join(path, file_in_archive)
|
file = os.path.join(path, file_in_archive)
|
||||||
files.append(file)
|
|
||||||
known_meas = {}
|
known_meas = {}
|
||||||
if not os.path.exists(os.path.join(path, '.', 'archive', ensemble, corr)):
|
if not os.path.exists(os.path.join(path, '.', 'archive', ensemble, corr)):
|
||||||
os.makedirs(os.path.join(path, '.', 'archive', ensemble, corr))
|
os.makedirs(os.path.join(path, '.', 'archive', ensemble, corr))
|
||||||
|
files_to_save.append(file_in_archive)
|
||||||
else:
|
else:
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
|
if file not in files_to_save:
|
||||||
unlock(path, file_in_archive)
|
unlock(path, file_in_archive)
|
||||||
known_meas = pj.load_json_dict(file)
|
files_to_save.append(file_in_archive)
|
||||||
|
known_meas = pj.load_json_dict(file, verbose=False)
|
||||||
if code == "sfcf":
|
if code == "sfcf":
|
||||||
parameters = sfcf.read_param(path, uuid, parameter_file)
|
parameters = sfcf.read_param(path, uuid, parameter_file)
|
||||||
pars = {}
|
pars = {}
|
||||||
|
|
@ -98,9 +104,8 @@ def write_measurement(path: str, ensemble: str, measurement: dict[str, dict[str,
|
||||||
(corr, ensemble, code, meas_path, uuid, pars[subkey], parameter_file))
|
(corr, ensemble, code, meas_path, uuid, pars[subkey], parameter_file))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
pj.dump_dict_to_json(known_meas, file)
|
pj.dump_dict_to_json(known_meas, file)
|
||||||
files.append(os.path.join(path, db_file))
|
|
||||||
conn.close()
|
conn.close()
|
||||||
save(path, message="Add measurements to database", files=files)
|
save(path, message="Add measurements to database", files=files_to_save)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue