das-cli 1.6.5__tar.gz → 1.6.6__tar.gz
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.
- {das_cli-1.6.5/das_cli.egg-info → das_cli-1.6.6}/PKG-INFO +15 -1
- {das_cli-1.6.5 → das_cli-1.6.6}/README.md +14 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/cli.py +48 -20
- {das_cli-1.6.5 → das_cli-1.6.6}/das/managers/entries_manager.py +107 -19
- {das_cli-1.6.5 → das_cli-1.6.6/das_cli.egg-info}/PKG-INFO +15 -1
- {das_cli-1.6.5 → das_cli-1.6.6}/pyproject.toml +1 -1
- {das_cli-1.6.5 → das_cli-1.6.6}/LICENSE +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/MANIFEST.in +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/__init__.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/ai/plugins/dasai.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/ai/plugins/entries/entries_plugin.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/app.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/authentication/auth.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/authentication/oauth.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/authentication/secure_input.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/api.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/config.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/entry_fields_constants.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/enums.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/errors.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/exceptions.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/common/file_utils.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/managers/__init__.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/managers/digital_objects_manager.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/managers/download_manager.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/managers/search_manager.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/attributes.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/cache.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/das_elastic_search.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/digital_objects.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/downloads.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/entries.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/entry_fields.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/hangfire.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/search.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/service_base.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das/services/users.py +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das_cli.egg-info/SOURCES.txt +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das_cli.egg-info/dependency_links.txt +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das_cli.egg-info/entry_points.txt +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das_cli.egg-info/requires.txt +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/das_cli.egg-info/top_level.txt +0 -0
- {das_cli-1.6.5 → das_cli-1.6.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: das-cli
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.6
|
|
4
4
|
Summary: DAS api client.
|
|
5
5
|
Author: Royal Netherlands Institute for Sea Research
|
|
6
6
|
License-Expression: MIT
|
|
@@ -362,6 +362,20 @@ entry = entries.get(id="6b0e68e6-00cd-43a7-9c51-d56c9c091123")
|
|
|
362
362
|
entry = entries.get_entry("6b0e68e6-00cd-43a7-9c51-d56c9c091123")
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
+
When the entry has digital objects attached they are always included, even for
|
|
366
|
+
attributes whose entry-field metadata does not expose a digital-object field.
|
|
367
|
+
They land under the digital-object field's display name when there is one, and
|
|
368
|
+
under `"Digital Object(s)"` otherwise:
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
for obj in entry.get("Digital Object(s)", []):
|
|
372
|
+
print(obj["Id"], obj["Name"], obj["Type"], obj["Links"])
|
|
373
|
+
# 1715e27d-bc89-4f9c-8fdf-36ad2da333c6 zeynep.erdem.jpg Image 4d.b.cb
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
`das entry get` and `das search entry <id>` print the same objects as a block
|
|
377
|
+
below the field list (or inline in the payload with `--format json`).
|
|
378
|
+
|
|
365
379
|
#### `create` — create one or many entries
|
|
366
380
|
|
|
367
381
|
```python
|
|
@@ -339,6 +339,20 @@ entry = entries.get(id="6b0e68e6-00cd-43a7-9c51-d56c9c091123")
|
|
|
339
339
|
entry = entries.get_entry("6b0e68e6-00cd-43a7-9c51-d56c9c091123")
|
|
340
340
|
```
|
|
341
341
|
|
|
342
|
+
When the entry has digital objects attached they are always included, even for
|
|
343
|
+
attributes whose entry-field metadata does not expose a digital-object field.
|
|
344
|
+
They land under the digital-object field's display name when there is one, and
|
|
345
|
+
under `"Digital Object(s)"` otherwise:
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
for obj in entry.get("Digital Object(s)", []):
|
|
349
|
+
print(obj["Id"], obj["Name"], obj["Type"], obj["Links"])
|
|
350
|
+
# 1715e27d-bc89-4f9c-8fdf-36ad2da333c6 zeynep.erdem.jpg Image 4d.b.cb
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
`das entry get` and `das search entry <id>` print the same objects as a block
|
|
354
|
+
below the field list (or inline in the payload with `--format json`).
|
|
355
|
+
|
|
342
356
|
#### `create` — create one or many entries
|
|
343
357
|
|
|
344
358
|
```python
|
|
@@ -53,6 +53,32 @@ def format_table(data, headers):
|
|
|
53
53
|
|
|
54
54
|
return '\n'.join(table)
|
|
55
55
|
|
|
56
|
+
def is_digital_object_list(value):
|
|
57
|
+
"""True when a manager field value is a list of digital objects.
|
|
58
|
+
|
|
59
|
+
Digital objects are normalized to Id/Name/Links/Type by the entry manager;
|
|
60
|
+
select/relation fields only ever carry Id/Name, so "Type" tells them apart.
|
|
61
|
+
"""
|
|
62
|
+
return (
|
|
63
|
+
isinstance(value, list)
|
|
64
|
+
and len(value) > 0
|
|
65
|
+
and all(isinstance(item, dict) and "Id" in item and "Type" in item for item in value)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def echo_digital_objects(label, objects):
|
|
70
|
+
"""Print a digital-object list as an indented block."""
|
|
71
|
+
click.echo()
|
|
72
|
+
click.echo("─" * 40)
|
|
73
|
+
click.echo(f"{label}:")
|
|
74
|
+
for obj in objects:
|
|
75
|
+
click.echo(f" - ID: {obj.get('Id')}")
|
|
76
|
+
click.echo(f" Name: {obj.get('Name')}")
|
|
77
|
+
click.echo(f" Type: {obj.get('Type')}")
|
|
78
|
+
click.echo(f" Links: {obj.get('Links')}")
|
|
79
|
+
click.echo()
|
|
80
|
+
|
|
81
|
+
|
|
56
82
|
class DasCLI:
|
|
57
83
|
def __init__(self):
|
|
58
84
|
self.client = None
|
|
@@ -378,11 +404,17 @@ def get_entry(das_ctx, entry_id, output_format):
|
|
|
378
404
|
|
|
379
405
|
# Format display fields in a readable way
|
|
380
406
|
formatted_data = []
|
|
407
|
+
digital_object_blocks = []
|
|
381
408
|
for key, value in sorted(entry.items()):
|
|
382
409
|
# Skip empty or None values
|
|
383
410
|
if value is None or value == '':
|
|
384
411
|
continue
|
|
385
|
-
|
|
412
|
+
|
|
413
|
+
# Digital objects get their own block below the key/value list
|
|
414
|
+
if is_digital_object_list(value):
|
|
415
|
+
digital_object_blocks.append((key, value))
|
|
416
|
+
continue
|
|
417
|
+
|
|
386
418
|
# Format date fields
|
|
387
419
|
if isinstance(value, str) and key.lower().endswith(('time', 'date')) and 'T' in value:
|
|
388
420
|
try:
|
|
@@ -398,7 +430,10 @@ def get_entry(das_ctx, entry_id, output_format):
|
|
|
398
430
|
# Display as key-value pairs
|
|
399
431
|
for key, value in formatted_data:
|
|
400
432
|
click.echo(f"{key.ljust(25)}: {value}")
|
|
401
|
-
|
|
433
|
+
|
|
434
|
+
for key, objects in digital_object_blocks:
|
|
435
|
+
echo_digital_objects(key, objects)
|
|
436
|
+
|
|
402
437
|
except Exception as e:
|
|
403
438
|
click.secho(f"Error: {e}", fg="red")
|
|
404
439
|
|
|
@@ -856,7 +891,7 @@ def direct_download_digital_object(das_ctx, entry_code, entry_id, attribute_id,
|
|
|
856
891
|
|
|
857
892
|
@entry.command("get")
|
|
858
893
|
@click.option('--code', default=None, help='Entry code')
|
|
859
|
-
@click.option('--id',
|
|
894
|
+
@click.option('--id', default=None, help='Entry ID (GUID)')
|
|
860
895
|
@pass_das_context
|
|
861
896
|
def get_entry(das_ctx, code=None, id=None):
|
|
862
897
|
"""Get entry by either its code or ID"""
|
|
@@ -872,28 +907,21 @@ def get_entry(das_ctx, code=None, id=None):
|
|
|
872
907
|
if entry:
|
|
873
908
|
click.secho("Entry Details:", fg="green", bold=True)
|
|
874
909
|
click.echo("─" * 40)
|
|
910
|
+
digital_object_blocks = []
|
|
875
911
|
for key, value in entry.items():
|
|
876
|
-
if
|
|
877
|
-
|
|
878
|
-
|
|
912
|
+
if is_digital_object_list(value):
|
|
913
|
+
# printed as its own block below, for readability
|
|
914
|
+
digital_object_blocks.append((key, value))
|
|
915
|
+
elif isinstance(value, list):
|
|
879
916
|
click.echo(f"{key}:")
|
|
880
917
|
for item in value:
|
|
881
|
-
click.echo(f" - {item}")
|
|
882
|
-
else:
|
|
918
|
+
click.echo(f" - {item}")
|
|
919
|
+
else:
|
|
883
920
|
click.echo(f"{key}: {value or ''}")
|
|
884
921
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
click.echo()
|
|
889
|
-
click.echo("─" * 40)
|
|
890
|
-
click.echo("Digital Object(s):")
|
|
891
|
-
for obj in entry['Digital Object(s)']:
|
|
892
|
-
click.echo(f" - ID: {obj.get('Id')}")
|
|
893
|
-
click.echo(f" Name: {obj.get('Name')}")
|
|
894
|
-
click.echo(f" Type: {obj.get('Type')}")
|
|
895
|
-
click.echo(f" Links: {obj.get('Links')}")
|
|
896
|
-
click.echo()
|
|
922
|
+
for key, objects in digital_object_blocks:
|
|
923
|
+
echo_digital_objects(key, objects)
|
|
924
|
+
|
|
897
925
|
click.echo("─" * 40)
|
|
898
926
|
else:
|
|
899
927
|
click.secho("Entry not found.", fg="yellow")
|
|
@@ -49,6 +49,54 @@ def _safe_lower(value) -> str:
|
|
|
49
49
|
return str(value).lower()
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
# Key used for digital objects when the attribute's entry-field metadata does
|
|
53
|
+
# not expose a DIGITAL_OBJECT_INPUT field (the CLI already prints this name).
|
|
54
|
+
DIGITAL_OBJECTS_KEY = "Digital Object(s)"
|
|
55
|
+
|
|
56
|
+
# Keys only a digital-object payload carries. Select/relation attributes are
|
|
57
|
+
# also returned as JSON lists under numeric keys, but they only ever hold
|
|
58
|
+
# id/name/attributeid/tag - so these markers tell the two apart.
|
|
59
|
+
_DIGITAL_OBJECT_MARKERS = ("filesize", "checksum", "instrumentname", "path")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _normalize_digital_object(obj: dict) -> dict:
|
|
63
|
+
"""Reduce a raw digital-object payload to the fields we surface."""
|
|
64
|
+
return {
|
|
65
|
+
"Id": obj.get("id"),
|
|
66
|
+
"Name": obj.get("name"),
|
|
67
|
+
"Links": obj.get("needle"),
|
|
68
|
+
"Type": obj.get("typename"),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _parse_digital_objects(value):
|
|
73
|
+
"""Parse a raw entry value into a list of normalized digital objects.
|
|
74
|
+
|
|
75
|
+
Returns ``None`` when the value is not a JSON list of digital objects, so
|
|
76
|
+
callers can safely walk every value of an entry payload.
|
|
77
|
+
"""
|
|
78
|
+
if not isinstance(value, str) or value.strip() == "":
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
data = json.loads(value)
|
|
83
|
+
except ValueError: # includes json.JSONDecodeError
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
if not isinstance(data, list):
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
objects = [obj for obj in data if isinstance(obj, dict)]
|
|
90
|
+
|
|
91
|
+
if not objects:
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
if not any(marker in obj for obj in objects for marker in _DIGITAL_OBJECT_MARKERS):
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
return [_normalize_digital_object(obj) for obj in objects]
|
|
98
|
+
|
|
99
|
+
|
|
52
100
|
class EntryManager:
|
|
53
101
|
def __init__(self):
|
|
54
102
|
|
|
@@ -160,6 +208,8 @@ class EntryManager:
|
|
|
160
208
|
|
|
161
209
|
entry[field_name] = field_value
|
|
162
210
|
|
|
211
|
+
self.__attach_digital_objects(entry, entry_raw, fields.get("result").get("items"))
|
|
212
|
+
|
|
163
213
|
if (entry_raw.get("creationtime") is not None):
|
|
164
214
|
entry["Created At"] = entry_raw.get("creationtime")
|
|
165
215
|
|
|
@@ -652,27 +702,65 @@ class EntryManager:
|
|
|
652
702
|
def __get_digital_object_field_value(self, entry_raw, field):
|
|
653
703
|
"""Helper method to get digital object field value."""
|
|
654
704
|
digital_objects = entry_raw.get(_safe_lower(field.get('column')), None)
|
|
655
|
-
|
|
656
|
-
|
|
705
|
+
|
|
706
|
+
if digital_objects is None:
|
|
707
|
+
return None
|
|
657
708
|
|
|
658
709
|
# checks if its a valid json string
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
710
|
+
try:
|
|
711
|
+
data = json.loads(digital_objects) if isinstance(digital_objects, str) else digital_objects
|
|
712
|
+
except (TypeError, ValueError): # ValueError includes json.JSONDecodeError
|
|
713
|
+
return digital_objects
|
|
714
|
+
|
|
715
|
+
if isinstance(data, list):
|
|
716
|
+
return [_normalize_digital_object(obj) for obj in data if isinstance(obj, dict)]
|
|
717
|
+
|
|
718
|
+
def __attach_digital_objects(self, entry, entry_raw, field_items):
|
|
719
|
+
"""Make sure the digital objects of an entry are part of the result.
|
|
720
|
+
|
|
721
|
+
The backend returns digital objects under the *attribute id* of the
|
|
722
|
+
digital-object attribute (e.g. ``"6"``), and that column is not always
|
|
723
|
+
present in the entry-field metadata - so mapping fields alone silently
|
|
724
|
+
drops them. Scan the raw payload instead and expose whatever is there
|
|
725
|
+
under the digital-object field name (or ``DIGITAL_OBJECTS_KEY``).
|
|
726
|
+
"""
|
|
727
|
+
digital_objects = []
|
|
728
|
+
seen_ids = set()
|
|
729
|
+
|
|
730
|
+
for value in entry_raw.values():
|
|
731
|
+
objects = _parse_digital_objects(value)
|
|
732
|
+
|
|
733
|
+
if not objects:
|
|
734
|
+
continue
|
|
735
|
+
|
|
736
|
+
for obj in objects:
|
|
737
|
+
identifier = obj.get("Id")
|
|
738
|
+
if identifier is not None:
|
|
739
|
+
if identifier in seen_ids:
|
|
740
|
+
continue
|
|
741
|
+
seen_ids.add(identifier)
|
|
742
|
+
digital_objects.append(obj)
|
|
743
|
+
|
|
744
|
+
if not digital_objects:
|
|
745
|
+
return
|
|
746
|
+
|
|
747
|
+
target_key = DIGITAL_OBJECTS_KEY
|
|
748
|
+
|
|
749
|
+
for field in field_items:
|
|
750
|
+
if field.get('inputType') == DIGITAL_OBJECT_INPUT and field.get('displayName'):
|
|
751
|
+
target_key = field.get('displayName')
|
|
752
|
+
break
|
|
753
|
+
|
|
754
|
+
# A mapped field that already resolved to objects wins - the scan is
|
|
755
|
+
# only there to fill the gap when the metadata does not expose it.
|
|
756
|
+
existing = entry.get(target_key)
|
|
757
|
+
|
|
758
|
+
if isinstance(existing, list) and existing:
|
|
759
|
+
return
|
|
760
|
+
|
|
761
|
+
entry[target_key] = digital_objects
|
|
762
|
+
|
|
763
|
+
|
|
676
764
|
def __create_from_json_file(self, attribute: str, file_path: str):
|
|
677
765
|
"""Create a set of new entries from a file."""
|
|
678
766
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: das-cli
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.6
|
|
4
4
|
Summary: DAS api client.
|
|
5
5
|
Author: Royal Netherlands Institute for Sea Research
|
|
6
6
|
License-Expression: MIT
|
|
@@ -362,6 +362,20 @@ entry = entries.get(id="6b0e68e6-00cd-43a7-9c51-d56c9c091123")
|
|
|
362
362
|
entry = entries.get_entry("6b0e68e6-00cd-43a7-9c51-d56c9c091123")
|
|
363
363
|
```
|
|
364
364
|
|
|
365
|
+
When the entry has digital objects attached they are always included, even for
|
|
366
|
+
attributes whose entry-field metadata does not expose a digital-object field.
|
|
367
|
+
They land under the digital-object field's display name when there is one, and
|
|
368
|
+
under `"Digital Object(s)"` otherwise:
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
for obj in entry.get("Digital Object(s)", []):
|
|
372
|
+
print(obj["Id"], obj["Name"], obj["Type"], obj["Links"])
|
|
373
|
+
# 1715e27d-bc89-4f9c-8fdf-36ad2da333c6 zeynep.erdem.jpg Image 4d.b.cb
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
`das entry get` and `das search entry <id>` print the same objects as a block
|
|
377
|
+
below the field list (or inline in the payload with `--format json`).
|
|
378
|
+
|
|
365
379
|
#### `create` — create one or many entries
|
|
366
380
|
|
|
367
381
|
```python
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|