mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibredb: Add ability to create empty books in the database. Fixes #5504 (Improve bulk creation of empty book items)
This commit is contained in:
parent
421475f02a
commit
56e2918c13
@ -376,12 +376,35 @@ the directory related options below.
|
||||
help=_('Process directories recursively'))
|
||||
parser.add_option('-d', '--duplicates', action='store_true', default=False,
|
||||
help=_('Add books to database even if they already exist. Comparison is done based on book titles.'))
|
||||
parser.add_option('-e', '--empty', action='store_true', default=False,
|
||||
help=_('Add an empty book (a book with no formats)'))
|
||||
parser.add_option('-t', '--title', default=None,
|
||||
help=_('Set the title of the added empty book'))
|
||||
parser.add_option('-a', '--authors', default=None,
|
||||
help=_('Set the authors of the added empty book'))
|
||||
parser.add_option('-i', '--isbn', default=None,
|
||||
help=_('Set the ISBN of the added empty book'))
|
||||
|
||||
return parser
|
||||
|
||||
def do_add_empty(db, title, authors, isbn):
|
||||
from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
||||
mi = MetaInformation(None)
|
||||
if title is not None:
|
||||
mi.title = title
|
||||
if authors:
|
||||
mi.authors = string_to_authors(authors)
|
||||
if isbn:
|
||||
mi.isbn = isbn
|
||||
db.import_book(mi, [])
|
||||
send_message()
|
||||
|
||||
def command_add(args, dbpath):
|
||||
parser = add_option_parser()
|
||||
opts, args = parser.parse_args(sys.argv[:1] + args)
|
||||
if opts.empty:
|
||||
do_add_empty(get_db(dbpath, opts), opts.title, opts.authors, opts.isbn)
|
||||
return 0
|
||||
if len(args) < 2:
|
||||
parser.print_help()
|
||||
print
|
||||
|
Loading…
x
Reference in New Issue
Block a user