deriva 1.7.6__py3-none-any.whl → 1.7.7__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.
deriva/core/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.7.6"
1
+ __version__ = "1.7.7"
2
2
 
3
3
  from deriva.core.utils.core_utils import *
4
4
  from deriva.core.base_cli import BaseCLI, KeyValuePairArgs
deriva/core/base_cli.py CHANGED
@@ -53,6 +53,11 @@ class BaseCLI(object):
53
53
 
54
54
  return args
55
55
 
56
+ # Function to convert comma-separated CLI input into a tuple
57
+ @staticmethod
58
+ def parse_tuple(value):
59
+ # Split the input by commas and convert to a tuple
60
+ return tuple(map(float, value.split(',')))
56
61
 
57
62
  class KeyValuePairArgs(argparse.Action):
58
63
  def __init__(self, option_strings, dest, nargs=None, **kwargs):
@@ -184,6 +184,7 @@ class HatracStore(DerivaBinding):
184
184
 
185
185
  headers = headers.copy()
186
186
 
187
+ file_opened = False
187
188
  if hasattr(data, 'read') and hasattr(data, 'seek'):
188
189
  data.seek(0, os.SEEK_END)
189
190
  file_size = data.tell()
@@ -192,6 +193,7 @@ class HatracStore(DerivaBinding):
192
193
  else:
193
194
  file_size = os.path.getsize(data)
194
195
  f = open(data, 'rb')
196
+ file_opened = True
195
197
 
196
198
  if not (md5 or sha256):
197
199
  md5 = hu.compute_hashes(f, hashes=['md5'])['md5'][1]
@@ -208,7 +210,8 @@ class HatracStore(DerivaBinding):
208
210
  if (md5 and r.headers.get('Content-MD5') == md5 or
209
211
  sha256 and r.headers.get('Content-SHA256') == sha256):
210
212
  # object already has same content so skip upload
211
- f.close()
213
+ if file_opened:
214
+ f.close()
212
215
  return r.headers.get('Content-Location')
213
216
  elif not allow_versioning:
214
217
  raise NotModified("The data cannot be uploaded because content already exists for this object "
@@ -232,6 +235,8 @@ class HatracStore(DerivaBinding):
232
235
  url = '%s%s' % (url.rstrip("/") if url.endswith("/") else url,
233
236
  "" if not parents else "?parents=%s" % str(parents).lower())
234
237
  r = self._session.put(url, data=f, headers=headers)
238
+ if file_opened:
239
+ f.close()
235
240
  self._response_raise_for_status(r)
236
241
  loc = r.text.strip() or r.url
237
242
  if loc.startswith(self._server_uri):
@@ -8,8 +8,8 @@ import requests
8
8
  from requests.exceptions import HTTPError
9
9
  from bdbag import bdbag_api as bdb, bdbag_ro as ro, BAG_PROFILE_TAG, BDBAG_RO_PROFILE_ID
10
10
  from bdbag.bdbagit import BagValidationError
11
- from deriva.core import ErmrestCatalog, HatracStore, format_exception, get_credential, format_credential, read_config, \
12
- stob, Megabyte, __version__ as VERSION
11
+ from deriva.core import DerivaServer, ErmrestCatalog, HatracStore, format_exception, get_credential, \
12
+ format_credential, read_config, stob, Megabyte, __version__ as VERSION
13
13
  from deriva.core.utils.version_utils import get_installed_version
14
14
  from deriva.transfer.download.processors import find_query_processor, find_transform_processor, find_post_processor
15
15
  from deriva.transfer.download.processors.base_processor import LOCAL_PATH_KEY, REMOTE_PATHS_KEY, SERVICE_URL_KEY, \
@@ -76,14 +76,9 @@ class DerivaDownload(object):
76
76
  password=password)
77
77
 
78
78
  # catalog and file store initialization
79
- if self.catalog:
80
- del self.catalog
81
- self.catalog = ErmrestCatalog(
82
- protocol, self.hostname, catalog_id, self.credentials, session_config=session_config)
83
- if self.store:
84
- del self.store
85
- self.store = HatracStore(
86
- protocol, self.hostname, self.credentials, session_config=session_config)
79
+ server = DerivaServer(protocol, self.hostname, credentials=self.credentials, session_config=session_config)
80
+ self.catalog = server.connect_ermrest(catalog_id)
81
+ self.store = HatracStore(protocol, self.hostname, self.credentials, session_config=session_config)
87
82
 
88
83
  # init dcctx cid
89
84
  self.set_dcctx_cid(kwargs.get("dcctx_cid", "api/" + self.__class__.__name__))
@@ -29,7 +29,8 @@ Client tool for interacting with DERIVA Export service.
29
29
  :param envars (dict): A dictionary of variables used for template substitution. Optional.
30
30
  :param output_dir (str): The directory where exported data will be stored (default: "."). Optional.
31
31
  :param defer_download (bool): Whether to defer the actual data download. Optional.
32
- :param timeout (int): Timeout value for export operations. Optional.
32
+ :param timeout (tuple) OR (float): Timeout value as a tuple of floats in seconds for (connect,read) export operations.
33
+ If a single float value is passed, it will apply to both connect and read operations. Optional.
33
34
  :param export_type (str): The type of export to perform (default: "bdbag"). Optional.
34
35
 
35
36
  :return: The full path to the downloaded file. If "defer_download" is True, the URL(s) where the export can be downloaded.
@@ -47,10 +48,20 @@ class DerivaExport:
47
48
  self.base_server_uri = "https://" + self.host
48
49
  self.service_url = self.base_server_uri + EXPORT_SERVICE_PATH % self.export_type
49
50
  self.session_config = DEFAULT_SESSION_CONFIG.copy()
50
- if self.timeout is not None:
51
- self.session_config["timeout"] = self.timeout
51
+ if isinstance(self.timeout, tuple):
52
+ if len(self.timeout) == 2:
53
+ self.session_config["timeout"] = self.timeout
54
+ else:
55
+ self.session_config["timeout"] = float(self.timeout[0])
56
+ elif self.timeout is not None:
57
+ try:
58
+ self.session_config["timeout"] = float(self.timeout)
59
+ except ValueError:
60
+ logger.warning("Unparseable timeout value: %r. Defaults will be used: %r." %
61
+ (self.timeout, self.session_config["timeout"]))
52
62
  self.session = get_new_requests_session(self.service_url, self.session_config)
53
63
  self.dcctx = DerivaClientContext()
64
+ self.dcctx['cid'] = kwargs.get("dcctx_cid", "api/" + self.__class__.__name__)
54
65
  self.session.headers.update({'deriva-client-context': self.dcctx.encoded()})
55
66
 
56
67
  # credential initialization
@@ -190,8 +201,10 @@ class DerivaExportCLI(BaseCLI):
190
201
  BaseCLI.__init__(self, description, epilog, **kwargs)
191
202
  self.parser.add_argument("--defer-download", action="store_true",
192
203
  help="Do not download exported file(s). Default: False")
193
- self.parser.add_argument("--timeout", metavar="<seconds>",
194
- help="Total number of seconds elapsed before the download is aborted.")
204
+ self.parser.add_argument("--timeout", metavar="<connect,read>", type=BaseCLI.parse_tuple,
205
+ help="Timeout value(s) in seconds (int or float) for connect and read operations. "
206
+ "Separate using commas. If a single value is provided it will be used for both "
207
+ "connect and read timeouts.")
195
208
  self.parser.add_argument("--export-type", choices=["bdbag", "file"], default="bdbag",
196
209
  help="Export type: {bdbag|file}. Default is bdbag.",)
