rename getter for the database file name
This commit is contained in:
parent
14d19ce9dd
commit
3d91509ab6
5 changed files with 30 additions and 30 deletions
|
|
@ -1,22 +1,22 @@
|
|||
from typing import Union, Optional
|
||||
from typing import Optional
|
||||
import os
|
||||
import shutil
|
||||
from .tools import record2name_key
|
||||
from pyerrors import dump_object
|
||||
import datalad.api as dl
|
||||
import sqlite3
|
||||
from tools import db_filename
|
||||
|
||||
|
||||
def get_version_hash(path, record):
|
||||
db = os.path.join(path, "backlogger.db")
|
||||
def get_version_hash(path: str, record: str) -> str:
|
||||
db = os.path.join(path, db_filename(path))
|
||||
dl.get(db, dataset=path)
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
c.execute(f"SELECT current_version FROM 'backlogs' WHERE path = '{record}'")
|
||||
return c.fetchall()[0][0]
|
||||
return str(c.fetchall()[0][0])
|
||||
|
||||
|
||||
def drop_cache_files(path: str, fs: Optional[list[str]]=None):
|
||||
def drop_cache_files(path: str, fs: Optional[list[str]]=None) -> None:
|
||||
cache_dir = os.path.join(path, ".cache")
|
||||
if fs is None:
|
||||
fs = os.listdir(cache_dir)
|
||||
|
|
@ -24,7 +24,7 @@ def drop_cache_files(path: str, fs: Optional[list[str]]=None):
|
|||
shutil.rmtree(os.path.join(cache_dir, f))
|
||||
|
||||
|
||||
def cache_dir(path, file):
|
||||
def cache_dir(path: str, file: str) -> str:
|
||||
cache_path_list = [path]
|
||||
cache_path_list.append(".cache")
|
||||
cache_path_list.extend(file.split("/")[1:])
|
||||
|
|
@ -32,27 +32,27 @@ def cache_dir(path, file):
|
|||
return cache_path
|
||||
|
||||
|
||||
def cache_path(path, file, sha_hash, key):
|
||||
def cache_path(path: str, file: str, sha_hash: str, key: str) -> str:
|
||||
cache_path = os.path.join(cache_dir(path, file), key + "_" + sha_hash)
|
||||
return cache_path
|
||||
|
||||
|
||||
def is_old_version(path, record):
|
||||
def is_old_version(path: str, record: str) -> bool:
|
||||
version_hash = get_version_hash(path, record)
|
||||
file, key = record2name_key(record)
|
||||
meas_cache_path = os.path.join(cache_dir(path, file))
|
||||
ls = []
|
||||
is_old = True
|
||||
for p, ds, fs in os.walk(meas_cache_path):
|
||||
ls.extend(fs)
|
||||
for filename in ls:
|
||||
if key == filename.split("_")[0]:
|
||||
if not version_hash == filename.split("_")[1][:-2]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
if version_hash == filename.split("_")[1][:-2]:
|
||||
is_old = False
|
||||
return is_old
|
||||
|
||||
|
||||
def is_in_cache(path, record):
|
||||
def is_in_cache(path: str, record: str) -> bool:
|
||||
version_hash = get_version_hash(path, record)
|
||||
file, key = record2name_key(record)
|
||||
return os.path.exists(cache_path(path, file, version_hash, key) + ".p")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue