ensure db get before query #5
4 changed files with 18 additions and 10 deletions
ensure db get before query
commit
2940ee9055
|
|
@ -143,8 +143,7 @@ def find_record(path, ensemble, correlator_name, code, project=None, parameters=
|
|||
db = path + '/backlogger.db'
|
||||
if code not in codes:
|
||||
raise ValueError("Code " + code + "unknown, take one of the following:" + ", ".join(codes))
|
||||
if os.path.exists(db):
|
||||
dl.get(db, dataset=path)
|
||||
dl.get(db, dataset=path)
|
||||
results = _db_lookup(db, ensemble, correlator_name,code, project, parameters=parameters, created_before=created_before, created_after=created_after, updated_before=updated_before, updated_after=updated_after, revision=revision)
|
||||
if code == "sfcf":
|
||||
results = sfcf_filter(results, **kwargs)
|
||||
|
|
@ -152,12 +151,14 @@ def find_record(path, ensemble, correlator_name, code, project=None, parameters=
|
|||
return results.reset_index()
|
||||
|
||||
|
||||
def find_project(db, name):
|
||||
def find_project(path, db, name):
|
||||
dl.get(db, dataset=path)
|
||||
return _project_lookup_by_alias(db, name)
|
||||
|
||||
|
||||
def list_projects(path):
|
||||
db = path + '/backlogger.db'
|
||||
dl.get(db, dataset=path)
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT id,aliases FROM projects")
|
||||
|
|
|
|||
|
|
@ -24,13 +24,15 @@ def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Uni
|
|||
code: str (optional)
|
||||
The code that was used to create the measurements.
|
||||
"""
|
||||
conn = sqlite3.connect(path + "/backlogger.db")
|
||||
db = path + "/backlogger.db"
|
||||
dl.get(db, dataset=path)
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
known_projects = c.execute("SELECT * FROM projects WHERE id=?", (uuid,))
|
||||
if known_projects.fetchone():
|
||||
raise ValueError("Project already imported, use update_project() instead.")
|
||||
|
||||
dl.unlock(path + "/backlogger.db", dataset=path)
|
||||
dl.unlock(db, dataset=path)
|
||||
alias_str = None
|
||||
if aliases is not None:
|
||||
alias_str = list2str(aliases)
|
||||
|
|
@ -40,10 +42,11 @@ def create_project(path: str, uuid: str, owner: Union[str, None]=None, tags: Uni
|
|||
c.execute("INSERT INTO projects (id, aliases, customTags, owner, code, created_at, updated_at) VALUES (?, ?, ?, ?, ?, datetime('now'), datetime('now'))", (uuid, alias_str, tag_str, owner, code))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
dl.save(path + "/backlogger.db", message="Added entry for project " + uuid + " to database", dataset=path)
|
||||
dl.save(db, message="Added entry for project " + uuid + " to database", dataset=path)
|
||||
|
||||
|
||||
def update_project_data(db, uuid, prop, value = None):
|
||||
def update_project_data(path, db, uuid, prop, value = None):
|
||||
dl.get(db, dataset=path)
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
c.execute(f"UPDATE projects SET '{prop}' = '{value}' WHERE id == '{uuid}'")
|
||||
|
|
@ -54,6 +57,7 @@ def update_project_data(db, uuid, prop, value = None):
|
|||
|
||||
def update_aliases(path: str, uuid: str, aliases: list[str]):
|
||||
db = os.path.join(path, "backlogger.db")
|
||||
dl.get(db, dataset=path)
|
||||
known_data = _project_lookup_by_id(db, uuid)[0]
|
||||
known_aliases = known_data[1]
|
||||
|
||||
|
|
@ -117,11 +121,13 @@ def import_project(path: str, url: str, owner: Union[str, None]=None, tags: Unio
|
|||
if not uuid:
|
||||
raise ValueError("The dataset does not have a uuid!")
|
||||
if not os.path.exists(path + "/projects/" + uuid):
|
||||
dl.unlock(path + "/backlogger.db", dataset=path)
|
||||
db = path + "/backlogger.db"
|
||||
dl.get(db, ds=path)
|
||||
dl.unlock(db, dataset=path)
|
||||
create_project(path, uuid, owner, tags, aliases, code)
|
||||
move_submodule(path, 'projects/tmp', 'projects/' + uuid)
|
||||
os.mkdir(path + '/import_scripts/' + uuid)
|
||||
dl.save([path + "/backlogger.db", path + '/projects/' + uuid], message="Import project from " + url, dataset=path)
|
||||
dl.save([db, path + '/projects/' + uuid], message="Import project from " + url, dataset=path)
|
||||
else:
|
||||
dl.drop(tmp_path, reckless='kill')
|
||||
shutil.rmtree(tmp_path)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ def write_measurement(path, ensemble, measurement, uuid, code, parameter_file=No
|
|||
The uuid of the project.
|
||||
"""
|
||||
db = os.path.join(path, 'backlogger.db')
|
||||
dl.get(db, ds=path)
|
||||
dl.unlock(db, dataset=path)
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
|
|
@ -176,6 +177,7 @@ def drop_record(path: str, meas_path: str):
|
|||
file_in_archive = meas_path.split("::")[0]
|
||||
file = os.path.join(path, file_in_archive)
|
||||
db = os.path.join(path, 'backlogger.db')
|
||||
dl.get(db, ds=path)
|
||||
sub_key = meas_path.split("::")[1]
|
||||
dl.unlock(db, dataset=path)
|
||||
conn = sqlite3.connect(db)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
|
||||
|
||||
def str2list(string):
|
||||
return string.split(",")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue