deriva 1.7.0__py3-none-any.whl → 1.7.3__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.
@@ -53,11 +53,15 @@ class DerivaServer (DerivaBinding):
53
53
  """
54
54
  return ErmrestCatalog.connect(self, catalog_id, snaptime)
55
55
 
56
- def create_ermrest_catalog(self, id=None, owner=None):
56
+ def create_ermrest_catalog(self, id=None, owner=None, name=None, description=None, is_persistent=None, clone_source=None):
57
57
  """Create an ERMrest catalog.
58
58
 
59
59
  :param id: The (str) id desired by the client (default None)
60
60
  :param owner: The initial (list of str) ACL desired by the client (default None)
61
+ :param name: Initial (str) catalog name if not None
62
+ :param description: Initial (str) catalog description if not None
63
+ :param is_persistent: Initial (bool) catalog persistence flag if not None
64
+ :param clone_source: Initial catalog clone_source if not None
61
65
 
62
66
  The new catalog id will be returned in the response, and used
63
67
  in future catalog access. The use of the id parameter
@@ -77,8 +81,17 @@ class DerivaServer (DerivaBinding):
77
81
  owner ACL influences which client(s) are allowed to retry
78
82
  creation with the same id.
79
83
 
84
+ The name, description, is_persistent, and clone_source
85
+ parameters are passed through to the catalog creation service
86
+ to initialize those respective metadata fields of the new
87
+ catalog's registry entry. See ERMrest documentation for more
88
+ detail. Authorization failures may occur when attempting to
89
+ set the is_persistent flag. By default, these fields are not
90
+ initialized in the catalog creation request, and they instead
91
+ receive server-assigned defaults.
92
+
80
93
  """
81
- return ErmrestCatalog.create(self, id, owner)
94
+ return ErmrestCatalog.create(self, id, owner, name, description, is_persistent, clone_source)
82
95
 
83
96
  def connect_ermrest_alias(self, id):
84
97
  """Connect to an ERMrest alias and return the alias binding.
@@ -88,12 +101,14 @@ class DerivaServer (DerivaBinding):
88
101
  """
89
102
  return ErmrestAlias.connect(self, id)
90
103
 
91
- def create_ermrest_alias(self, id=None, owner=None, alias_target=None):
104
+ def create_ermrest_alias(self, id=None, owner=None, alias_target=None, name=None, description=None):
92
105
  """Create an ERMrest catalog alias.
93
106
 
94
107
  :param id: The (str) id desired by the client (default None)
95
108
  :param owner: The initial (list of str) ACL desired by the client (default None)
96
109
  :param alias_target: The initial target catalog id binding desired by the client (default None)
110
+ :param name: Initial (str) catalog name if not None
111
+ :param description: Initial (str) catalog description if not None
97
112
 
98
113
  The new alias id will be returned in the response, and used
99
114
  in future alias access. The use of the id parameter
@@ -118,8 +133,13 @@ class DerivaServer (DerivaBinding):
118
133
  influences which client(s) are allowed to retry creation with
119
134
  the same id.
120
135
 
136
+ The name and description parameters are passed through to the
137
+ alias creation service to initialize those respective metadata
138
+ fields of the new aliase's registry entry. See ERMrest
139
+ documentation for more detail.
140
+
121
141
  """
122
- return ErmrestAlias.create(self, id, owner, alias_target)
142
+ return ErmrestAlias.create(self, id, owner, alias_target, name, description)
123
143
 
124
144
  class ErmrestCatalogMutationError(Exception):
125
145
  pass
@@ -204,15 +224,22 @@ class ErmrestCatalog(DerivaBinding):
204
224
  )
205
225
 
206
226
  @classmethod
207
- def _digest_catalog_args(cls, id, owner):
227
+ def _digest_catalog_args(cls, id, owner, name=None, description=None, is_persistent=None, clone_source=None):
208
228
  rep = dict()
209
229
 
210
- if isinstance(id, str):
211
- rep['id'] = id
212
- elif isinstance(id, (type(nochange), type(None))):
213
- pass
214
- else:
215
- raise TypeError('id must be of type str or None or nochange, not %s' % type(id))
230
+ for v, k, typ in [
231
+ (id, 'id', str),
232
+ (name, 'name', str),
233
+ (description, 'description', str),
234
+ (is_persistent, 'is_persistent', bool),
235
+ (clone_source, 'clone_source', str),
236
+ ]:
237
+ if isinstance(v, typ):
238
+ rep[k] = v
239
+ elif isinstance(v, (type(nochange), type(None))):
240
+ pass
241
+ else:
242
+ raise TypeError('%s must be of type %s or None or nochange, not %s' % (k, typ.__name__, type(v)))
216
243
 
217
244
  if isinstance(owner, list):
218
245
  for e in owner:
@@ -227,12 +254,16 @@ class ErmrestCatalog(DerivaBinding):
227
254
  return rep
228
255
 
229
256
  @classmethod
230
- def create(cls, deriva_server, id=None, owner=None):
257
+ def create(cls, deriva_server, id=None, owner=None, name=None, description=None, is_persistent=None, clone_source=None):
231
258
  """Create an ERMrest catalog and return the ERMrest catalog binding.
