pyBiocFileCache 0.3.1__py3-none-any.whl → 0.4.0__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.
@@ -2,3 +2,4 @@
2
2
 
3
3
  * Jayaram Kancherla <jayaram.kancherla@gmail.com>
4
4
  * Max Hargreaves <max_hargreaves@outlook.com>
5
+ * Oleksandr Khoroshevskyi <khorosh@virginia.edu>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyBiocFileCache
3
- Version: 0.3.1
3
+ Version: 0.4.0
4
4
  Summary: File based cache for resources and metadata
5
5
  Home-page: https://github.com/epiviz/pyBiocFileCache
6
6
  Author: jkanche
@@ -0,0 +1,13 @@
1
+ pybiocfilecache/BiocFileCache.py,sha256=q19EAVMZSyG6I4om2AiY0wMXyMs87nVEza4r3phCJLw,8577
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=jsaF6B1FViqfiWBJEq4ZCY7eI0bznpcozWkbGbBDH0c,2054
6
+ pybiocfilecache/db/__init__.py,sha256=v1G_gueaai3eECWSgj1G4EPH631x1Yg3AiSoY2jVJHE,107
7
+ pybiocfilecache/db/db_config.py,sha256=R15fSAmuP0pnWYpH6lY1ko7zIrqvvJ5dNKd1aEXoDDE,2360
8
+ pyBiocFileCache-0.4.0.dist-info/AUTHORS.md,sha256=o_ehUYmMFNMl2a6xQTKhEKxv6eXIJF0TIUTQRhHdsrk,160
9
+ pyBiocFileCache-0.4.0.dist-info/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
10
+ pyBiocFileCache-0.4.0.dist-info/METADATA,sha256=qjbb84Uq5vZ8GBIhN7NzVGryAfUz_w_52C_iy1ZR9n4,2535
11
+ pyBiocFileCache-0.4.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
12
+ pyBiocFileCache-0.4.0.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
13
+ pyBiocFileCache-0.4.0.dist-info/RECORD,,
@@ -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"
@@ -17,8 +17,8 @@ finally:
17
17
 
18
18
  from .BiocFileCache import BiocFileCache as BiocFileCache
19
19
 
20
- from .db.schema import Metadata as Metadata
21
- from .db.schema import Resource as Resource
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
@@ -0,0 +1 @@
1
+ SCHEMA_VERSION = "0.99.4"
@@ -2,4 +2,4 @@ __author__ = "jkanche"
2
2
  __copyright__ = "jkanche"
3
3
  __license__ = "MIT"
4
4
 
5
- from .Base import create_schema
5
+ from .db_config import create_schema
@@ -0,0 +1,84 @@
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(
76
+ f"sqlite:///{cache_dir}", connect_args={"check_same_thread": False}
77
+ )
78
+
79
+ Base.metadata.create_all(bind=engine, checkfirst=True)
80
+ sessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
81
+
82
+ add_metadata("schema_version", SCHEMA_VERSION, engine)
83
+
84
+ return (engine, sessionLocal)
@@ -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,,
@@ -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
@@ -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)