From db71dde384d3d90116fde9bd2e7294c596225773 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 8 Nov 2012 14:29:55 +0530 Subject: [PATCH] calibredb: Add an option to not notify the GUI --- src/calibre/library/cli.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/cli.py b/src/calibre/library/cli.py index 10265dd773..3993244215 100644 --- a/src/calibre/library/cli.py +++ b/src/calibre/library/cli.py @@ -23,13 +23,16 @@ FIELDS = set(['title', 'authors', 'author_sort', 'publisher', 'rating', 'formats', 'isbn', 'uuid', 'pubdate', 'cover', 'last_modified', 'identifiers']) +do_notify = True def send_message(msg=''): + global do_notify + if not do_notify: + return prints('Notifying calibre of the change') from calibre.utils.ipc import RC - import time t = RC(print_error=False) t.start() - time.sleep(3) + t.join(3) if t.done: t.conn.send('refreshdb:'+msg) t.conn.close() @@ -42,16 +45,22 @@ def get_parser(usage): parser = OptionParser(usage) go = parser.add_option_group(_('GLOBAL OPTIONS')) go.add_option('--library-path', '--with-library', default=None, help=_('Path to the calibre library. Default is to use the path stored in the settings.')) + go.add_option('--dont-notify-gui', default=False, action='store_true', + help=_('Do not notify the running calibre GUI (if any) that the database has' + ' changed. Use with care, as it can lead to database corruption!')) return parser def get_db(dbpath, options): + global do_notify if options.library_path is not None: dbpath = options.library_path if dbpath is None: raise ValueError('No saved library path, either run the GUI or use the' ' --with-library option') dbpath = os.path.abspath(dbpath) + if options.dont_notify_gui: + do_notify = False return LibraryDatabase2(dbpath) def do_list(db, fields, afields, sort_by, ascending, search_text, line_width, separator,