dcicutils 8.14.0.1b2__py3-none-any.whl → 8.14.0.1b3__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.
@@ -123,7 +123,8 @@ def main():
123
123
  parser.add_argument("--delete", type=str, required=False, default=None, help="Delete data.")
124
124
  parser.add_argument("--purge", type=str, required=False, default=None, help="Purge data.")
125
125
  parser.add_argument("--noignore", action="store_true", required=False, default=False,
126
- help="Do not ignore standard fields on insert.")
126
+ help="Do not ignore standard fields on update(s).")
127
+ parser.add_argument("--ignore", nargs="+", help="Ignore these additional fields.")
127
128
  parser.add_argument("--confirm", action="store_true", required=False, default=False, help="Confirm before action.")
128
129
  parser.add_argument("--verbose", action="store_true", required=False, default=False, help="Verbose output.")
129
130
  parser.add_argument("--quiet", action="store_true", required=False, default=False, help="Quiet output.")
@@ -158,7 +159,7 @@ def main():
158
159
  explicit_schema_name=explicit_schema_name,
159
160
  update_function=post_data,
160
161
  update_action_name="POST",
161
- noignore=args.noignore,
162
+ noignore=args.noignore, ignore=args.ignore,
162
163
  confirm=args.confirm, verbose=args.verbose, quiet=args.quiet, debug=args.debug)
163
164
  if args.patch:
164
165
  _post_or_patch_or_upsert(portal=portal,
@@ -167,7 +168,7 @@ def main():
167
168
  update_function=patch_data,
168
169
  update_action_name="PATCH",
169
170
  patch_delete_fields=args.delete,
170
- noignore=args.noignore,
171
+ noignore=args.noignore, ignore=args.ignore,
171
172
  confirm=args.confirm, verbose=args.verbose, quiet=args.quiet, debug=args.debug)
172
173
  args.delete = None
173
174
  if args.upsert:
@@ -177,7 +178,7 @@ def main():
177
178
  update_function=upsert_data,
178
179
  update_action_name="UPSERT",
179
180
  patch_delete_fields=args.delete,
180
- noignore=args.noignore,
181
+ noignore=args.noignore, ignore=args.ignore,
181
182
  confirm=args.confirm, verbose=args.verbose, quiet=args.quiet, debug=args.debug)
182
183
  args.delete = None
183
184
 
@@ -201,7 +202,7 @@ def _post_or_patch_or_upsert(portal: Portal, file_or_directory: str,
201
202
  explicit_schema_name: str,
202
203
  update_function: Callable, update_action_name: str,
203
204
  patch_delete_fields: Optional[str] = None,
204
- noignore: bool = False,
205
+ noignore: bool = False, ignore: Optional[List[str]] = None,
205
206
  confirm: bool = False, verbose: bool = False,
206
207
  quiet: bool = False, debug: bool = False) -> None:
207
208
 
