def _delete_entity_type_data(args): if args.force or (not args.force and mcmd.io.ask.confirm( 'Are you sure you want to delete all data in entity type {}?'. format(args.resource))): io.start('Deleting all data from entity {}'.format( highlight(args.resource))) client.delete(api.rest1(args.resource))
def set_(args): """ set sets the specified row of the specified table (or setting of specified settings table) to the specified value :param args: command line arguments containing: the settings type, the setting to set, and the value to set it to, if not a setting also the --for (which row to alter) if --from-path or --from-resource is passed the value is assumed to be a file containing the value data to be set :return: None """ value = args.value value_desc = highlight(value) if args.from_path: path = Path(args.value) value = files.read_file(path) value_desc = 'contents of {}'.format(highlight(args.value)) elif args.from_resource: path = files.select_file_from_folders(context().get_resource_folders(), args.value) value = files.read_file(path) value_desc = 'contents of {}'.format(highlight(args.value)) if args.for_: entity = args.type row = args.for_ io.start('Updating {} of {} for id {} to {}'.format( highlight(args.attribute), highlight(args.type), highlight(args.for_), value_desc)) else: entity = _get_settings_entity(args.type) io.start('Updating {} of {} settings to {}'.format( highlight(args.attribute), highlight(args.type), value_desc)) row = _get_first_row_id(entity) url = api.rest1('{}/{}/{}'.format(entity, row, args.attribute)) put(url, json.dumps(value))
def add_package(args): io.start('Adding package %s' % highlight(args.id)) data = {'id': args.id, 'label': args.id} if args.parent: data['parent'] = args.parent post(api.rest1('sys_md_Package'), data=data)
def add_token(args): io.start('Adding token %s for user %s' % (highlight(args.token), highlight(args.user))) user = get(api.rest2('sys_sec_User'), params={ 'attrs': 'id', 'q': 'username=={}'.format(args.user) }) if user.json()['total'] == 0: raise McmdError('Unknown user %s' % args.user) user_id = user.json()['items'][0]['id'] data = {'User': user_id, 'token': args.token} post(api.rest1('sys_sec_Token'), data=data)
def add_user(args): io.start('Adding user %s' % highlight(args.username)) password = args.set_password if args.set_password else args.username email = args.with_email if args.with_email else args.username + '@molgenis.org' active = not args.is_inactive superuser = args.is_superuser ch_pwd = args.change_password post(api.rest1('sys_sec_User'), data={ 'username': args.username, 'password_': password, 'changePassword': ch_pwd, 'Email': email, 'active': active, 'superuser': superuser })
def set_(args): """ set sets the specified row of the specified table (or setting of specified settings table) to the specified value :param args: command line arguments containing: the settings type, the setting to set, and the value to set it to, if not a setting also the --for (which row to alter) :return: None """ if args.for_: entity = args.type row = args.for_ io.start('Updating {} of {} for id {} to {}'.format( highlight(args.attribute), highlight(args.type), highlight(args.for_), highlight(args.value))) else: entity = _get_settings_entity(args.type) io.start('Updating {} of {} settings to {}'.format( highlight(args.attribute), highlight(args.type), highlight(args.value))) row = _get_first_row_id(entity) url = api.rest1('{}/{}/{}'.format(entity, row, args.attribute)) put(url, json.dumps(args.value))
def disable_language(args): io.start('Disabling language {}'.format(highlight(args.language))) url = api.rest1('sys_Language/{}/active'.format(args.language)) put(url, 'false')