dcicutils 8.8.4__py3-none-any.whl → 8.8.4.1b2__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.
dcicutils/ff_utils.py CHANGED
@@ -895,9 +895,12 @@ def _get_es_metadata(uuids, es_client, filters, sources, chunk_size, auth):
895
895
  used to create the generator.
896
896
  Should NOT be used directly
897
897
  """
898
+ def get_es_host_local() -> Optional[str]:
899
+ return os.environ.get("ES_HOST_LOCAL", None)
898
900
  health = get_health_page(key=auth)
899
901
  if es_client is None:
900
- es_url = health['elasticsearch']
902
+ if not (es_url := get_es_host_local()):
903
+ es_url = health['elasticsearch']
901
904
  es_client = es_utils.create_es_client(es_url, use_aws_auth=True)
902
905
  namespace_star = health.get('namespace', '') + '*'
903
906
  # match all given uuids to _id fields
@@ -0,0 +1,15 @@
1
+ from contextlib import contextmanager
2
+ import requests
3
+ from typing import Optional
4
+ from dcicutils.tmpfile_utils import temporary_file
5
+
6
+
7
+ @contextmanager
8
+ def download(url: str, suffix: Optional[str] = None, binary: bool = True) -> Optional[str]:
9
+ with temporary_file(suffix=suffix) as file:
10
+ response = requests.get(url, stream=True)
11
+ with open(file, "wb" if binary is True else "w") as f:
12
+ for chunk in response.iter_content(chunk_size=8192):
13
+ if chunk:
14
+ f.write(chunk)
15
+ yield file
dcicutils/misc_utils.py CHANGED
@@ -3,6 +3,7 @@ This file contains functions that might be generally useful.
3
3
  """
4
4
 
5
5
  from collections import namedtuple
6
+ import appdirs
6
7
  import contextlib
7
8
  import datetime
8
9
  import functools
@@ -2670,3 +2671,14 @@ class JsonLinesReader:
2670
2671
  yield line
2671
2672
  else:
2672
2673
  raise Exception(f"If the first line is not a list, all lines must be dictionaries: {line!r}")
2674
+
2675
+
2676
+ def get_app_specific_directory() -> str:
2677
+ """
2678
+ Returns the standard system application specific directory:
2679
+ - On MacOS this directory: is: ~/Library/Application Support
2680
+ - On Linux this directory is: ~/.local/share
2681
+ - On Windows this directory is: %USERPROFILE%\AppData\Local # noqa
2682
+ N.B. This is has been tested on MacOS and Linux but not on Windows.
2683
+ """
2684
+ return appdirs.user_data_dir()
dcicutils/zip_utils.py CHANGED
@@ -2,7 +2,9 @@ from contextlib import contextmanager
2
2
  from dcicutils.tmpfile_utils import temporary_directory, temporary_file
3
3
  import gzip
4
4
  import os
5
+ import shutil
5
6
  import tarfile
7
+ import tempfile
6
8
  from typing import List, Optional
7
9
  import zipfile
8
10
 
@@ -45,3 +47,23 @@ def unpack_gz_file_to_temporary_file(file: str, suffix: Optional[str] = None) ->
45
47
  outputf.write(inputf.read())
46
48
  outputf.close()
47
49
  yield tmp_file_name
50
+
51
+
52
+ def extract_file_from_zip(zip_file: str, file_to_extract: str,
53
+ destination_file: str, raise_exception: bool = True) -> bool:
54
+ try:
55
+ if not (destination_directory := os.path.dirname(destination_file)):
56
+ destination_directory = os.getcwd()
57
+ destination_file = os.path.join(destination_directory, destination_file)
58
+ with tempfile.TemporaryDirectory() as tmp_directory_name:
59
+ with zipfile.ZipFile(zip_file, "r") as zipf:
60
+ if file_to_extract not in zipf.namelist():
61
+ return False
62
+ zipf.extract(file_to_extract, path=tmp_directory_name)
63
+ os.makedirs(destination_directory, exist_ok=True)
64
+ shutil.move(os.path.join(tmp_directory_name, file_to_extract), destination_file)
65
+ return True
66
+ except Exception as e:
67
+ if raise_exception:
68
+ raise e
69
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.8.4
3
+ Version: 8.8.4.1b2
4
4
  Summary: Utility package for interacting with the 4DN Data Portal and other 4DN resources
5
5
  Home-page: https://github.com/4dn-dcic/utils
6
6
  License: MIT
@@ -24,6 +24,7 @@ Classifier: Programming Language :: Python :: 3.9
24
24
  Classifier: Topic :: Database :: Database Engines/Servers
25
25
  Requires-Dist: PyJWT (>=2.6.0,<3.0.0)
26
26
  Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
27
+ Requires-Dist: appdirs (>=1.4.4,<2.0.0)
27
28
  Requires-Dist: aws-requests-auth (>=0.4.2,<1)
28
29
  Requires-Dist: boto3 (>=1.28.57,<2.0.0)
29
30
  Requires-Dist: botocore (>=1.31.57,<2.0.0)
@@ -27,10 +27,11 @@ dcicutils/env_utils_legacy.py,sha256=J81OAtJHN69o1beHO6q1j7_J6TeblSjnAHlS8VA5KSM
27
27
  dcicutils/es_utils.py,sha256=ZksLh5ei7kRUfiFltk8sd2ZSfh15twbstrMzBr8HNw4,7541
28
28
  dcicutils/exceptions.py,sha256=4giQGtpak-omQv7BP6Ckeu91XK5fnDosC8gfdmN_ccA,9931
29
29
  dcicutils/ff_mocks.py,sha256=6RKS4eUiu_Wl8yP_8V0CaV75w4ZdWxdCuL1CVlnMrek,36918
30
- dcicutils/ff_utils.py,sha256=Yf-fET5gdpjrH0gikpOCIJdY2Dv3obzUpR31ur816mU,72972
30
+ dcicutils/ff_utils.py,sha256=oIhuZPnGtfwj6bWyCc1u23JbMB_6InPp01ZqUOljd8M,73123
31
31
  dcicutils/file_utils.py,sha256=098rXvLeIh8n69EGW7DpOS227ef3BPgwhRAktoU6mhE,2663
32
32
  dcicutils/function_cache_decorator.py,sha256=XMyiEGODVr2WoAQ68vcoX_9_Xb9p8pZXdXl7keU8i2g,10026
33
33
  dcicutils/glacier_utils.py,sha256=Q4CVXsZCbP-SoZIsZ5NMcawDfelOLzbQnIlQn-GdlTo,34149
34
+ dcicutils/http_utils.py,sha256=UKIsP-e8NOZN_4ScLDoFA4Bd1ifYBLTl6RrwvRfuAPY,549
34
35
  dcicutils/jh_utils.py,sha256=Gpsxb9XEzggF_-Eq3ukjKvTnuyb9V1SCSUXkXsES4Kg,11502
35
36
  dcicutils/kibana/dashboards.json,sha256=wHMB_mpJ8OaYhRRgvpZuihaB2lmSF64ADt_8hkBWgQg,16225
36
37
  dcicutils/kibana/readme.md,sha256=3KmHF9FH6A6xwYsNxRFLw27q0XzHYnjZOlYUnn3VkQQ,2164
@@ -43,7 +44,7 @@ dcicutils/license_policies/park-lab-gpl-pipeline.jsonc,sha256=vLZkwm3Js-kjV44nug
43
44
  dcicutils/license_policies/park-lab-pipeline.jsonc,sha256=9qlY0ASy3iUMQlr3gorVcXrSfRHnVGbLhkS427UaRy4,283
44
45
  dcicutils/license_utils.py,sha256=d1cq6iwv5Ju-VjdoINi6q7CPNNL7Oz6rcJdLMY38RX0,46978
45
46
  dcicutils/log_utils.py,sha256=7pWMc6vyrorUZQf-V-M3YC6zrPgNhuV_fzm9xqTPph0,10883
46
- dcicutils/misc_utils.py,sha256=YH_TTmv6ABWeMERwVvA2-rIfdS-CoPYLXJru9TvWxgM,104610
47
+ dcicutils/misc_utils.py,sha256=hdL7FP2fMTX6OuJ9SXyAS4BLvrNUBLk8XOQHRw_EeiI,105041
47
48
  dcicutils/obfuscation_utils.py,sha256=fo2jOmDRC6xWpYX49u80bVNisqRRoPskFNX3ymFAmjw,5963
48
49
  dcicutils/opensearch_utils.py,sha256=V2exmFYW8Xl2_pGFixF4I2Cc549Opwe4PhFi5twC0M8,1017
49
50
  dcicutils/portal_object_utils.py,sha256=gDXRgPsRvqCFwbC8WatsuflAxNiigOnqr0Hi93k3AgE,15422
@@ -71,9 +72,9 @@ dcicutils/tmpfile_utils.py,sha256=n95XF8dZVbQRSXBZTGToXXfSs3JUVRyN6c3ZZ0nhAWI,14
71
72
  dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
72
73
  dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
73
74
  dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
74
- dcicutils/zip_utils.py,sha256=rnjNv_k6L9jT2SjDSgVXp4BEJYLtz9XN6Cl2Fy-tqnM,2027
75
- dcicutils-8.8.4.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
76
- dcicutils-8.8.4.dist-info/METADATA,sha256=fMdiyQonxO9h426d8jDY59u47FAfvXcNrwRXW0GmsIY,3352
77
- dcicutils-8.8.4.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
78
- dcicutils-8.8.4.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
79
- dcicutils-8.8.4.dist-info/RECORD,,
75
+ dcicutils/zip_utils.py,sha256=dEnUZ1GHfJHPmqXBIqYRorsClSeUTPADoBMxp9TWacI,2994
76
+ dcicutils-8.8.4.1b2.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
77
+ dcicutils-8.8.4.1b2.dist-info/METADATA,sha256=IXQBCwnsqr2r6XPr-LJ2LOZ4zcYjklc0D_DILN7dVeo,3396
78
+ dcicutils-8.8.4.1b2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
79
+ dcicutils-8.8.4.1b2.dist-info/entry_points.txt,sha256=51Q4F_2V10L0282W7HFjP4jdzW4K8lnWDARJQVFy_hw,270
80
+ dcicutils-8.8.4.1b2.dist-info/RECORD,,