pyBiocFileCache 0.6.0__py3-none-any.whl → 0.6.2__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.6.0.dist-info → pyBiocFileCache-0.6.2.dist-info}/METADATA +2 -2
- pyBiocFileCache-0.6.2.dist-info/RECORD +12 -0
- {pyBiocFileCache-0.6.0.dist-info → pyBiocFileCache-0.6.2.dist-info}/WHEEL +1 -1
- pybiocfilecache/cache.py +151 -75
- pybiocfilecache/models.py +1 -1
- pybiocfilecache/utils.py +20 -4
- pyBiocFileCache-0.6.0.dist-info/RECORD +0 -13
- pybiocfilecache/exceptions.py +0 -31
- {pyBiocFileCache-0.6.0.dist-info → pyBiocFileCache-0.6.2.dist-info}/AUTHORS.md +0 -0
- {pyBiocFileCache-0.6.0.dist-info → pyBiocFileCache-0.6.2.dist-info}/LICENSE.txt +0 -0
- {pyBiocFileCache-0.6.0.dist-info → pyBiocFileCache-0.6.2.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyBiocFileCache
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
4
4
|
Summary: File based cache for resources and metadata
|
|
5
5
|
Home-page: https://github.com/epiviz/pyBiocFileCache
|
|
6
6
|
Author: jkanche
|
|
@@ -23,7 +23,7 @@ Requires-Dist: pytest-cov; extra == "testing"
|
|
|
23
23
|
|
|
24
24
|
[](https://pyscaffold.org/)
|
|
25
25
|
[](https://pypi.org/project/pyBiocFileCache/)
|
|
26
|
-

|
|
27
27
|
|
|
28
28
|
# pyBiocFileCache
|
|
29
29
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
pybiocfilecache/__init__.py,sha256=kClwDkzgGPYAyDW-fuo5LI4lKCruYJhDHvw0lq9u4b0,652
|
|
2
|
+
pybiocfilecache/cache.py,sha256=CW_jjF2lIbUf-ZpNe3LXhNxrtLnLoeMRzTYxgigTwps,23171
|
|
3
|
+
pybiocfilecache/config.py,sha256=bado4Hg6QFIfV46zKwx6Q9AoV__G-e8fghylnk5I-nk,803
|
|
4
|
+
pybiocfilecache/const.py,sha256=c9167eSCGBp0wF1xuAEvr-fbYCzp0lcOtKF9sqxlLF8,26
|
|
5
|
+
pybiocfilecache/models.py,sha256=qxOZqmvKLloNygiQgr2ECtgXCZbvxOA_JoLLeM18mRA,1967
|
|
6
|
+
pybiocfilecache/utils.py,sha256=z0WSk9vSk3ivMJ4dRICQbbDj8JtgpeGzNMImyKPdROc,2659
|
|
7
|
+
pyBiocFileCache-0.6.2.dist-info/AUTHORS.md,sha256=ptvMLokf9Knfp0Ng-dHSgtEimkXWZhjZAR_o2aJm9bw,161
|
|
8
|
+
pyBiocFileCache-0.6.2.dist-info/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
|
|
9
|
+
pyBiocFileCache-0.6.2.dist-info/METADATA,sha256=BEoKhTG5v4h8d0CS5C2VynWnN41SW7dDWo94w-Ob-Vw,2947
|
|
10
|
+
pyBiocFileCache-0.6.2.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
|
11
|
+
pyBiocFileCache-0.6.2.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
|
|
12
|
+
pyBiocFileCache-0.6.2.dist-info/RECORD,,
|
pybiocfilecache/cache.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import json
|
|
2
1
|
import logging
|
|
3
2
|
from contextlib import contextmanager
|
|
4
3
|
from datetime import datetime
|
|
@@ -12,20 +11,14 @@ from sqlalchemy.pool import QueuePool
|
|
|
12
11
|
|
|
13
12
|
from .config import CacheConfig
|
|
14
13
|
from .const import SCHEMA_VERSION
|
|
15
|
-
from .
|
|
16
|
-
BiocCacheError,
|
|
17
|
-
InvalidRnameError,
|
|
18
|
-
NoFpathError,
|
|
19
|
-
RnameExistsError,
|
|
20
|
-
RpathTimeoutError,
|
|
21
|
-
)
|
|
22
|
-
from .models import Base, Resource
|
|
14
|
+
from .models import Base, Metadata, Resource
|
|
23
15
|
from .utils import (
|
|
24
16
|
calculate_file_hash,
|
|
25
17
|
copy_or_move,
|
|
26
18
|
create_tmp_dir,
|
|
19
|
+
download_web_file,
|
|
27
20
|
generate_id,
|
|
28
|
-
|
|
21
|
+
generate_uuid,
|
|
29
22
|
)
|
|
30
23
|
|
|
31
24
|
__author__ = "Jayaram Kancherla"
|
|
@@ -66,7 +59,6 @@ class BiocFileCache:
|
|
|
66
59
|
db_schema_version = self._setup_database()
|
|
67
60
|
|
|
68
61
|
if db_schema_version != SCHEMA_VERSION:
|
|
69
|
-
print(db_schema_version)
|
|
70
62
|
raise RuntimeError(f"Database version is not {SCHEMA_VERSION}.")
|
|
71
63
|
|
|
72
64
|
self._last_cleanup = datetime.now()
|
|
@@ -108,16 +100,19 @@ class BiocFileCache:
|
|
|
108
100
|
"""),
|
|
109
101
|
{"version": SCHEMA_VERSION},
|
|
110
102
|
)
|
|
103
|
+
conn.commit()
|
|
111
104
|
|
|
112
105
|
return SCHEMA_VERSION
|
|
113
106
|
|
|
114
|
-
def _get_detached_resource(
|
|
107
|
+
def _get_detached_resource(
|
|
108
|
+
self, session: Session, obj: Union[Resource, Metadata]
|
|
109
|
+
) -> Optional[Union[Resource, Metadata]]:
|
|
115
110
|
"""Get a detached copy of a resource."""
|
|
116
|
-
if
|
|
111
|
+
if obj is None:
|
|
117
112
|
return None
|
|
118
|
-
session.refresh(
|
|
119
|
-
session.expunge(
|
|
120
|
-
return
|
|
113
|
+
session.refresh(obj)
|
|
114
|
+
session.expunge(obj)
|
|
115
|
+
return obj
|
|
121
116
|
|
|
122
117
|
def __enter__(self) -> "BiocFileCache":
|
|
123
118
|
return self
|
|
@@ -142,10 +137,10 @@ class BiocFileCache:
|
|
|
142
137
|
finally:
|
|
143
138
|
session.close()
|
|
144
139
|
|
|
145
|
-
def _validate_rname(self, rname: str) -> None:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
# def _validate_rname(self, rname: str) -> None:
|
|
141
|
+
# """Validate resource name format."""
|
|
142
|
+
# if not validate_rname(rname, self.config.rname_pattern):
|
|
143
|
+
# raise Exception(f"Resource name '{rname}' doesn't match pattern " f"'{self.config.rname_pattern}'")
|
|
149
144
|
|
|
150
145
|
def _should_cleanup(self) -> bool:
|
|
151
146
|
"""Check if cache cleanup should be performed.
|
|
@@ -196,16 +191,25 @@ class BiocFileCache:
|
|
|
196
191
|
self._last_cleanup = datetime.now()
|
|
197
192
|
return removed
|
|
198
193
|
|
|
199
|
-
def get(self, rname: str) -> Optional[Resource]:
|
|
194
|
+
def get(self, rname: str = None, rid: str = None) -> Optional[Resource]:
|
|
200
195
|
"""Get resource by name from cache.
|
|
201
196
|
|
|
202
197
|
Args:
|
|
203
198
|
rname:
|
|
204
199
|
Name to identify the resource in cache.
|
|
205
200
|
|
|
201
|
+
rid:
|
|
202
|
+
Resource id to search by.
|
|
203
|
+
|
|
206
204
|
"""
|
|
205
|
+
if rname is None and rid is None:
|
|
206
|
+
raise ValueError("either 'rname' or 'rid' must be provided.")
|
|
207
|
+
|
|
207
208
|
with self.get_session() as session:
|
|
208
|
-
|
|
209
|
+
if rname is not None:
|
|
210
|
+
resource = session.query(Resource).filter(Resource.rname == rname).first()
|
|
211
|
+
elif rid is not None:
|
|
212
|
+
resource = session.query(Resource).filter(Resource.rid == rid).first()
|
|
209
213
|
|
|
210
214
|
if resource is not None:
|
|
211
215
|
# Check if path exists with timeout
|
|
@@ -213,7 +217,7 @@ class BiocFileCache:
|
|
|
213
217
|
timeout = 30
|
|
214
218
|
while not Path(str(resource.rpath)).exists():
|
|
215
219
|
if time() - start >= timeout:
|
|
216
|
-
raise
|
|
220
|
+
raise TimeoutError(
|
|
217
221
|
f"For resource: '{rname}' the rpath does not exist " f"after {timeout} seconds."
|
|
218
222
|
)
|
|
219
223
|
sleep(0.1)
|
|
@@ -229,10 +233,11 @@ class BiocFileCache:
|
|
|
229
233
|
self,
|
|
230
234
|
rname: str,
|
|
231
235
|
fpath: Union[str, Path],
|
|
232
|
-
rtype: Literal["local", "web", "relative"] = "
|
|
236
|
+
rtype: Literal["local", "web", "relative"] = "relative",
|
|
233
237
|
action: Literal["copy", "move", "asis"] = "copy",
|
|
234
238
|
expires: Optional[datetime] = None,
|
|
235
|
-
|
|
239
|
+
download: bool = True,
|
|
240
|
+
ext: bool = True,
|
|
236
241
|
) -> Resource:
|
|
237
242
|
"""Add a resource to the cache.
|
|
238
243
|
|
|
@@ -252,29 +257,41 @@ class BiocFileCache:
|
|
|
252
257
|
How to handle the file ("copy", "move", or "asis").
|
|
253
258
|
Defaults to ``copy``.
|
|
254
259
|
|
|
260
|
+
download:
|
|
261
|
+
Whether to download the resource.
|
|
262
|
+
Only used if 'rtype' is "web".
|
|
263
|
+
|
|
255
264
|
expires:
|
|
256
265
|
Optional expiration datetime.
|
|
257
266
|
If None, resource never expires.
|
|
258
267
|
|
|
259
268
|
ext:
|
|
260
269
|
Whether to use filepath extension when storing in cache.
|
|
261
|
-
Defaults to `
|
|
270
|
+
Defaults to `True`.
|
|
262
271
|
|
|
263
272
|
Returns:
|
|
264
273
|
The `Resource` object added to the cache.
|
|
265
274
|
"""
|
|
266
|
-
self._validate_rname(rname)
|
|
267
|
-
fpath = Path(fpath)
|
|
268
|
-
|
|
269
|
-
if not fpath.exists():
|
|
270
|
-
raise NoFpathError(f"Resource at '{fpath}' does not exist")
|
|
275
|
+
# self._validate_rname(rname)
|
|
276
|
+
fpath = Path(fpath) if rtype != "web" else fpath
|
|
271
277
|
|
|
272
278
|
if self.get(rname) is not None:
|
|
273
|
-
raise
|
|
279
|
+
raise FileExistsError(f"Resource '{rname}' already exists")
|
|
280
|
+
|
|
281
|
+
if rtype == "web":
|
|
282
|
+
outpath = download_web_file(fpath, Path(fpath).name, download)
|
|
283
|
+
action = "copy"
|
|
284
|
+
else:
|
|
285
|
+
outpath = Path(fpath)
|
|
286
|
+
|
|
287
|
+
if action == "asis":
|
|
288
|
+
logger.warning("If action='asis', rtype must be 'local'.")
|
|
289
|
+
rtype = "local"
|
|
274
290
|
|
|
275
291
|
# Generate paths and check size
|
|
276
|
-
rid = generate_id()
|
|
277
|
-
|
|
292
|
+
rid = generate_id(size=len(self))
|
|
293
|
+
uuid = generate_uuid()
|
|
294
|
+
rpath = self.config.cache_dir / f"{uuid}_{outpath.name if ext else outpath.stem}" if action != "asis" else fpath
|
|
278
295
|
|
|
279
296
|
# Create resource record
|
|
280
297
|
resource = Resource(
|
|
@@ -292,7 +309,7 @@ class BiocFileCache:
|
|
|
292
309
|
session.commit()
|
|
293
310
|
|
|
294
311
|
try:
|
|
295
|
-
copy_or_move(
|
|
312
|
+
copy_or_move(outpath, rpath, rname, action, False)
|
|
296
313
|
|
|
297
314
|
# Calculate and store checksum
|
|
298
315
|
resource.etag = calculate_file_hash(rpath, self.config.hash_algorithm)
|
|
@@ -303,7 +320,7 @@ class BiocFileCache:
|
|
|
303
320
|
except Exception as e:
|
|
304
321
|
session.delete(resource)
|
|
305
322
|
session.commit()
|
|
306
|
-
raise
|
|
323
|
+
raise Exception("Failed to add resource") from e
|
|
307
324
|
|
|
308
325
|
def add_batch(self, resources: List[Dict[str, Any]]) -> List[Resource]:
|
|
309
326
|
"""Add multiple resources in a single transaction.
|
|
@@ -349,7 +366,7 @@ class BiocFileCache:
|
|
|
349
366
|
"""
|
|
350
367
|
fpath = Path(fpath)
|
|
351
368
|
if not fpath.exists():
|
|
352
|
-
raise
|
|
369
|
+
raise FileNotFoundError(f"File '{fpath}' does not exist")
|
|
353
370
|
|
|
354
371
|
with self.get_session() as session:
|
|
355
372
|
resource = session.query(Resource).filter(Resource.rname == rname).first()
|
|
@@ -369,7 +386,7 @@ class BiocFileCache:
|
|
|
369
386
|
|
|
370
387
|
except Exception as e:
|
|
371
388
|
session.rollback()
|
|
372
|
-
raise
|
|
389
|
+
raise Exception("Failed to update resource") from e
|
|
373
390
|
|
|
374
391
|
def remove(self, rname: str) -> None:
|
|
375
392
|
"""Remove a resource from cache by name.
|
|
@@ -381,7 +398,7 @@ class BiocFileCache:
|
|
|
381
398
|
Name to identify the resource in cache.
|
|
382
399
|
|
|
383
400
|
Raises:
|
|
384
|
-
|
|
401
|
+
Exception: If resource removal fails
|
|
385
402
|
"""
|
|
386
403
|
with self.get_session() as session:
|
|
387
404
|
resource = session.query(Resource).filter(Resource.rname == rname).first()
|
|
@@ -399,7 +416,7 @@ class BiocFileCache:
|
|
|
399
416
|
|
|
400
417
|
except Exception as e:
|
|
401
418
|
session.rollback()
|
|
402
|
-
raise
|
|
419
|
+
raise Exception(f"Failed to remove resource '{rname}'") from e
|
|
403
420
|
|
|
404
421
|
def list_resources(self, rtype: Optional[str] = None, expired: Optional[bool] = None) -> List[Resource]:
|
|
405
422
|
"""List resources in the cache with optional filtering.
|
|
@@ -459,38 +476,38 @@ class BiocFileCache:
|
|
|
459
476
|
logger.error(f"Failed to validate resource: {resource.rname}", exc_info=e)
|
|
460
477
|
return False
|
|
461
478
|
|
|
462
|
-
def export_metadata(self, path: Path) -> None:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
def import_metadata(self, path: Path) -> None:
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
479
|
+
# def export_metadata(self, path: Path) -> None:
|
|
480
|
+
# """Export cache metadata to JSON file."""
|
|
481
|
+
# data = {
|
|
482
|
+
# "resources": [
|
|
483
|
+
# {
|
|
484
|
+
# "rname": r.rname,
|
|
485
|
+
# "rtype": r.rtype,
|
|
486
|
+
# "expires": r.expires.isoformat() if r.expires else None,
|
|
487
|
+
# "etag": r.etag,
|
|
488
|
+
# }
|
|
489
|
+
# for r in self.list_resources()
|
|
490
|
+
# ],
|
|
491
|
+
# "export_time": datetime.now().isoformat(),
|
|
492
|
+
# }
|
|
493
|
+
|
|
494
|
+
# with open(path, "w") as f:
|
|
495
|
+
# json.dump(data, f, indent=2)
|
|
496
|
+
|
|
497
|
+
# def import_metadata(self, path: Path) -> None:
|
|
498
|
+
# """Import cache metadata from JSON file."""
|
|
499
|
+
# with open(path) as f:
|
|
500
|
+
# data = json.load(f)
|
|
501
|
+
|
|
502
|
+
# with self.get_session() as session:
|
|
503
|
+
# for resource_data in data["resources"]:
|
|
504
|
+
# resource = self._get(session, resource_data["rname"])
|
|
505
|
+
# if resource:
|
|
506
|
+
# resource.expires = (
|
|
507
|
+
# datetime.fromisoformat(resource_data["expires"]) if resource_data["expires"] else None
|
|
508
|
+
# )
|
|
509
|
+
# session.merge(resource)
|
|
510
|
+
# session.commit()
|
|
494
511
|
|
|
495
512
|
def verify_cache(self) -> Tuple[int, int]:
|
|
496
513
|
"""Verify integrity of all cached resources.
|
|
@@ -564,7 +581,7 @@ class BiocFileCache:
|
|
|
564
581
|
True if purge was successful, False otherwise.
|
|
565
582
|
|
|
566
583
|
Raises:
|
|
567
|
-
|
|
584
|
+
Exception: If purge fails and force=False.
|
|
568
585
|
"""
|
|
569
586
|
try:
|
|
570
587
|
with self.get_session() as session:
|
|
@@ -577,7 +594,7 @@ class BiocFileCache:
|
|
|
577
594
|
except Exception as e:
|
|
578
595
|
if not force:
|
|
579
596
|
session.rollback()
|
|
580
|
-
raise
|
|
597
|
+
raise Exception(f"Failed to remove file for resource '{resource.rname}'") from e
|
|
581
598
|
logger.warning(f"Failed to remove file for resource '{resource.rname}': {e}")
|
|
582
599
|
|
|
583
600
|
session.commit()
|
|
@@ -598,7 +615,7 @@ class BiocFileCache:
|
|
|
598
615
|
|
|
599
616
|
except Exception as e:
|
|
600
617
|
if not force:
|
|
601
|
-
raise
|
|
618
|
+
raise Exception("Failed to purge cache") from e
|
|
602
619
|
|
|
603
620
|
logger.error("Database cleanup failed, forcing file removal", exc_info=e)
|
|
604
621
|
for file in self.config.cache_dir.iterdir():
|
|
@@ -612,3 +629,62 @@ class BiocFileCache:
|
|
|
612
629
|
logger.warning(f"Failed to remove {file}: {file_e}")
|
|
613
630
|
|
|
614
631
|
return False
|
|
632
|
+
|
|
633
|
+
def __len__(self):
|
|
634
|
+
with self.get_session() as session:
|
|
635
|
+
return session.query(Resource).count()
|
|
636
|
+
|
|
637
|
+
def check_metadata_key(self, key: str) -> bool:
|
|
638
|
+
"""Check if a key exists in the metadata table.
|
|
639
|
+
|
|
640
|
+
Args:
|
|
641
|
+
key:
|
|
642
|
+
Key to search.
|
|
643
|
+
|
|
644
|
+
Returns:
|
|
645
|
+
True if the key exists, else False.
|
|
646
|
+
"""
|
|
647
|
+
with self.get_session() as session:
|
|
648
|
+
return session.query(Metadata).filter(Metadata.key == key).count() != 0
|
|
649
|
+
|
|
650
|
+
def get_metadata(self, key: str):
|
|
651
|
+
"""Add a new metadata key"""
|
|
652
|
+
with self.get_session() as session:
|
|
653
|
+
meta = session.query(Metadata).filter(Metadata.key == key).first()
|
|
654
|
+
if meta is not None:
|
|
655
|
+
return self._get_detached_resource(session, meta)
|
|
656
|
+
|
|
657
|
+
return None
|
|
658
|
+
|
|
659
|
+
def add_metadata(self, key: str, value: str):
|
|
660
|
+
"""Add a new metadata key"""
|
|
661
|
+
exists = self.get_metadata(key=key)
|
|
662
|
+
|
|
663
|
+
if exists is None:
|
|
664
|
+
meta = Metadata(key=key, value=value)
|
|
665
|
+
|
|
666
|
+
with self.get_session() as session:
|
|
667
|
+
try:
|
|
668
|
+
session.add(meta)
|
|
669
|
+
session.commit()
|
|
670
|
+
return self._get_detached_resource(session, meta)
|
|
671
|
+
except Exception as e:
|
|
672
|
+
session.delete(meta)
|
|
673
|
+
session.commit()
|
|
674
|
+
raise Exception("Failed to add metadata") from e
|
|
675
|
+
else:
|
|
676
|
+
raise Exception(f"'key'={key} already exists in metadata.")
|
|
677
|
+
|
|
678
|
+
def remove_metadata(self, key: str) -> None:
|
|
679
|
+
"""Remove a metadata key."""
|
|
680
|
+
with self.get_session() as session:
|
|
681
|
+
meta = session.query(Metadata).filter(Metadata.key == key).first()
|
|
682
|
+
|
|
683
|
+
if meta is not None:
|
|
684
|
+
try:
|
|
685
|
+
session.delete(meta)
|
|
686
|
+
session.commit()
|
|
687
|
+
|
|
688
|
+
except Exception as e:
|
|
689
|
+
session.rollback()
|
|
690
|
+
raise Exception(f"Failed to remove key '{key}'") from e
|
pybiocfilecache/models.py
CHANGED
pybiocfilecache/utils.py
CHANGED
|
@@ -2,14 +2,13 @@ import hashlib
|
|
|
2
2
|
import logging
|
|
3
3
|
import re
|
|
4
4
|
import tempfile
|
|
5
|
+
import urllib.request
|
|
5
6
|
import uuid
|
|
6
7
|
import zlib
|
|
7
8
|
from pathlib import Path
|
|
8
9
|
from shutil import copy2, move
|
|
9
10
|
from typing import Literal
|
|
10
11
|
|
|
11
|
-
from .exceptions import BiocCacheError
|
|
12
|
-
|
|
13
12
|
__author__ = "Jayaram Kancherla"
|
|
14
13
|
__copyright__ = "Jayaram Kancherla"
|
|
15
14
|
__license__ = "MIT"
|
|
@@ -22,11 +21,17 @@ def create_tmp_dir() -> Path:
|
|
|
22
21
|
return Path(tempfile.mkdtemp())
|
|
23
22
|
|
|
24
23
|
|
|
25
|
-
def
|
|
24
|
+
def generate_uuid() -> str:
|
|
26
25
|
"""Generate unique identifier."""
|
|
27
26
|
return uuid.uuid4().hex
|
|
28
27
|
|
|
29
28
|
|
|
29
|
+
def generate_id(size) -> str:
|
|
30
|
+
"""Generate unique identifier."""
|
|
31
|
+
size += 1
|
|
32
|
+
return "BFC" + str(size)
|
|
33
|
+
|
|
34
|
+
|
|
30
35
|
def validate_rname(rname: str, pattern: str) -> bool:
|
|
31
36
|
"""Validate resource name format."""
|
|
32
37
|
return bool(re.match(pattern, rname))
|
|
@@ -80,4 +85,15 @@ def copy_or_move(
|
|
|
80
85
|
elif action == "asis":
|
|
81
86
|
pass
|
|
82
87
|
except Exception as e:
|
|
83
|
-
raise
|
|
88
|
+
raise Exception(f"Failed to store resource '{rname}' from '{source}' to '{target}'") from e
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def download_web_file(url: str, filename: str, download: bool):
|
|
92
|
+
tmp_dir = create_tmp_dir()
|
|
93
|
+
outpath = tmp_dir / filename
|
|
94
|
+
if download:
|
|
95
|
+
urllib.request.urlretrieve(str(url), str(outpath))
|
|
96
|
+
else:
|
|
97
|
+
open(str(outpath), "a").close()
|
|
98
|
+
|
|
99
|
+
return outpath
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
pybiocfilecache/__init__.py,sha256=kClwDkzgGPYAyDW-fuo5LI4lKCruYJhDHvw0lq9u4b0,652
|
|
2
|
-
pybiocfilecache/cache.py,sha256=N1xJFCDFINvWxDKwO7ibPiFOJHQOTlr_IV6UrxIW8Bk,20434
|
|
3
|
-
pybiocfilecache/config.py,sha256=bado4Hg6QFIfV46zKwx6Q9AoV__G-e8fghylnk5I-nk,803
|
|
4
|
-
pybiocfilecache/const.py,sha256=c9167eSCGBp0wF1xuAEvr-fbYCzp0lcOtKF9sqxlLF8,26
|
|
5
|
-
pybiocfilecache/exceptions.py,sha256=8jrnctFYF7Rc1xsITtLUwKKvx8GMoKbarucyc-4f2zI,706
|
|
6
|
-
pybiocfilecache/models.py,sha256=inFECbprbU6W67XAkx8-Wbj3p57PdVlerb1SRvp1WlY,1943
|
|
7
|
-
pybiocfilecache/utils.py,sha256=lBK4BmzT6Z7XCn4j8kmhz9BPQpWT-RYfWvWC7YNtIGM,2291
|
|
8
|
-
pyBiocFileCache-0.6.0.dist-info/AUTHORS.md,sha256=ptvMLokf9Knfp0Ng-dHSgtEimkXWZhjZAR_o2aJm9bw,161
|
|
9
|
-
pyBiocFileCache-0.6.0.dist-info/LICENSE.txt,sha256=bV5MJ4ezdCnC4yREyxU30iel5hFq8T8kGqobu4Kc-WM,1082
|
|
10
|
-
pyBiocFileCache-0.6.0.dist-info/METADATA,sha256=xFfkcCK-paxNVnt02VWdvxO39zgUkorb5cCp8usgWG4,2947
|
|
11
|
-
pyBiocFileCache-0.6.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
12
|
-
pyBiocFileCache-0.6.0.dist-info/top_level.txt,sha256=_A2QFmYMnsz6WoSRPk1EFMDr5mkQVGx9Xtz2RMv3aF4,16
|
|
13
|
-
pyBiocFileCache-0.6.0.dist-info/RECORD,,
|
pybiocfilecache/exceptions.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
__author__ = "Jayaram Kancherla"
|
|
2
|
-
__copyright__ = "Jayaram Kancherla"
|
|
3
|
-
__license__ = "MIT"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BiocCacheError(Exception):
|
|
7
|
-
"""Base exception for BiocFileCache errors."""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class NoFpathError(BiocCacheError):
|
|
11
|
-
"""Source file does not exist."""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class RnameExistsError(BiocCacheError):
|
|
15
|
-
"""Resource name already exists in cache."""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class RpathTimeoutError(BiocCacheError):
|
|
19
|
-
"""Resource path does not exist after timeout."""
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class CacheSizeLimitError(BiocCacheError):
|
|
23
|
-
"""Cache size limit would be exceeded."""
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class ResourceValidationError(BiocCacheError):
|
|
27
|
-
"""Resource failed validation check."""
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class InvalidRnameError(BiocCacheError):
|
|
31
|
-
"""Invalid resource name format."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|