Skip to content

Commit

Permalink
fixed a few ia md --remove bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjake committed Feb 11, 2021
1 parent f9cbcb2 commit 55431a5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
Release History
---------------

2.0.0 (?)
+++++++++

**Bugfixes**

- Fixed bug in ``ia metadata --remove ...`` where multiple collections would be removed
if the specified collection was a substring of any of the existing collections.
- Fixed bug in ``ia metadata --remove ...`` where removing multiple collections was sometimes
not supported.

1.9.9 (2021-01-27)
++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion internetarchive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from __future__ import absolute_import

__title__ = 'internetarchive'
__version__ = '1.9.9'
__version__ = '2.0.0.dev1'
__author__ = 'Jacob M. Johnson'
__license__ = 'AGPL 3'
__copyright__ = 'Copyright (C) 2012-2019 Internet Archive'
Expand Down
48 changes: 31 additions & 17 deletions internetarchive/cli/ia_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,31 @@ def remove_metadata(item, metadata, args):
print('{0}/metadata/{1} does not exist, skipping.'.format(
item.identifier, key), file=sys.stderr)
continue
elif key == 'collection' and metadata[key] not in src_md:
r = item.remove_from_simplelist(metadata[key], 'holdings')
j = r.json()
if j.get('success'):
print('{} - success: {} no longer in {}'.format(
item.identifier, item.identifier, metadata[key]))
sys.exit(0)
elif j.get('error', '').startswith('no row to delete for'):
print('{} - success: {} no longer in {}'.format(
item.identifier, item.identifier, metadata[key]))
sys.exit(0)
else:
print('{} - error: {}'.format(item.identifier, j.get('error')))
sys.exit()
elif not isinstance(src_md, list):

if key == 'collection':
_col = copy(metadata[key])
_src_md = copy(src_md)
if not isinstance(_col, list):
_col = [_col]
if not isinstance(_src_md, list):
_src_md = [_src_md]
for c in _col:
if c not in _src_md:
r = item.remove_from_simplelist(c, 'holdings')
j = r.json()
if j.get('success'):
print('{} - success: {} no longer in {}'.format(
item.identifier, item.identifier, c))
sys.exit(0)
elif j.get('error', '').startswith('no row to delete for'):
print('{} - success: {} no longer in {}'.format(
item.identifier, item.identifier, c))
sys.exit(0)
else:
print('{} - error: {}'.format(item.identifier, j.get('error')))
sys.exit(1)

if not isinstance(src_md, list):
if key == 'subject':
src_md = src_md.split(';')
elif key == 'collection':
Expand All @@ -133,8 +143,12 @@ def remove_metadata(item, metadata, args):
continue

for x in src_md:
if x not in metadata[key]:
md[key].append(x)
if isinstance(metadata[key], list):
if x not in metadata[key]:
md[key].append(x)
else:
if x != metadata[key]:
md[key].append(x)

if len(md[key]) == len(src_md):
del md[key]
Expand Down

0 comments on commit 55431a5

Please sign in to comment.