record remove: remove by Record UID
@@ -120,6 +120,7 @@ edit_parser.exit = suppress_exit
rm_parser = argparse.ArgumentParser(prog='rm', description='Remove record')
+rm_parser.add_argument('--purge', dest='purge', action='store_true', help='remove owned record from all folders')
rm_parser.add_argument('-f', '--force', dest='force', action='store_true', help='do not prompt')
rm_parser.add_argument('record', nargs='?', type=str, action='store', help='record path or UID')
rm_parser.error = raise_parse_exception
@@ -448,7 +449,6 @@ class RecordRemoveCommand(Command):
if name in params.record_cache:
record_uid = name
folders = list(find_folders(params, record_uid))
- #TODO support multiple folders
if len(folders) > 0:
folder = params.folder_cache[folders[0]] if len(folders[0]) > 0 else params.root_folder
else:
@@ -463,6 +463,32 @@ class RecordRemoveCommand(Command):
if record_uid is None:
raise CommandError('rm', 'Enter name of existing record')
+ if kwargs.get('purge'):
+ is_owner = False
+ if record_uid in params.meta_data_cache:
+ md = params.meta_data_cache[record_uid]
+ is_owner = md.get('owner') or False
+ if not is_owner:
+ logging.warning('Record purge error: Not an owner')
+ return
+
+ rq = {
+ 'command': 'record_update',
+ 'pt': 'Commander',
+ 'device_id': 'Commander',
+ 'client_time': api.current_milli_time(),
+ 'delete_records': [record_uid]
+ }
+ if not kwargs.get('force'):
+ answer = user_choice('Do you want to proceed with record purge?', 'yn', default='n')
+ if answer.lower() != 'y':
+ return
+ rs = api.communicate(params, rq)
+ if 'delete_records' in rs:
+ for status in rs['delete_records']:
+ if status['status'] != 'success':
+ logging.warning('Record purge error: %s', status.get('status'))
+ else:
del_obj = {
'delete_resolution': 'unlink',
'object_uid': record_uid,
