19070: Still trying to fix test_with_arvbox
[arvados.git] / doc / _includes / _admin_set_property_to_collections_under_project_py.liquid
1 #!/usr/bin/env python3
2 {% comment %}
3 Copyright (C) The Arvados Authors. All rights reserved.
4
5 SPDX-License-Identifier: CC-BY-SA-3.0
6 {% endcomment %}
7 import arvados
8 import arvados.util as util
9
10 def get_subproject_uuids(api, root_uuid):
11     uuids = []
12     groups = util.list_all(api.groups().list, filters=[['owner_uuid', '=', '{}'.format(root_uuid)]], select=['uuid'])
13     for g in groups:
14         uuids += ([g['uuid']] + get_subproject_uuids(api, g['uuid']))
15     return uuids
16
17 def get_cols(api, filters):
18     cols = util.list_all(api.collections().list, filters=filters, select=['uuid', 'properties'])
19     return cols
20
21 # Search for collections on project hierarchy rooted at root_uuid
22 root_uuid = 'zzzzz-j7d0g-ppppppppppppppp'
23 # Set the property to the UUID below
24 responsible_uuid = 'zzzzz-tpzed-xxxxxxxxxxxxxxx'
25
26 api = arvados.api()
27 for p_uuid in [root_uuid] + get_subproject_uuids(api, root_uuid):
28     f = [['properties.responsible_person_uuid', 'exists', False],
29          ['owner_uuid', '=', p_uuid]]
30     cols = get_cols(api, f)
31     print('Found {} collections owned by {}'.format(len(cols), p_uuid))
32     for c in cols:
33         print(' - Updating collection {}'.format(c['uuid']))
34         props = c['properties']
35         props['responsible_person_uuid'] = responsible_uuid
36         api.collections().update(uuid=c['uuid'], body={'properties': props}).execute()