pyBiocFileCache 0.3.1__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyBiocFileCache-0.3.1.dist-info → pyBiocFileCache-0.4.1.dist-info}/AUTHORS.md +1 -0
- {pyBiocFileCache-0.3.1.dist-info → pyBiocFileCache-0.4.1.dist-info}/METADATA +6 -6
- pyBiocFileCache-0.4.1.dist-info/RECORD +13 -0
- {pyBiocFileCache-0.3.1.dist-info → pyBiocFileCache-0.4.1.dist-info}/WHEEL +1 -1
- pybiocfilecache/BiocFileCache.py +14 -17
- pybiocfilecache/__init__.py +2 -2
- pybiocfilecache/const.py +1 -0
- pybiocfilecache/db/__init__.py +1 -1
- pybiocfilecache/db/db_config.py +82 -0
- pybiocfilecache/utils.py +2 -6
- pyBiocFileCache-0.3.1.dist-info/RECORD +0 -13
- pybiocfilecache/db/Base.py +0 -36
- pybiocfilecache/db/schema.py +0 -35
- {pyBiocFileCache-0.3.1.dist-info → pyBiocFileCache-0.4.1.dist-info}/LICENSE.txt +0 -0
- {pyBiocFileCache-0.3.1.dist-info → pyBiocFileCache-0.4.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyBiocFileCache
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: File based cache for resources and metadata
|
|
5
5
|
Home-page: https://github.com/epiviz/pyBiocFileCache
|
|
6
6
|
Author: jkanche
|
|
@@ -13,12 +13,12 @@ Classifier: Programming Language :: Python
|
|
|
13
13
|
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
14
|
License-File: LICENSE.txt
|
|
15
15
|
License-File: AUTHORS.md
|
|
16
|
-
Requires-Dist:
|
|
17
|
-
Requires-Dist:
|
|
16
|
+
Requires-Dist: importlib-metadata; python_version < "3.8"
|
|
17
|
+
Requires-Dist: sqlalchemy<2.1,>=2
|
|
18
18
|
Provides-Extra: testing
|
|
19
|
-
Requires-Dist: setuptools
|
|
20
|
-
Requires-Dist: pytest
|
|
21
|
-
Requires-Dist: pytest-cov
|
|
19
|
+
Requires-Dist: setuptools; extra == "testing"
|
|
20
|
+
Requires-Dist: pytest; extra == "testing"
|
|
21
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
22
22
|
|
|
23
23
|
[](https://pyscaffold.org/)
|
|
24
24
|
[](https://pypi.org/project/pyBiocFileCache/)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
pybiocfilecache/BiocFileCache.py,sha256=-aqTaPtTSXVi6sBP7VnXEXYOHgZHzDcCK1zJmw3u_3I,8691
|
|
2
|
+
pybiocfilecache/__init__.py,sha256=IAUOQ-SoVfKXEexvljUBJQrVrntYZUxxgFXnlEGi2jY,921
|
|
3
|
+
pybiocfilecache/_exceptions.py,sha256=347Lt1Rrt-TTzP5yEqlRM1QoaPBXB1UnZXv0GfhZmv0,374
|
|
4
|
+
pybiocfilecache/const.py,sha256=c9167eSCGBp0wF1xuAEvr-fbYCzp0lcOtKF9sqxlLF8,26
|
|
5
|
+
pybiocfilecache/utils.py,sha256=dJBZpLqAoD4qIW9SVBTGeoiYjxraeswAOApQxACpSAU,2018
|
|
6
|
+
pybiocfilecache/db/__init__.py,sha256=v1G_gueaai3eECWSgj1G4EPH631x1Yg3AiSoY2jVJHE,107
|
|
7
|
+
pybiocfilecache/db/db_config.py,sha256=UNtjzyZ1Et3j183OUXd5iiyHshGqxwTSUPmqzuxmTi4,2346
|
|
8
|
+
pyBiocFileCache-0.4.1.dist-info/AUTHORS.md,sha256=ptvMLokf9Knfp0Ng-dHSgtEimkXWZhjZAR_o2aJm9bw,161
|
|
9
|
+
pyBiocFileCache-0.4.1.dist-info/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
|
|
10
|
+
pyBiocFileCache-0.4.1.dist-info/METADATA,sha256=Ithgx-0PCLVCF9k1klrqSzo5RE9g4LZkRAMtmYs1hA4,2530
|
|
11
|
+
pyBiocFileCache-0.4.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
12
|
+
pyBiocFileCache-0.4.1.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
|
|
13
|
+
pyBiocFileCache-0.4.1.dist-info/RECORD,,
|
pybiocfilecache/BiocFileCache.py
CHANGED
|
@@ -9,8 +9,7 @@ from sqlalchemy import func
|
|
|
9
9
|
from sqlalchemy.orm import Session
|
|
10
10
|
|
|
11
11
|
from ._exceptions import NoFpathError, RnameExistsError, RpathTimeoutError
|
|
12
|
-
from .db import create_schema
|
|
13
|
-
from .db.schema import Resource
|
|
12
|
+
from .db.db_config import create_schema, Resource
|
|
14
13
|
from .utils import copy_or_move, create_tmp_dir, generate_id
|
|
15
14
|
|
|
16
15
|
__author__ = "Jayaram Kancherla"
|
|
@@ -96,11 +95,7 @@ class BiocFileCache:
|
|
|
96
95
|
raise NoFpathError(f"Resource at '{fpath}' does not exist.")
|
|
97
96
|
|
|
98
97
|
rid = generate_id()
|
|
99
|
-
rpath = (
|
|
100
|
-
f"{self.cache}/{rid}" + (f".{fpath.suffix}" if ext else "")
|
|
101
|
-
if action != "asis"
|
|
102
|
-
else str(fpath)
|
|
103
|
-
)
|
|
98
|
+
rpath = f"{self.cache}/{rid}" + (f".{fpath.suffix}" if ext else "") if action != "asis" else str(fpath)
|
|
104
99
|
|
|
105
100
|
# create new record in the database
|
|
106
101
|
res = Resource(
|
|
@@ -152,11 +147,7 @@ class BiocFileCache:
|
|
|
152
147
|
List of matching resources from cache.
|
|
153
148
|
"""
|
|
154
149
|
with self.sessionLocal() as session:
|
|
155
|
-
return (
|
|
156
|
-
session.query(Resource)
|
|
157
|
-
.filter(Resource[field].ilike("%{}%".format(query)))
|
|
158
|
-
.all()
|
|
159
|
-
)
|
|
150
|
+
return session.query(Resource).filter(Resource[field].ilike("%{}%".format(query))).all()
|
|
160
151
|
|
|
161
152
|
def _get(self, session: Session, rname: str) -> Optional[Resource]:
|
|
162
153
|
"""Get a resource with `rname` from given `Session`.
|
|
@@ -171,9 +162,7 @@ class BiocFileCache:
|
|
|
171
162
|
Returns:
|
|
172
163
|
The `Resource` for the `rname` if available.
|
|
173
164
|
"""
|
|
174
|
-
resource: Optional[Resource] = (
|
|
175
|
-
session.query(Resource).filter(Resource.rname == rname).first()
|
|
176
|
-
)
|
|
165
|
+
resource: Optional[Resource] = session.query(Resource).filter(Resource.rname == rname).first()
|
|
177
166
|
|
|
178
167
|
if resource is not None:
|
|
179
168
|
# `Resource` may exist but `rpath` could still be being
|
|
@@ -183,8 +172,7 @@ class BiocFileCache:
|
|
|
183
172
|
while not Path(str(resource.rpath)).exists():
|
|
184
173
|
if time() - start >= timeout:
|
|
185
174
|
raise RpathTimeoutError(
|
|
186
|
-
f"For resource: '{rname}' the rpath does not exist "
|
|
187
|
-
f"after {timeout} seconds."
|
|
175
|
+
f"For resource: '{rname}' the rpath does not exist " f"after {timeout} seconds."
|
|
188
176
|
)
|
|
189
177
|
sleep(0.1)
|
|
190
178
|
|
|
@@ -275,3 +263,12 @@ class BiocFileCache:
|
|
|
275
263
|
# but lets just add it to the cache.
|
|
276
264
|
res = self.add(rname=rname, fpath=fpath, action=action)
|
|
277
265
|
return res
|
|
266
|
+
|
|
267
|
+
def list_all(self) -> List[Resource]:
|
|
268
|
+
"""List all resources currently in the cache.
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
List of all Resource objects in the cache.
|
|
272
|
+
"""
|
|
273
|
+
with self.sessionLocal() as session:
|
|
274
|
+
return session.query(Resource).all()
|
pybiocfilecache/__init__.py
CHANGED
|
@@ -17,8 +17,8 @@ finally:
|
|
|
17
17
|
|
|
18
18
|
from .BiocFileCache import BiocFileCache as BiocFileCache
|
|
19
19
|
|
|
20
|
-
from .db.
|
|
21
|
-
from .db.
|
|
20
|
+
from .db.db_config import Metadata as Metadata
|
|
21
|
+
from .db.db_config import Resource as Resource
|
|
22
22
|
|
|
23
23
|
from ._exceptions import NoFpathError as NoFpathError
|
|
24
24
|
from ._exceptions import RnameExistsError as RnameExistsError
|
pybiocfilecache/const.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
SCHEMA_VERSION = "0.99.4"
|
pybiocfilecache/db/__init__.py
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from typing import Tuple
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import create_engine, select, Column, Integer, Text, DateTime, func
|
|
4
|
+
from sqlalchemy.engine import Engine
|
|
5
|
+
from sqlalchemy.orm.session import Session
|
|
6
|
+
|
|
7
|
+
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
8
|
+
|
|
9
|
+
from ..const import SCHEMA_VERSION
|
|
10
|
+
|
|
11
|
+
__author__ = "jkanche"
|
|
12
|
+
__copyright__ = "jkanche"
|
|
13
|
+
__license__ = "MIT"
|
|
14
|
+
|
|
15
|
+
Base = declarative_base()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Metadata(Base):
|
|
19
|
+
__tablename__ = "metadata"
|
|
20
|
+
key = Column(Text(), primary_key=True, index=True)
|
|
21
|
+
value = Column(Text())
|
|
22
|
+
|
|
23
|
+
def __repr__(self):
|
|
24
|
+
return "<Metadata(key='%s', valye='%s')>" % (self.key, self.value)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Resource(Base):
|
|
28
|
+
__tablename__ = "resource"
|
|
29
|
+
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
|
30
|
+
rid = Column(Text())
|
|
31
|
+
rname = Column(Text())
|
|
32
|
+
create_time = Column(DateTime, server_default=func.now())
|
|
33
|
+
access_time = Column(DateTime, server_default=func.now())
|
|
34
|
+
rpath = Column(Text())
|
|
35
|
+
rtype = Column(Text())
|
|
36
|
+
fpath = Column(Text())
|
|
37
|
+
last_modified_time = Column(DateTime, onupdate=func.now())
|
|
38
|
+
etag = Column(Text())
|
|
39
|
+
expires = Column(DateTime)
|
|
40
|
+
|
|
41
|
+
def __repr__(self):
|
|
42
|
+
return "<Resource(id='%s', rname='%s')>" % (self.id, self.rname)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def add_metadata(key: str, value: str, engine: Engine) -> None:
|
|
46
|
+
"""Add metadata to the database.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
key:
|
|
50
|
+
Key of the metadata.
|
|
51
|
+
value:
|
|
52
|
+
Value of the metadata.
|
|
53
|
+
engine:
|
|
54
|
+
Engine
|
|
55
|
+
"""
|
|
56
|
+
with Session(engine) as session:
|
|
57
|
+
if session.scalar(select(Metadata).where(Metadata.key == key)):
|
|
58
|
+
pass
|
|
59
|
+
else:
|
|
60
|
+
new_metadata = Metadata(key=key, value=value)
|
|
61
|
+
session.add(new_metadata)
|
|
62
|
+
session.commit()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
|
|
66
|
+
"""Create the schema in the sqlite database.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
cache_dir:
|
|
70
|
+
Location where the cache directory.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
A tuple of sqlalchemy engine and session maker.
|
|
74
|
+
"""
|
|
75
|
+
engine = create_engine(f"sqlite:///{cache_dir}", connect_args={"check_same_thread": False})
|
|
76
|
+
|
|
77
|
+
Base.metadata.create_all(bind=engine, checkfirst=True)
|
|
78
|
+
sessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
79
|
+
|
|
80
|
+
add_metadata("schema_version", SCHEMA_VERSION, engine)
|
|
81
|
+
|
|
82
|
+
return (engine, sessionLocal)
|
pybiocfilecache/utils.py
CHANGED
|
@@ -60,9 +60,7 @@ def copy_or_move(
|
|
|
60
60
|
"""
|
|
61
61
|
|
|
62
62
|
if action not in ["copy", "move", "asis"]:
|
|
63
|
-
raise ValueError(
|
|
64
|
-
f"Action must be either 'move', 'copy' or 'asis', provided {action}."
|
|
65
|
-
)
|
|
63
|
+
raise ValueError(f"Action must be either 'move', 'copy' or 'asis', provided {action}.")
|
|
66
64
|
|
|
67
65
|
try:
|
|
68
66
|
if action == "copy":
|
|
@@ -84,6 +82,4 @@ def setup_logging(loglevel):
|
|
|
84
82
|
loglevel (int): minimum loglevel for emitting messages
|
|
85
83
|
"""
|
|
86
84
|
logformat = "[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
|
|
87
|
-
logging.basicConfig(
|
|
88
|
-
level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S"
|
|
89
|
-
)
|
|
85
|
+
logging.basicConfig(level=loglevel, stream=sys.stdout, format=logformat, datefmt="%Y-%m-%d %H:%M:%S")
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
pybiocfilecache/BiocFileCache.py,sha256=8Yau3LfXTo7lW18XTOOQoJ_6VW5-dQQxmSUSEal4v_Q,8589
|
|
2
|
-
pybiocfilecache/__init__.py,sha256=5SUhxaA5370FRyHOs5miL4WXxe2fNODbO_I6VRqDCB0,915
|
|
3
|
-
pybiocfilecache/_exceptions.py,sha256=347Lt1Rrt-TTzP5yEqlRM1QoaPBXB1UnZXv0GfhZmv0,374
|
|
4
|
-
pybiocfilecache/utils.py,sha256=jsaF6B1FViqfiWBJEq4ZCY7eI0bznpcozWkbGbBDH0c,2054
|
|
5
|
-
pybiocfilecache/db/Base.py,sha256=5kIUy1DHqJVKQQwVG017nh-HxCnz1XljiefJaG7c59E,948
|
|
6
|
-
pybiocfilecache/db/__init__.py,sha256=XE1DrTqLmDOM4Y4Qt3fdr6ahir5Vqug5e5v-DQexCDw,102
|
|
7
|
-
pybiocfilecache/db/schema.py,sha256=alr2YCfCmYb7xt8pzXqwpY-eBLNA3oR4nD8ruVzHo6E,1041
|
|
8
|
-
pyBiocFileCache-0.3.1.dist-info/AUTHORS.md,sha256=MMx3vll5oIcyk72Bk3N_ACfHWt5YhAlk2vBjx68m4R8,112
|
|
9
|
-
pyBiocFileCache-0.3.1.dist-info/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
|
|
10
|
-
pyBiocFileCache-0.3.1.dist-info/METADATA,sha256=B1HXt8rYFB4NO3rtQMaRkzU1Fdiv3HjB3OjV57697ro,2535
|
|
11
|
-
pyBiocFileCache-0.3.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
12
|
-
pyBiocFileCache-0.3.1.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
|
|
13
|
-
pyBiocFileCache-0.3.1.dist-info/RECORD,,
|
pybiocfilecache/db/Base.py
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
from typing import Tuple
|
|
2
|
-
|
|
3
|
-
from sqlalchemy import create_engine
|
|
4
|
-
from sqlalchemy.engine import Engine
|
|
5
|
-
|
|
6
|
-
# from sqlalchemy.ext.declarative import declarative_base
|
|
7
|
-
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
8
|
-
|
|
9
|
-
__author__ = "jkanche"
|
|
10
|
-
__copyright__ = "jkanche"
|
|
11
|
-
__license__ = "MIT"
|
|
12
|
-
|
|
13
|
-
Base = declarative_base()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def create_schema(cache_dir: str) -> Tuple[Engine, sessionmaker]:
|
|
17
|
-
"""Create the schema in the sqlite database.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
cache_dir:
|
|
21
|
-
Location where the cache directory.
|
|
22
|
-
|
|
23
|
-
Returns:
|
|
24
|
-
A tuple of sqlalchemy engine and session maker.
|
|
25
|
-
"""
|
|
26
|
-
try:
|
|
27
|
-
engine = create_engine(
|
|
28
|
-
f"sqlite:///{cache_dir}", connect_args={"check_same_thread": False}
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
Base.metadata.create_all(bind=engine, checkfirst=True)
|
|
32
|
-
sessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
33
|
-
|
|
34
|
-
return (engine, sessionLocal)
|
|
35
|
-
except Exception as e:
|
|
36
|
-
raise e
|
pybiocfilecache/db/schema.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
from sqlalchemy import Column, DateTime, Integer, String
|
|
2
|
-
from sqlalchemy.sql import func
|
|
3
|
-
|
|
4
|
-
from .Base import Base
|
|
5
|
-
|
|
6
|
-
__author__ = "jkanche"
|
|
7
|
-
__copyright__ = "jkanche"
|
|
8
|
-
__license__ = "MIT"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Metadata(Base):
|
|
12
|
-
__tablename__ = "metadata"
|
|
13
|
-
key = Column(String(), primary_key=True, index=True)
|
|
14
|
-
value = Column(String())
|
|
15
|
-
|
|
16
|
-
def __repr__(self):
|
|
17
|
-
return "<Metadata(key='%s', valye='%s')>" % (self.key, self.value)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class Resource(Base):
|
|
21
|
-
__tablename__ = "resource"
|
|
22
|
-
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
|
23
|
-
rid = Column(String())
|
|
24
|
-
rname = Column(String())
|
|
25
|
-
create_time = Column(DateTime, server_default=func.now())
|
|
26
|
-
access_time = Column(DateTime, server_default=func.now())
|
|
27
|
-
rpath = Column(String())
|
|
28
|
-
rtype = Column(String())
|
|
29
|
-
fpath = Column(String())
|
|
30
|
-
last_modified_time = Column(DateTime, onupdate=func.now())
|
|
31
|
-
etag = Column(String())
|
|
32
|
-
expires = Column(DateTime)
|
|
33
|
-
|
|
34
|
-
def __repr__(self):
|
|
35
|
-
return "<Resource(id='%s', rname='%s')>" % (self.id, self.rname)
|
|
File without changes
|
|
File without changes
|