Fix 'list --json-lines' command when only a single result line is output. By @rblenis (#910)

This commit is contained in:
Robert Blenis 2021-03-12 09:47:11 -05:00 committed by GitHub
parent 2b009c517f
commit 08797aba77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -18,12 +18,10 @@ class ExtractDialog(ExtractDialogBase, ExtractDialogUI):
super().__init__()
self.setupUi(self)
files_with_attributes = []
nested_file_list = nested_dict()
self.selected = set()
def parse_json_line(line):
data = json.loads(line)
def parse_json_line(data):
size = data["size"]
# python >= 3.7
# modified = datetime.fromisoformat(data["mtime"]).ctime()
@ -39,11 +37,11 @@ class ExtractDialog(ExtractDialogBase, ExtractDialogUI):
d[name] = {}
return size, modified, name, dirpath
for line in fs_data.split("\n"):
try:
files_with_attributes.append(parse_json_line(line))
except ValueError:
pass
# handle case of a single line of result, which will already be a dict
lines = [fs_data] if isinstance(fs_data, dict) else \
[json.loads(line) for line in fs_data.split('\n') if line]
files_with_attributes = [parse_json_line(line) for line in lines]
model = ExtractTree(files_with_attributes, nested_file_list, self.selected)