• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

4dn-dcic / dcicwrangling / 8573091028

05 Apr 2024 04:49PM UTC coverage: 33.709% (-0.009%) from 33.718%
8573091028

push

github

aschroed
hotfix bugfix to support testing

0 of 1 new or added line in 1 file covered. (0.0%)

1256 of 3726 relevant lines covered (33.71%)

1.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/scripts/delete_item_or_fields.py
1
#!/usr/bin/env python3
2
'''
×
3
Given a list of item IDs or search result will:
4
    1. given one of more values in the '--fields' options delete those fields from the item
5
    2. if no fields option then set the status of the item(s) to deleted
6
Useful for deleting multiple fields or changing item status to deleted
7
NOTE: can use patch_field_for_many_items script to delete a single field for many items
8
but this script is more direct/flexible in some ways
9
'''
NEW
10
import sys
×
11
import argparse
×
12
from dcicutils.ff_utils import get_metadata, delete_metadata, delete_field
×
13
from functions import script_utils as scu
×
14

15

16
def get_args(args):
×
17
    parser = argparse.ArgumentParser(
×
18
        parents=[scu.create_input_arg_parser(), scu.create_ff_arg_parser()],
19
        formatter_class=argparse.RawDescriptionHelpFormatter,
20
    )
21
    parser.add_argument('--fields',
×
22
                        nargs='+',
23
                        help="With this option these fields will be removed from the items.")
24
    args = parser.parse_args(args)
×
25
    return args
×
26

27

28
def main():  # pragma: no cover
29
    args = get_args(sys.argv[1:])
30
    auth = scu.authenticate(key=args.key, keyfile=args.keyfile, env=args.env)
31
    dry_run = True
32
    if args.dbupdate:
33
        dry_run = False
34

35
    print('#', auth.get('server'))
36
    id_list = scu.get_item_ids_from_args(args.input, auth, args.search)
37
    del_flds = None
38
    if args.fields:
39
        fields = args.fields
40
        del_flds = ','.join(fields)
41
    problems = []
42
    for iid in id_list:
43
        try:
44
            get_metadata(iid, auth, add_on='frame=object')
45
        except Exception:
46
            problems.append(iid)
47
            continue
48

49
        if del_flds:
50
            # we have field(s) that we want to delete from provided items
51
            print(f"Will delete {del_flds} from {iid}")
52
            if dry_run:
53
                print("DRY RUN")
54
            else:
55
                try:
56
                    res = delete_field(iid, del_flds, auth)
57
                    status = res.get('status')
58
                    if status.lower() == 'success':
59
                        print(status)
60
                    else:
61
                        print(res)
62
                        problems.append(iid)
63
                except Exception as e:
64
                    print(f"PROBLEM: {e}")
65
                    problems.append(iid)
66
        else:
67
            # we want to set the status of the items in id_list to deleted
68
            print(f"Will set status of {iid} to DELETED")
69
            if dry_run:
70
                print("DRY RUN")
71
            else:
72
                try:
73
                    res = delete_metadata(iid, auth)
74
                    status = res.get('status')
75
                    if status.lower() == 'success':
76
                        print(status)
77
                    else:
78
                        print(res)
79
                        problems.append(iid)
80
                except Exception as e:
81
                    print(f"PROBLEM: {e}")
82
                    problems.append(iid)
83

84
    if problems:
85
        print('THERE WAS A PROBLEM DELETING METADATA FOR THE FOLLOWING:')
86
        for p in problems:
87
            print(p)
88

89

90
if __name__ == '__main__':
×
91
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc