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

4dn-dcic / dcicwrangling / 8545209979

03 Apr 2024 08:37PM UTC coverage: 33.718% (+1.6%) from 32.1%
8545209979

push

github

web-flow
Merge pull request #113 from 4dn-dcic/ajs_add_del_script

New property or item status change script

81 of 95 new or added lines in 3 files covered. (85.26%)

8 existing lines in 8 files now uncovered.

1256 of 3725 relevant lines covered (33.72%)

1.35 hits per line

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

0.0
/scripts/patch_field_for_many_items.py
1
import sys
×
2
import argparse
×
NEW
3
from dcicutils.ff_utils import patch_metadata, delete_field
×
4
from functions import script_utils as scu
×
5

6

7
def get_args(args):
×
8
    parser = argparse.ArgumentParser(
×
9
        parents=[scu.create_input_arg_parser(), scu.create_ff_arg_parser()],
10
        formatter_class=argparse.RawDescriptionHelpFormatter,
11
    )
12
    parser.add_argument('field',
×
13
                        help="The field to update.")
14
    parser.add_argument('value',
×
15
                        help="The value(s) to update. Array fields need \"''\" surround \
16
                        even if only a single value i.e. \"'value here'\" or \"'v1' 'v2'\" \
17
                        NOTE: can delete field by passing val *delete*")
UNCOV
18
    parser.add_argument('--isarray',
×
19
                        default=False,
20
                        action='store_true',
21
                        help="Field is an array.  Default is False \
22
                        use this so value is correctly formatted even if only a single value")
23
    parser.add_argument('--numtype',
×
24
                        help="options: 'i' or 'f' If the field value is integer or number deal accordingly")
25
    args = parser.parse_args(args)
×
26
    return args
×
27

28

29
def main():
×
30
    args = get_args(sys.argv[1:])
×
31
    auth = scu.authenticate(key=args.key, keyfile=args.keyfile, env=args.env)
×
32
    print("Working on {}".format(auth.get('server')))
×
33
    itemids = scu.get_item_ids_from_args(args.input, auth, args.search)
×
34
    field = args.field
×
35
    val = args.value
×
36
    if val == 'True':
×
37
        val = True
×
38
    elif val == 'False':
×
39
        val = False
×
40
    if args.isarray:
×
41
        val = [v for v in val.split("'") if v]
×
42
    ntype = args.numtype
×
43
    if ntype:
×
44
        if ntype == 'i':
×
45
            val = int(val)
×
46
        elif ntype == 'f':
×
47
            val = float(val)
×
48
    for iid in itemids:
×
49
        print("PATCHING", iid, "to", field, "=", val)
×
50
        if (args.dbupdate):
×
51
            # do the patch
52
            if val == '*delete*':
×
53
                res = delete_field(iid, field, auth)
×
54
            else:
55
                res = patch_metadata({args.field: val}, iid, auth)
×
56
            if res['status'] == 'success':
×
57
                print("SUCCESS!")
×
58
            else:
59
                print("FAILED TO PATCH", iid, "RESPONSE STATUS", res['status'], res['description'])
×
60
                # print(res)
61

62

63
if __name__ == '__main__':  # pragma:nocover
64
    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