232
259
 
233
260
  :param deriva_server: The DerivaServer binding which hosts ermrest.
234
261
  :param id: The (str) id desired by the client (default None)
235
262
  :param owner: The initial (list of str) ACL desired by the client (default None)
263
+ :param name: Initial (str) catalog name if not None
264
+ :param description: Initial (str) catalog description if not None
265
+ :param is_persistent: Initial (bool) catalog persistence flag if not None
266
+ :param clone_source: Initial catalog clone_source if not None
236
267
 
237
268
  The new catalog id will be returned in the response, and used
238
269
  in future catalog access. The use of the id parameter
@@ -252,9 +283,18 @@ class ErmrestCatalog(DerivaBinding):
252
283
  influences which client(s) are allowed to retry creation with
253
284
  the same id.
254
285
 
286
+ The name, description, is_persistent, and clone_source
287
+ parameters are passed through to the catalog creation service
288
+ to initialize those respective metadata fields of the new
289
+ catalog's registry entry. See ERMrest documentation for more
290
+ detail. Authorization failures may occur when attempting to
291
+ set the is_persistent flag. By default, these fields are not
292
+ initialized in the catalog creation request, and they instead
293
+ receive server-assigned defaults.
294
+
255
295
  """
256
296
  path = '/ermrest/catalog'
257
- r = deriva_server.post(path, json=cls._digest_catalog_args(id, owner))
297
+ r = deriva_server.post(path, json=cls._digest_catalog_args(id, owner, name, description, is_persistent, clone_source))
258
298
  r.raise_for_status()
259
299
  return cls.connect(deriva_server, r.json()['id'])
260
300
 
@@ -655,7 +695,8 @@ class ErmrestCatalog(DerivaBinding):
655
695
  copy_annotations=True,
656
696
  copy_policy=True,
657
697
  truncate_after=True,
658
- exclude_schemas=None):
698
+ exclude_schemas=None,
699
+ dst_properties=None):
659
700
  """Clone this catalog's content into dest_catalog, creating a new catalog if needed.
660
701
 
661
702
  :param dst_catalog: Destination catalog or None to request creation of new destination (default).
@@ -664,13 +705,22 @@ class ErmrestCatalog(DerivaBinding):
664
705
  :param copy_policy: Copy access-control policies when True (default).
665
706
  :param truncate_after: Truncate destination history after cloning when True (default).
666
707
  :param exclude_schemas: A list of schema names to exclude from the cloning process.
708
+ :param dst_properties: A dictionary of custom catalog-creation properties.
667
709
 
668
- When dest_catalog is provided, attempt an idempotent clone,
710
+ When dst_catalog is provided, attempt an idempotent clone,
669
711
  assuming content MAY be partially cloned already using the
670
712
  same parameters. This routine uses a table-level annotation
671
713
  "tag:isrd.isi.edu,2018:clone-state" to save progress markers
672
714
  which help it restart efficiently if interrupted.
673
715
 
716
+ When dst_catalog is not provided, a new catalog is
717
+ provisioned. The optional dst_properties can customize
718
+ metadata properties during this step:
719
+
720
+ - name: str
721
+ - description: str (markdown-formatted)
722
+ - is_persistent: boolean
723
+
674
724
  Cloning preserves source row RID values for application tables
675
725
  so that any RID-based foreign keys are still valid. It is not
676
726
  generally advisable to try to merge more than one source into
@@ -692,10 +742,33 @@ class ErmrestCatalog(DerivaBinding):
692
742
  session_config["allow_retry_on_all_methods"] = True
693
743
 
694
744
  if dst_catalog is None:
695
- # TODO: refactor with DerivaServer someday
696
- server = DerivaBinding(self._scheme, self._server, self._credentials, self._caching, session_config)
697
- dst_id = server.post("/ermrest/catalog").json()["id"]
698
- dst_catalog = ErmrestCatalog(self._scheme, self._server, dst_id, self._credentials, self._caching, session_config)
745
+ if dst_properties is not None:
746
+ if not isinstance(dst_properties, dict):
747
+ raise TypeError('dst_properties must be of type dict or None, not %s' % (type(dst_properties),))
748
+ else:
749
+ dst_properties = {}
750
+ kwargs = {
751
+ "name": dst_properties.get('name', 'Clone of %r' % (self._catalog_id,)),
752
+ "description": dst_properties.get(
753
+ 'description',
754
+ '''A cloned copy of catalog %r made with ErmrestCatalog.clone_catalog() using the following parameters:
755
+ - `copy_data`: %r
756
+ - `copy_annotations`: %r
757
+ - `copy_policy`: %r
758
+ - `truncate_after`: %r
759
+ - `exclude_schemas`: %r
760
+ ''' % (
761
+ self._catalog_id,
762
+ copy_data,
763
+ copy_annotations,
764
+ copy_policy,
765
+ truncate_after,
766
+ exclude_schemas,
767
+ )),
768
+ "clone_source": dst_properties.get('clone_source', self._catalog_id),
769
+ }
770
+ server = self.deriva_server
771
+ dst_catalog = server.create_ermrest_catalog(**kwargs)
699
772
 
700
773
  # set top-level config right away and find fatal usage errors...
701
774
  if copy_policy:
@@ -1051,8 +1124,8 @@ class ErmrestAlias(DerivaBinding):
1051
1124
  )
1052
1125
 
1053
1126
  @classmethod
1054
- def _digest_alias_args(cls, id, owner, alias_target):
1055
- rep = ErmrestCatalog._digest_catalog_args(id, owner)
1127
+ def _digest_alias_args(cls, id, owner, alias_target, name, description):
1128
+ rep = ErmrestCatalog._digest_catalog_args(id, owner, name, description)
1056
1129
 
1057
1130
  if isinstance(alias_target, (str, type(None))):
1058
1131
  rep['alias_target'] = alias_target
@@ -1064,13 +1137,15 @@ class ErmrestAlias(DerivaBinding):
1064
1137
  return rep
1065
1138
 
1066
1139
  @classmethod
1067
- def create(cls, deriva_server, id=None, owner=None, alias_target=None):
1140
+ def create(cls, deriva_server, id=None, owner=None, alias_target=None, name=None, description=None):
1068
1141
  """Create an ERMrest catalog alias.
1069
1142
 
1070
1143
  :param deriva_server: The DerivaServer binding which hosts ermrest
1071
1144
  :param id: The (str) id desired by the client (default None)
1072
1145
  :param owner: The initial (list of str) ACL desired by the client (default None)
1073
1146
  :param alias_target: The initial target catalog id desired by the client (default None)
1147
+ :param name: Initial (str) catalog name if not None
1148
+ :param description: Initial (str) catalog description if not None
1074
1149
 
1075
1150
  The new alias id will be returned in the response, and used
1076
1151
  in future alias access. The use of the id parameter
@@ -1095,9 +1170,14 @@ class ErmrestAlias(DerivaBinding):
1095
1170
  influences which client(s) are allowed to retry creation with
1096
1171
  the same id.
1097
1172
 
1173
+ The name and description parameters are passed through to the
1174
+ alias creation service to initialize those respective metadata
1175
+ fields of the new aliase's registry entry. See ERMrest
1176
+ documentation for more detail.
1177
+
1098
1178
  """
1099
1179
  path = '/ermrest/alias'
1100
- r = deriva_server.post(path, json=cls._digest_alias_args(id, owner, alias_target))
1180
+ r = deriva_server.post(path, json=cls._digest_alias_args(id, owner, alias_target, name, description))
1101
1181
  r.raise_for_status()
1102
1182
  return cls.connect(deriva_server, r.json()['id'])
1103
1183