197
210
  self.parser.add_argument("--output-dir", metavar="<output dir>", default=".",
@@ -212,7 +225,7 @@ class DerivaExportCLI(BaseCLI):
212
225
  sys.stderr.write("\n")
213
226
 
214
227
  try:
215
- exporter = DerivaExport(**vars(args))
228
+ exporter = DerivaExport(**vars(args), dcctx_cid="cli/" + self.__class__.__name__)
216
229
  exporter.export()
217
230
  except (DerivaDownloadError, DerivaDownloadConfigurationError, DerivaDownloadAuthenticationError,
218
231
  DerivaDownloadAuthorizationError, DerivaDownloadTimeoutError) as e:
@@ -2,7 +2,7 @@ import os
2
2
  import errno
3
3
  import certifi
4
4
  import requests
5
- from deriva.core import urlsplit, get_new_requests_session, stob, make_dirs, DEFAULT_SESSION_CONFIG
5
+ from deriva.core import urlsplit, get_new_requests_session, stob, make_dirs, format_exception, DEFAULT_SESSION_CONFIG
6
6
  from deriva.transfer.download import DerivaDownloadError, DerivaDownloadConfigurationError, \
7
7
  DerivaDownloadAuthenticationError, DerivaDownloadAuthorizationError
8
8
  from deriva.transfer.download.processors.base_processor import BaseProcessor, \
@@ -83,12 +83,12 @@ class BaseQueryProcessor(BaseProcessor):
83
83
  return self.catalog.get(self.query, headers=headers).json()
84
84
  except requests.HTTPError as e:
85
85
  if e.response.status_code == 401:
86
- raise DerivaDownloadAuthenticationError(e)
86
+ raise DerivaDownloadAuthenticationError(format_exception(e))
87
87
  if e.response.status_code == 403:
88
- raise DerivaDownloadAuthorizationError(e)
88
+ raise DerivaDownloadAuthorizationError(format_exception(e))
89
89
  if as_file:
90
90
  os.remove(self.output_abspath)
91
- raise DerivaDownloadError("Error executing catalog query: %s" % e)
91
+ raise DerivaDownloadError("Error executing catalog query: %s" % format_exception(e))
92
92
  except Exception:
93
93
  if as_file:
94
94
  os.remove(self.output_abspath)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: deriva
3
- Version: 1.7.6
3
+ Version: 1.7.7
4
4
  Summary: Python APIs and CLIs (Command-Line Interfaces) for the DERIVA platform.
5
5
  Home-page: https://github.com/informatics-isi-edu/deriva-py
6
6
  Author: USC Information Sciences Institute, Informatics Systems Research Division
@@ -8,9 +8,9 @@ deriva/config/dump_catalog_annotations.py,sha256=QzaWDLfWIAQ0eWVV11zeceWgwDBOYIe
8
8
  deriva/config/rollback_annotation.py,sha256=vqrIcen-KZX8LDpu2OVNivzIHpQoQgWkZAChZJctvtk,3015
9
9
  deriva/config/examples/group_owner_policy.json,sha256=8v3GWM1F_BWnYD9x_f6Eo4kBDvyy8g7mRqujfoEKLNc,2408
10
10
  deriva/config/examples/self_serve_policy.json,sha256=pW-cqWz4rJNNXwY4eVZFkQ8gKCHclC9yDa22ylfcDqY,1676
11
- deriva/core/__init__.py,sha256=aeGZj0oHsMpa48MGoOyfk693jk-xnWq3o8TcznkudM0,4945
11
+ deriva/core/__init__.py,sha256=D7aya8r3BTbewaSUmhbb4DB-Ltwe2aXV10CMfPo13rI,4945
12
12
  deriva/core/annotation.py,sha256=PkAkPkxX1brQsb8_drR1Qj5QjQA5mjkpXhkq9NuZ1g8,13432
13
- deriva/core/base_cli.py,sha256=EkLXOTeaFWUbPaYV-eLuLGga1PbkFVWi3Jjo-e_Vb-U,2681
13
+ deriva/core/base_cli.py,sha256=78Ilf3_f2xREQb3IIj6q0jwWAiXSObZszG0JURs36lA,2902
14
14
  deriva/core/catalog_cli.py,sha256=-6Bo6GLWFWap7y3VxkzPs73HAe_XzRXIJMW-Ri84m3M,23273
15
15
  deriva/core/datapath.py,sha256=w8LvPAd_DuknKxHc_YS6NUHhTY6XpCSkfa0m_xQUdZE,89068
16
16
  deriva/core/deriva_binding.py,sha256=_sA9HGrcVRqT-OhrneMDMOquyVOFOxLq3WzBQhasLIM,12970
@@ -18,7 +18,7 @@ deriva/core/deriva_server.py,sha256=nsW3gwg1sIaHl3BTf-nL41AkSj3dEpcEBlatvjvN8CQ,
18
18
  deriva/core/ermrest_catalog.py,sha256=_eqQg16i1aA95R99B7tLZxHWQlYk-rLpN_0zghfNWRc,54991
19
19
  deriva/core/ermrest_model.py,sha256=NdvrMLkmNTY4ncodzojpyV1XjgSlod7x-SXyUu65Z0Q,124921
20
20
  deriva/core/hatrac_cli.py,sha256=l9QmneLRHSMiG_z9S83ea0QGVhTS3Wq1KGPEKEDpecM,14522
21
- deriva/core/hatrac_store.py,sha256=pRupabYZzXvf1iQTYmv0AME8n7KCkTCMfrojhl_JOTs,22178
21
+ deriva/core/hatrac_store.py,sha256=NcVuO4h4hswbEAct8tTKZ1pNtXBn74Nn9TelKN_jr8Q,22323
22
22
  deriva/core/mmo.py,sha256=dcB8akgsqbYMi22ClbVpOKVL6so8FjSDjSb6gP4_jFo,17852
23
23
  deriva/core/polling_ermrest_catalog.py,sha256=KsjiFqPQaHWnJZCVF5i77sdzfubqZHgMBbQ1p8V8D3s,10351
24
24
  deriva/core/schemas/app_links.schema.json,sha256=AxrkC2scxomM6N7jyjtdYA73BbZzPrmuqU8PYWe7okI,954
@@ -60,9 +60,9 @@ deriva/transfer/backup/deriva_backup.py,sha256=IO9Tmzx6jHfUCkP-41nSsAeOFLn9T-0Hw
60
60
  deriva/transfer/backup/deriva_backup_cli.py,sha256=T0tvPKWniRinMQt0qG7FI8AoK3GgtlT6EyBZmZCAjL8,2157
61
61
  deriva/transfer/download/__init__.py,sha256=Pr7Zud4AFsIWwopTxeC_pupslgCG_lzycO9w9Xyh88Q,350
62
62
  deriva/transfer/download/__main__.py,sha256=YUg7AZ07t_xaOgtfJnU_l1nkEHCCPR8sU5X-l1An6SY,363
63
- deriva/transfer/download/deriva_download.py,sha256=9WHX0iBUsXv3iT0pEy95kpVN-Oh4vc6ywI5tYmJWpfk,17145
63
+ deriva/transfer/download/deriva_download.py,sha256=ulFrHHEDj3oJA2pAo7MGvGyDF9rA3l8yCUoK3FMvHEk,17100
64
64
  deriva/transfer/download/deriva_download_cli.py,sha256=wN8tyQDv1AIE_aDqjECbmkoEWN050vlEdJyteYbdgSs,3940
65
- deriva/transfer/download/deriva_export.py,sha256=lymAfCrD0Ol2kVgx7g0UAGez755D3ak8tMEneCHzwUQ,12102
65
+ deriva/transfer/download/deriva_export.py,sha256=R6f08eJSt1iBeDNNQhThN3W1l4UwE0xzy2DjXbqNskE,13085
66
66
  deriva/transfer/download/processors/__init__.py,sha256=evLp36tZn-Z_AMshdfV3JJO8w1es5owsnRN0IFJUwIo,4507
67
67
  deriva/transfer/download/processors/base_processor.py,sha256=R6IIHSa_euv4X2Dyhd8fvQAiVYDGJTWMQtPoukHQn-Q,3837
68
68
  deriva/transfer/download/processors/postprocess/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -71,7 +71,7 @@ deriva/transfer/download/processors/postprocess/transfer_post_processor.py,sha25
71
71
  deriva/transfer/download/processors/postprocess/url_post_processor.py,sha256=s68iIYqQSZHtbv4y-fCG8pjhApAeMEG6hYcKx2Pvf5Y,2745
72
72
  deriva/transfer/download/processors/query/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
73
73
  deriva/transfer/download/processors/query/bag_fetch_query_processor.py,sha256=tiQtfuy01YgOFFD5b_sP7TGjMnt0Jqcg2gp1KNWqeLE,5645
74
- deriva/transfer/download/processors/query/base_query_processor.py,sha256=DGvYM4Ykwo5OYq2D-HKB2bYPuqhJMKdMQ8GGw7OCMz0,10393
74
+ deriva/transfer/download/processors/query/base_query_processor.py,sha256=0tGxTJKCEqm7ecdOcfd8szA94muc2jbYwbqYvTGwAac,10465
75
75
  deriva/transfer/download/processors/query/file_download_query_processor.py,sha256=Hg1NbKsaGJh9cB86yIyL7Fm7ywSNVop837Dv8aFXUes,7257
76
76
  deriva/transfer/download/processors/transform/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  deriva/transfer/download/processors/transform/base_transform_processor.py,sha256=Ddw5gsNpDANeuLvUaF4utp8psaxOtAzlgXtOg8gb-Pc,4109
@@ -108,9 +108,9 @@ tests/deriva/core/mmo/test_mmo_find.py,sha256=PcUN76sik68B3XKg0G3wHVpKcPEld_6Rtb
108
108
  tests/deriva/core/mmo/test_mmo_prune.py,sha256=4pYtYL8g1BgadlewNPVpVA5lT_gV6SPTDYf04ZKzBTA,6851
109
109
  tests/deriva/core/mmo/test_mmo_rename.py,sha256=4oSR1G3Od701Ss3AnolI1Z7CbMxKuQF2uSr2_IcoR6s,8512
110
110
  tests/deriva/core/mmo/test_mmo_replace.py,sha256=w-66LWyiQ_ajC7Ipmhc4kAKwIloPdQELeUPsvelTdX8,8439
111
- deriva-1.7.6.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
112
- deriva-1.7.6.dist-info/METADATA,sha256=qEPrF-sL3FER0i9i_RzniT-nGZeNMcA8j1tkm5pcDmE,1623
113
- deriva-1.7.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
114
- deriva-1.7.6.dist-info/entry_points.txt,sha256=HmYCHlgbjYQ_aZX_j4_4tApH4tDTbYtS66jKlfytbn8,850
115
- deriva-1.7.6.dist-info/top_level.txt,sha256=_LHDie5-O53wFlexfrxjewpVkf04oydf3CqX5h75DXE,13
116
- deriva-1.7.6.dist-info/RECORD,,
111
+ deriva-1.7.7.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
112
+ deriva-1.7.7.dist-info/METADATA,sha256=V1dOlM-ESgLHfPMX_EOZ-kI6jvouKBIIzBcwwZ_bnnM,1623
113
+ deriva-1.7.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
114
+ deriva-1.7.7.dist-info/entry_points.txt,sha256=HmYCHlgbjYQ_aZX_j4_4tApH4tDTbYtS66jKlfytbn8,850
115
+ deriva-1.7.7.dist-info/top_level.txt,sha256=_LHDie5-O53wFlexfrxjewpVkf04oydf3CqX5h75DXE,13
116
+ deriva-1.7.7.dist-info/RECORD,,
File without changes