@@ -227,7 +228,8 @@ def _post_or_patch_or_upsert(portal: Portal, file_or_directory: str,
227
228
  if debug:
228
229
  _print(f"DEBUG: File ({file}) contains an object of type: {schema_name}")
229
230
  update_function(portal, data, schema_name, file=file,
230
- patch_delete_fields=patch_delete_fields, noignore=noignore,
231
+ patch_delete_fields=patch_delete_fields,
232
+ noignore=noignore, ignore=ignore,
231
233
  confirm=confirm, verbose=verbose, debug=debug)
232
234
  elif is_schema_name_list(portal, list(data.keys())):
233
235
  if debug:
@@ -238,7 +240,8 @@ def _post_or_patch_or_upsert(portal: Portal, file_or_directory: str,
238
240
  _print(f"DEBUG: Processing {update_action_name}s for type: {schema_name}")
239
241
  for index, item in enumerate(schema_data):
240
242
  update_function(portal, item, schema_name, file=file, index=index,
241
- patch_delete_fields=patch_delete_fields, noignore=noignore,
243
+ patch_delete_fields=patch_delete_fields,
244
+ noignore=noignore, ignore=ignore,
242
245
  confirm=confirm, verbose=verbose, debug=debug)
243
246
  else:
244
247
  _print(f"WARNING: File ({file}) contains schema item which is not a list: {schema_name}")
@@ -249,7 +252,8 @@ def _post_or_patch_or_upsert(portal: Portal, file_or_directory: str,
249
252
  _print(f"DEBUG: File ({file}) contains a list of objects of type: {schema_name}")
250
253
  for index, item in enumerate(data):
251
254
  update_function(portal, item, schema_name, file=file, index=index,
252
- patch_delete_fields=patch_delete_fields, noignore=noignore,
255
+ patch_delete_fields=patch_delete_fields,
256
+ noignore=noignore, ignore=ignore,
253
257
  confirm=confirm, verbose=verbose, debug=debug)
254
258
  if debug:
255
259
  _print(f"DEBUG: Processing {update_action_name} file done: {file}")
@@ -284,7 +288,8 @@ def _post_or_patch_or_upsert(portal: Portal, file_or_directory: str,
284
288
 
285
289
  def post_data(portal: Portal, data: dict, schema_name: str,
286
290
  file: Optional[str] = None, index: int = 0,
287
- patch_delete_fields: Optional[str] = None, noignore: bool = False,
291
+ patch_delete_fields: Optional[str] = None,
292
+ noignore: bool = False, ignore: Optional[List[str]] = None,
288
293
  confirm: bool = False, verbose: bool = False, debug: bool = False) -> None:
289
294
  ignored(patch_delete_fields)
290
295
  if not (identifying_path := portal.get_identifying_path(data, portal_type=schema_name)):
@@ -301,7 +306,7 @@ def post_data(portal: Portal, data: dict, schema_name: str,
301
306
  if verbose:
302
307
  _print(f"POST {schema_name} item: {identifying_path}")
303
308
  try:
304
- data = _prune_data_for_update(data, noignore=noignore)
309
+ data = _prune_data_for_update(data, noignore=noignore, ignore=ignore)
305
310
  portal.post_metadata(schema_name, data)
306
311
  if debug:
307
312
  _print(f"DEBUG: POST {schema_name} item done: {identifying_path}")
@@ -313,7 +318,8 @@ def post_data(portal: Portal, data: dict, schema_name: str,
313
318
 
314
319
  def patch_data(portal: Portal, data: dict, schema_name: str,
315
320
  file: Optional[str] = None, index: int = 0,
316
- patch_delete_fields: Optional[str] = None, noignore: bool = False,
321
+ patch_delete_fields: Optional[str] = None,
322
+ noignore: bool = False, ignore: Optional[List[str]] = None,
317
323
  confirm: bool = False, verbose: bool = False, debug: bool = False) -> None:
318
324
  if not (identifying_path := portal.get_identifying_path(data, portal_type=schema_name)):
319
325
  if isinstance(file, str) and isinstance(index, int):
@@ -331,7 +337,7 @@ def patch_data(portal: Portal, data: dict, schema_name: str,
331
337
  try:
332
338
  if delete_fields := _parse_delete_fields(patch_delete_fields):
333
339
  identifying_path += f"?delete_fields={delete_fields}"
334
- data = _prune_data_for_update(data, noignore=noignore)
340
+ data = _prune_data_for_update(data, noignore=noignore, ignore=ignore)
335
341
  portal.patch_metadata(identifying_path, data)
336
342
  if debug:
337
343
  _print(f"DEBUG: PATCH {schema_name} item OK: {identifying_path}")
@@ -343,7 +349,8 @@ def patch_data(portal: Portal, data: dict, schema_name: str,
343
349
 
344
350
  def upsert_data(portal: Portal, data: dict, schema_name: str,
345
351
  file: Optional[str] = None, index: int = 0,
346
- patch_delete_fields: Optional[str] = None, noignore: bool = False,
352
+ patch_delete_fields: Optional[str] = None,
353
+ noignore: bool = False, ignore: Optional[List[str]] = None,
347
354
  confirm: bool = False, verbose: bool = False, debug: bool = False) -> None:
348
355
  if not (identifying_path := portal.get_identifying_path(data, portal_type=schema_name)):
349
356
  if isinstance(file, str) and isinstance(index, int):
@@ -358,12 +365,12 @@ def upsert_data(portal: Portal, data: dict, schema_name: str,
358
365
  _print(f"{'PATCH' if exists else 'POST'} {schema_name} item: {identifying_path}")
359
366
  try:
360
367
  if not exists:
361
- data = _prune_data_for_update(data, noignore=noignore)
368
+ data = _prune_data_for_update(data, noignore=noignore, ignore=ignore)
362
369
  portal.post_metadata(schema_name, data)
363
370
  else:
364
371
  if delete_fields := _parse_delete_fields(patch_delete_fields):
365
372
  identifying_path += f"?delete_fields={delete_fields}"
366
- data = _prune_data_for_update(data, noignore=noignore)
373
+ data = _prune_data_for_update(data, noignore=noignore, ignore=ignore)
367
374
  portal.patch_metadata(identifying_path, data)
368
375
  if debug:
369
376
  _print(f"DEBUG: UPSERT {schema_name} item OK: {identifying_path}")
@@ -373,10 +380,13 @@ def upsert_data(portal: Portal, data: dict, schema_name: str,
373
380
  return
374
381
 
375
382
 
376
- def _prune_data_for_update(data: dict, noignore: bool = False) -> dict:
377
- if noignore is True:
383
+ def _prune_data_for_update(data: dict, noignore: bool = False, ignore: Optional[List[str]] = None) -> dict:
384
+ ignore_these_properties = [] if noignore is True else _IGNORE_PROPERTIES_ON_UPDATE
385
+ if isinstance(ignore, list):
386
+ ignore_these_properties = ignore_these_properties + ignore
387
+ if not ignore_these_properties:
378
388
  return data
379
- return {key: value for key, value in data.items() if key not in _IGNORE_PROPERTIES_ON_UPDATE}
389
+ return {key: value for key, value in data.items() if key not in ignore_these_properties}
380
390
 
381
391
 
382
392
  def _create_portal(env: Optional[str] = None, app: Optional[str] = None,
@@ -104,6 +104,7 @@ def main():
104
104
  parser.add_argument("--raw", action="store_true", required=False, default=False, help="Raw output.")
105
105
  parser.add_argument("--inserts", action="store_true", required=False, default=False,
106
106
  help="Format output for subsequent inserts.")
107
+ parser.add_argument("--ignore", nargs="+", help="Ignore these fields for --inserts.")
107
108
  parser.add_argument("--tree", action="store_true", required=False, default=False, help="Tree output for schemas.")
108
109
  parser.add_argument("--database", action="store_true", required=False, default=False,
109
110
  help="Read from database output.")
@@ -191,7 +192,7 @@ def main():
191
192
  return
192
193
 
193
194
  data = _get_portal_object(portal=portal, uuid=args.uuid, raw=args.raw, inserts=args.inserts,
194
- database=args.database, check=args.bool, verbose=args.verbose)
195
+ ignore=args.ignore, database=args.database, check=args.bool, verbose=args.verbose)
195
196
  if args.bool:
196
197
  if data:
197
198
  _print(f"{args.uuid}: found")
@@ -242,7 +243,15 @@ def _create_portal(ini: str, env: Optional[str] = None,
242
243
 
243
244
  def _get_portal_object(portal: Portal, uuid: str,
244
245
  raw: bool = False, inserts: bool = False, database: bool = False,
246
+ ignore: Optional[List[str]] = None,
245
247
  check: bool = False, verbose: bool = False) -> dict:
248
+
249
+ def prune_data(data: dict) -> dict:
250
+ nonlocal ignore
251
+ if not isinstance(ignore, list) or not ignore:
252
+ return data
253
+ return {key: value for key, value in data.items() if key not in ignore}
254
+
246
255
  response = None
247
256
  try:
248
257
  if not uuid.startswith("/"):
@@ -300,6 +309,7 @@ def _get_portal_object(portal: Portal, uuid: str,
300
309
  for result in results:
301
310
  results_index += 1
302
311
  result.pop("schema_version", None)
312
+ result = prune_data(result)
303
313
  if (subtypes and
304
314
  (result_uuid := result.get("uuid")) and
305
315
  (individual_result_type := get_metadata_for_individual_result_type(result_uuid))): # noqa
@@ -313,7 +323,7 @@ def _get_portal_object(portal: Portal, uuid: str,
313
323
  # Get the result as non-raw so we can get its type.
314
324
  elif ((response_cooked := portal.get(path, database=database)) and
315
325
  (isinstance(response_type := response_cooked.json().get("@type"), list) and response_type)):
316
- response = {f"{response_type[0]}": [response]}
326
+ response = {f"{response_type[0]}": [prune_data(response)]}
317
327
  elif raw:
318
328
  response.pop("schema_version", None)
319
329
  return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dcicutils
3
- Version: 8.14.0.1b2
3
+ Version: 8.14.0.1b3
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
@@ -60,8 +60,8 @@ dcicutils/s3_utils.py,sha256=h2B9ftOo-kxqfiKth5ZDC_cAUFy1Pbu7BrVanFnE5Iw,28839
60
60
  dcicutils/schema_utils.py,sha256=GmRm-XqZKJ6qine16SQF1txcby9WougDav_sYmKNs9E,12400
61
61
  dcicutils/scripts/publish_to_pypi.py,sha256=sMd4WASQGlxlh7uLrt2eGkFRXYgONVmvIg8mClMS5RQ,13903
62
62
  dcicutils/scripts/run_license_checker.py,sha256=z2keYnRDZsHQbTeo1XORAXSXNJK5axVzL5LjiNqZ7jE,4184
63
- dcicutils/scripts/update_portal_object.py,sha256=gIO0fz6_SrfttYrdhfX7BVAYdtC4VZDXomycPrNWdbI,21395
64
- dcicutils/scripts/view_portal_object.py,sha256=yQAGxFWBZ7UU8vrD8xbeI_oS4oU2mXZBaQPCraLbdCU,33241
63
+ dcicutils/scripts/update_portal_object.py,sha256=qo_TGji-naaK2UXa-VbCfTSMsvRSEduqbQDuVXX3y4g,22188
64
+ dcicutils/scripts/view_portal_object.py,sha256=6day_AXtFf9y4oYNvZC_fGa-h9xQKbNwUBuoluVcuiI,33691
65
65
  dcicutils/secrets_utils.py,sha256=8dppXAsiHhJzI6NmOcvJV5ldvKkQZzh3Fl-cb8Wm7MI,19745
66
66
  dcicutils/sheet_utils.py,sha256=VlmzteONW5VF_Q4vo0yA5vesz1ViUah1MZ_yA1rwZ0M,33629
67
67
  dcicutils/snapshot_utils.py,sha256=YDeI3vD-MhAtHwKDzfEm2q-n3l-da2yRpRR3xp0Ah1M,23021
@@ -75,8 +75,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
75
75
  dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
76
76
  dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
77
77
  dcicutils/zip_utils.py,sha256=_Y9EmL3D2dUZhxucxHvrtmmlbZmK4FpSsHEb7rGSJLU,3265
78
- dcicutils-8.14.0.1b2.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
79
- dcicutils-8.14.0.1b2.dist-info/METADATA,sha256=uiJoLtk6VKcjRjvIlCDmF_8ADNo31t_Kuf1fxtv5OBM,3439
80
- dcicutils-8.14.0.1b2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
81
- dcicutils-8.14.0.1b2.dist-info/entry_points.txt,sha256=W6kEWdUJk9tQ4myAgpehPdebcwvCAZ7UgB-wyPgDUMg,335
82
- dcicutils-8.14.0.1b2.dist-info/RECORD,,
78
+ dcicutils-8.14.0.1b3.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
79
+ dcicutils-8.14.0.1b3.dist-info/METADATA,sha256=iuq31-VVzXhHa2-CxoblCc7iu0CgVP7hT4hXWU75szQ,3439
80
+ dcicutils-8.14.0.1b3.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
81
+ dcicutils-8.14.0.1b3.dist-info/entry_points.txt,sha256=W6kEWdUJk9tQ4myAgpehPdebcwvCAZ7UgB-wyPgDUMg,335
82
+ dcicutils-8.14.0.1b3.dist-info/RECORD,,