diff --git a/src/calibre/db/cli/cmd_list.py b/src/calibre/db/cli/cmd_list.py index 2cfee3589e..72e0262342 100644 --- a/src/calibre/db/cli/cmd_list.py +++ b/src/calibre/db/cli/cmd_list.py @@ -34,8 +34,9 @@ def cover(db, book_id): def implementation( - db, is_remote, fields, sort_by, ascending, search_text, limit + db, notify_changes, fields, sort_by, ascending, search_text, limit ): + is_remote = notify_changes is not None with db.safe_read_lock: fm = db.field_metadata afields = set(FIELDS) | {'id'} diff --git a/src/calibre/db/cli/main.py b/src/calibre/db/cli/main.py index 7646c6d8f1..dfba14d932 100644 --- a/src/calibre/db/cli/main.py +++ b/src/calibre/db/cli/main.py @@ -45,10 +45,10 @@ def send_message(msg=''): t.conn.close() -def run_cmd(cmd, opts, args, db_ctx): +def run_cmd(cmd, opts, args, dbctx): m = module_for_cmd(cmd) - ret = m.main(opts, args, db_ctx) - if not db_ctx.is_remote and not opts.dont_notify_gui and not getattr(m, 'readonly', False): + ret = m.main(opts, args, dbctx) + if not dbctx.is_remote and not opts.dont_notify_gui and not getattr(m, 'readonly', False): send_message() return ret @@ -171,6 +171,12 @@ class DBCtx(object): self._db = LibraryDatabase(self.library_path).new_api return self._db + def path(self, path): + if self.is_remote: + with lopen(path, 'rb') as f: + return f.read() + return path + def run(self, name, *args): m = module_for_cmd(name) if self.is_remote: diff --git a/src/calibre/srv/TODO b/src/calibre/srv/TODO index 8044f3535e..debb8649ea 100644 --- a/src/calibre/srv/TODO +++ b/src/calibre/srv/TODO @@ -1,4 +1,4 @@ -Rewrite calibredb to connect to running server +Wire up cdb notify_changes for the embeded server Prevent standalone and embedded servers from running simultaneously Prevent more than a single instance of the standalone server from running diff --git a/src/calibre/srv/cdb.py b/src/calibre/srv/cdb.py index 0c24d81405..6a1bd04e02 100644 --- a/src/calibre/srv/cdb.py +++ b/src/calibre/srv/cdb.py @@ -33,7 +33,7 @@ def cdb_run(ctx, rd, which): raise HTTPBadRequest('args are not valid encoded data') db = get_library_data(ctx, rd, strict_library_id=True)[0] try: - result = m.implementation(db, True, *args) + result = m.implementation(db, ctx.notify_changes, *args) except Exception as err: import traceback return {'err': as_unicode(err), 'tb':traceback.format_stack()} diff --git a/src/calibre/srv/handler.py b/src/calibre/srv/handler.py index c156619f6e..1795ef2d28 100644 --- a/src/calibre/srv/handler.py +++ b/src/calibre/srv/handler.py @@ -32,6 +32,7 @@ class Context(object): self.user_manager = UserManager(opts.userdb) self.ignored_fields = frozenset(filter(None, (x.strip() for x in (opts.ignored_fields or '').split(',')))) self.displayed_fields = frozenset(filter(None, (x.strip() for x in (opts.displayed_fields or '').split(',')))) + self.notify_changes = lambda *a: None def start_job(self, name, module, func, args=(), kwargs=None, job_done_callback=None, job_data=None): return self.jobs_manager.start_job(name, module, func, args, kwargs, job_done_callback, job_data)