(self, params, **kwargs)
| 1162 | return shortcut_list_parser |
| 1163 | |
| 1164 | def execute(self, params, **kwargs): |
| 1165 | records = ShortcutCommand.get_record_shortcuts(params) |
| 1166 | target = kwargs.get('target') |
| 1167 | to_show = set() |
| 1168 | if target: |
| 1169 | if target in params.record_cache: # record UID |
| 1170 | if target not in records: |
| 1171 | raise CommandError('shortcut-get', f'Record UID {target} does not have shortcuts') |
| 1172 | to_show.add(target) |
| 1173 | |
| 1174 | elif target in params.folder_cache: # folder UID |
| 1175 | for record_uid in records: |
| 1176 | if target in records[record_uid]: |
| 1177 | to_show.add(record_uid) |
| 1178 | |
| 1179 | else: |
| 1180 | try: |
| 1181 | path = try_resolve_path( |
| 1182 | params, target, raise_on_ambiguous=True) |
| 1183 | except FolderPathAmbiguousError as e: |
| 1184 | raise CommandError('shortcut-list', str(e)) |
| 1185 | if path is None: |
| 1186 | raise CommandError('shortcut-list', 'Target path should be existing record or folder') |
| 1187 | folder, name = path |
| 1188 | if name: |
| 1189 | regex = re.compile(fnmatch.translate(name)).match |
| 1190 | folder_uid = folder.uid or '' |
| 1191 | if folder_uid in params.subfolder_record_cache: |
| 1192 | for record_uid in params.subfolder_record_cache[folder_uid]: |
| 1193 | if record_uid == name: |
| 1194 | if record_uid in records: |
| 1195 | if folder_uid in records[record_uid]: |
| 1196 | to_show.add(record_uid) |
| 1197 | else: |
| 1198 | record = vault.KeeperRecord.load(params, record_uid) |
| 1199 | if isinstance(record, vault.PasswordRecord) or isinstance(record, vault.TypedRecord): |
| 1200 | if regex(record.title): |
| 1201 | if record_uid in records: |
| 1202 | if folder_uid in records[record_uid]: |
| 1203 | to_show.add(record_uid) |
| 1204 | else: |
| 1205 | folder_uid = folder.uid or '' |
| 1206 | if folder_uid in params.subfolder_record_cache: |
| 1207 | for record_uid in params.subfolder_record_cache[folder_uid]: |
| 1208 | if record_uid in records: |
| 1209 | if folder_uid in records[record_uid]: |
| 1210 | to_show.add(record_uid) |
| 1211 | else: |
| 1212 | logging.info('Displaying all shortcuts') |
| 1213 | to_show.update(records.keys()) |
| 1214 | |
| 1215 | table = [] |
| 1216 | json_headers = ['record_uid', 'record_title', 'folder'] |
| 1217 | headers = ['Record UID', 'Record Title', 'Folder'] |
| 1218 | fmt = kwargs.get('format') |
| 1219 | for record_uid in to_show: |
| 1220 | record = vault.KeeperRecord.load(params, record_uid) |
| 1221 | if record: |
nothing calls this directly
no test coverage detected