mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Framework for cdb change notifications
This commit is contained in:
parent
4df54f92f9
commit
530cb0d00a
@ -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'}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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()}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user