mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Fix #1401085 ['calibredb list --for-machine' ignores custom columns](https://bugs.launchpad.net/calibre/+bug/1401085)
This commit is contained in:
parent
3feee82566
commit
a82cf81975
@ -90,17 +90,21 @@ def do_list(db, fields, afields, sort_by, ascending, search_text, line_width, se
|
|||||||
return ans
|
return ans
|
||||||
if for_machine:
|
if for_machine:
|
||||||
import json
|
import json
|
||||||
|
record_keys = {field_name(field):field for field in fields}
|
||||||
for record in data:
|
for record in data:
|
||||||
for key in set(record) - set(fields):
|
for key in set(record) - set(record_keys):
|
||||||
del record[key]
|
del record[key]
|
||||||
|
for key in tuple(record):
|
||||||
|
if record_keys[key] != key: # A custom column, use the column label as the key rather than the column id number
|
||||||
|
record[record_keys[key]] = record.pop(key)
|
||||||
for key, val in tuple(record.iteritems()):
|
for key, val in tuple(record.iteritems()):
|
||||||
if hasattr(val, 'isoformat'):
|
if hasattr(val, 'isoformat'):
|
||||||
record[key] = isoformat(val, as_utc=True)
|
record[key] = isoformat(val, as_utc=True)
|
||||||
elif val is None:
|
elif val is None:
|
||||||
del record[key]
|
del record[key]
|
||||||
return json.dumps(data, indent=2, sort_keys=True)
|
return json.dumps(data, indent=2, sort_keys=True)
|
||||||
fields = list(map(field_name, fields))
|
|
||||||
|
|
||||||
|
fields = list(map(field_name, fields))
|
||||||
for f in data:
|
for f in data:
|
||||||
fmts = [x for x in f['formats'] if x is not None]
|
fmts = [x for x in f['formats'] if x is not None]
|
||||||
f['formats'] = u'[%s]'%u', '.join(fmts)
|
f['formats'] = u'[%s]'%u', '.join(fmts)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user