def cdb_run(ctx, rd, which, version): try: m = module_for_cmd(which) except ImportError: raise HTTPNotFound('No module named: {}'.format(which)) if not getattr(m, 'readonly', False): ctx.check_for_write_access(rd) if getattr(m, 'version', 0) != int(version): raise HTTPNotFound(('The module {} is not available in version: {}.' 'Make sure the version of calibre used for the' ' server and calibredb match').format(which, version)) db = get_library_data(ctx, rd, strict_library_id=True)[0] if ctx.restriction_for(rd, db): raise HTTPForbidden('Cannot use the command-line db interface with a user who has per library restrictions') raw = rd.read() ct = rd.inheaders.get('Content-Type', all=True) try: if MSGPACK_MIME in ct: args = msgpack_loads(raw) elif 'application/json' in ct: args = json_loads(raw) else: raise HTTPBadRequest('Only JSON or msgpack requests are supported') except Exception: raise HTTPBadRequest('args are not valid encoded data') if getattr(m, 'needs_srv_ctx', False): args = [ctx] + list(args) try: result = m.implementation(db, partial(ctx.notify_changes, db.backend.library_path), *args) except Exception as err: import traceback return {'err': as_unicode(err), 'tb': traceback.format_exc()} return {'result': result}
def run_cmd(cmd, opts, args, dbctx): m = module_for_cmd(cmd) if dbctx.is_remote and getattr(m, 'no_remote', False): raise SystemExit(_('The {} command is not supported with remote (server based) libraries').format(cmd)) 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
def run_cmd(cmd, opts, args, dbctx): m = module_for_cmd(cmd) if dbctx.is_remote and getattr(m, 'no_remote', False): raise SystemExit( _('The {} command is not supported with remote (server based) libraries' ).format(cmd)) ret = m.main(opts, args, dbctx) return ret
def run_cmd(cmd, opts, args, dbctx): m = module_for_cmd(cmd) if dbctx.is_remote and getattr(m, 'no_remote', False): raise SystemExit( _('The {} command is not supported with remote (server based) libraries' ).format(cmd)) 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
def cmd_option_parser(): return module_for_cmd(cmd).option_parser(get_parser, args)
def run(self, name, *args): m = module_for_cmd(name) if self.is_remote: return self.remote_run(name, m, *args) return m.implementation(self.db.new_api, None, *args)