def main(args=sys.argv): opts, args = create_option_parser().parse_args(args) libraries = args[1:] for lib in libraries: if not lib or not LibraryDatabase.exists_at(lib): raise SystemExit(_('There is no calibre library at: %s') % lib) if not libraries: if not prefs['library_path']: raise SystemExit(_('You must specify at least one calibre library')) libraries = [prefs['library_path']] if opts.auto_reload: if opts.daemonize: raise SystemExit('Cannot specify --auto-reload and --daemonize at the same time') from calibre.srv.auto_reload import auto_reload, NoAutoReload try: from calibre.utils.logging import default_log return auto_reload(default_log) except NoAutoReload as e: raise SystemExit(e.message) server = Server(libraries, opts) if opts.daemonize: if not opts.log and not iswindows: raise SystemExit('In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon') daemonize() if opts.pidfile: with lopen(opts.pidfile, 'wb') as f: f.write(str(os.getpid())) signal.signal(signal.SIGTERM, lambda s,f: server.stop()) if not opts.daemonize and not iswindows: signal.signal(signal.SIGHUP, lambda s,f: server.stop()) server.serve_forever()
def __init__(self, libraries): self.lock = Lock() self.lmap = OrderedDict() self.library_name_map = {} self.original_path_map = {} seen = set() for original_path in libraries: path = canonicalize_path(original_path) if path in seen: continue is_samefile = False for s in seen: if samefile(s, path): is_samefile = True break seen.add(path) if is_samefile or not LibraryDatabase.exists_at(path): continue corrected_path = correct_case_of_last_path_component(original_path) library_id = library_id_from_path(corrected_path, self.lmap) self.lmap[library_id] = path self.library_name_map[library_id] = basename(corrected_path) self.original_path_map[path] = original_path self.loaded_dbs = {} self.category_caches, self.search_caches, self.tag_browser_caches = ( defaultdict(OrderedDict), defaultdict(OrderedDict), defaultdict(OrderedDict))
def __init__(self, libraries): self.lock = Lock() self.lmap = OrderedDict() self.library_name_map = {} self.original_path_map = {} seen = set() for original_path in libraries: path = canonicalize_path(original_path) if path in seen: continue is_samefile = False for s in seen: if samefile(s, path): is_samefile = True break seen.add(path) if is_samefile or not LibraryDatabase.exists_at(path): continue library_id = library_id_from_path(original_path, self.lmap) self.lmap[library_id] = path self.library_name_map[library_id] = basename(original_path) self.original_path_map[path] = original_path self.loaded_dbs = {} self.category_caches, self.search_caches, self.tag_browser_caches = ( defaultdict(OrderedDict), defaultdict(OrderedDict), defaultdict(OrderedDict))
def main(args=sys.argv): opts, args = create_option_parser().parse_args(args) if opts.auto_reload: if getattr(opts, 'daemonize', False): raise SystemExit( 'Cannot specify --auto-reload and --daemonize at the same time') from calibre.srv.auto_reload import auto_reload, NoAutoReload try: from calibre.utils.logging import default_log return auto_reload(default_log, listen_on=opts.listen_on) except NoAutoReload as e: raise SystemExit(error_message(e)) ensure_single_instance() if opts.userdb: opts.userdb = os.path.abspath(os.path.expandvars(os.path.expanduser(opts.userdb))) connect(opts.userdb, exc_class=SystemExit).close() if opts.manage_users: try: manage_users_cli(opts.userdb) except (KeyboardInterrupt, EOFError): raise SystemExit(_('Interrupted by user')) raise SystemExit(0) libraries = args[1:] for lib in libraries: if not lib or not LibraryDatabase.exists_at(lib): raise SystemExit(_('There is no calibre library at: %s') % lib) libraries = libraries or load_gui_libraries() if not libraries: if not prefs['library_path']: raise SystemExit(_('You must specify at least one calibre library')) libraries = [prefs['library_path']] opts.auto_reload_port = int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0)) opts.allow_console_print = 'CALIBRE_ALLOW_CONSOLE_PRINT' in os.environ if opts.log and os.path.isdir(opts.log): raise SystemExit('The --log option must point to a file, not a directory') if opts.access_log and os.path.isdir(opts.access_log): raise SystemExit('The --access-log option must point to a file, not a directory') server = Server(libraries, opts) if getattr(opts, 'daemonize', False): if not opts.log and not iswindows: raise SystemExit( 'In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon' ) daemonize() if opts.pidfile: with lopen(opts.pidfile, 'wb') as f: f.write(unicode_type(os.getpid()).encode('ascii')) signal.signal(signal.SIGTERM, lambda s, f: server.stop()) if not getattr(opts, 'daemonize', False) and not iswindows: signal.signal(signal.SIGHUP, lambda s, f: server.stop()) # Needed for dynamic cover generation, which uses Qt for drawing from calibre.gui2 import ensure_app, load_builtin_fonts ensure_app(), load_builtin_fonts() try: server.serve_forever() finally: shutdown_delete_service()
def main(args=sys.argv): opts, args = create_option_parser().parse_args(args) ensure_single_instance() if opts.userdb: opts.userdb = os.path.abspath(os.path.expandvars(os.path.expanduser(opts.userdb))) connect(opts.userdb, exc_class=SystemExit).close() if opts.manage_users: try: manage_users_cli(opts.userdb) except (KeyboardInterrupt, EOFError): raise SystemExit(_('Interrupted by user')) raise SystemExit(0) libraries = args[1:] for lib in libraries: if not lib or not LibraryDatabase.exists_at(lib): raise SystemExit(_('There is no calibre library at: %s') % lib) libraries = libraries or load_gui_libraries() if not libraries: if not prefs['library_path']: raise SystemExit(_('You must specify at least one calibre library')) libraries = [prefs['library_path']] if opts.auto_reload: if getattr(opts, 'daemonize', False): raise SystemExit( 'Cannot specify --auto-reload and --daemonize at the same time') from calibre.srv.auto_reload import auto_reload, NoAutoReload try: from calibre.utils.logging import default_log return auto_reload(default_log, listen_on=opts.listen_on) except NoAutoReload as e: raise SystemExit(e.message) opts.auto_reload_port = int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0)) opts.allow_console_print = 'CALIBRE_ALLOW_CONSOLE_PRINT' in os.environ if opts.log and os.path.isdir(opts.log): raise SystemExit('The --log option must point to a file, not a directory') if opts.access_log and os.path.isdir(opts.access_log): raise SystemExit('The --access-log option must point to a file, not a directory') server = Server(libraries, opts) if getattr(opts, 'daemonize', False): if not opts.log and not iswindows: raise SystemExit( 'In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon' ) daemonize() if opts.pidfile: with lopen(opts.pidfile, 'wb') as f: f.write(str(os.getpid())) signal.signal(signal.SIGTERM, lambda s, f: server.stop()) if not getattr(opts, 'daemonize', False) and not iswindows: signal.signal(signal.SIGHUP, lambda s, f: server.stop()) # Needed for dynamic cover generation, which uses Qt for drawing from calibre.gui2 import ensure_app, load_builtin_fonts ensure_app(), load_builtin_fonts() try: server.serve_forever() finally: shutdown_delete_service()
def __init__(self, libraries): self.lock = Lock() self.lmap = {} for path in libraries: if not LibraryDatabase.exists_at(path): continue library_id = base = force_unicode(os.path.basename(path)) c = 0 while library_id in self.lmap: c += 1 library_id = base + ' (1)' if path is libraries[0]: self.default_library = library_id self.lmap[library_id] = path
def main(args=sys.argv): opts, args = create_option_parser().parse_args(args) if opts.manage_users: try: manage_users(opts.userdb) except (KeyboardInterrupt, EOFError): raise SystemExit(_('Interrupted by user')) raise SystemExit(0) libraries = args[1:] for lib in libraries: if not lib or not LibraryDatabase.exists_at(lib): raise SystemExit(_('There is no calibre library at: %s') % lib) if not libraries: if not prefs['library_path']: raise SystemExit( _('You must specify at least one calibre library')) libraries = [prefs['library_path']] if opts.auto_reload: if opts.daemonize: raise SystemExit( 'Cannot specify --auto-reload and --daemonize at the same time' ) from calibre.srv.auto_reload import auto_reload, NoAutoReload try: from calibre.utils.logging import default_log return auto_reload(default_log) except NoAutoReload as e: raise SystemExit(e.message) opts.auto_reload_port = int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0)) server = Server(libraries, opts) if opts.daemonize: if not opts.log and not iswindows: raise SystemExit( 'In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon' ) daemonize() if opts.pidfile: with lopen(opts.pidfile, 'wb') as f: f.write(str(os.getpid())) signal.signal(signal.SIGTERM, lambda s, f: server.stop()) if not opts.daemonize and not iswindows: signal.signal(signal.SIGHUP, lambda s, f: server.stop()) # Needed for dynamic cover generation, which uses Qt for drawing from calibre.gui2 import ensure_app, load_builtin_fonts ensure_app(), load_builtin_fonts() server.serve_forever()
def main(args=sys.argv): opts, args = create_option_parser().parse_args(args) if opts.manage_users: try: manage_users(opts.userdb) except (KeyboardInterrupt, EOFError): raise SystemExit(_("Interrupted by user")) raise SystemExit(0) libraries = args[1:] for lib in libraries: if not lib or not LibraryDatabase.exists_at(lib): raise SystemExit(_("There is no calibre library at: %s") % lib) if not libraries: if not prefs["library_path"]: raise SystemExit(_("You must specify at least one calibre library")) libraries = [prefs["library_path"]] if opts.auto_reload: if opts.daemonize: raise SystemExit("Cannot specify --auto-reload and --daemonize at the same time") from calibre.srv.auto_reload import auto_reload, NoAutoReload try: from calibre.utils.logging import default_log return auto_reload(default_log) except NoAutoReload as e: raise SystemExit(e.message) opts.auto_reload_port = int(os.environ.get("CALIBRE_AUTORELOAD_PORT", 0)) try: server = Server(libraries, opts) except InvalidCredentials as e: raise SystemExit(e.message) if opts.daemonize: if not opts.log and not iswindows: raise SystemExit( "In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon" ) daemonize() if opts.pidfile: with lopen(opts.pidfile, "wb") as f: f.write(str(os.getpid())) signal.signal(signal.SIGTERM, lambda s, f: server.stop()) if not opts.daemonize and not iswindows: signal.signal(signal.SIGHUP, lambda s, f: server.stop()) server.serve_forever()
def main(args=sys.argv): opts, args=create_option_parser().parse_args(args) if opts.manage_users: try: manage_users(opts.userdb) except (KeyboardInterrupt, EOFError): raise SystemExit(_('Interrupted by user')) raise SystemExit(0) libraries=args[1:] for lib in libraries: if not lib or not LibraryDatabase.exists_at(lib): raise SystemExit(_('There is no calibre library at: %s') % lib) if not libraries: if not prefs['library_path']: raise SystemExit(_('You must specify at least one calibre library')) libraries=[prefs['library_path']] if opts.auto_reload: if opts.daemonize: raise SystemExit('Cannot specify --auto-reload and --daemonize at the same time') from calibre.srv.auto_reload import auto_reload, NoAutoReload try: from calibre.utils.logging import default_log return auto_reload(default_log, listen_on=opts.listen_on) except NoAutoReload as e: raise SystemExit(e.message) opts.auto_reload_port=int(os.environ.get('CALIBRE_AUTORELOAD_PORT', 0)) opts.allow_console_print = 'CALIBRE_ALLOW_CONSOLE_PRINT' in os.environ server=Server(libraries, opts) if opts.daemonize: if not opts.log and not iswindows: raise SystemExit('In order to daemonize you must specify a log file, you can use /dev/stdout to log to screen even as a daemon') daemonize() if opts.pidfile: with lopen(opts.pidfile, 'wb') as f: f.write(str(os.getpid())) signal.signal(signal.SIGTERM, lambda s,f: server.stop()) if not opts.daemonize and not iswindows: signal.signal(signal.SIGHUP, lambda s,f: server.stop()) # Needed for dynamic cover generation, which uses Qt for drawing from calibre.gui2 import ensure_app, load_builtin_fonts ensure_app(), load_builtin_fonts() server.serve_forever()
def __init__(self, libraries): self.lock = Lock() self.lmap = {} seen = set() for i, path in enumerate(os.path.abspath(p) for p in libraries): if path in seen: continue seen.add(path) if not LibraryDatabase.exists_at(path): continue bname = library_id = hexlify(os.path.basename(path).encode('utf-8')).decode('ascii') c = 0 while library_id in self.lmap: c += 1 library_id = bname + '%d' % c if i == 0: self.default_library = library_id self.lmap[library_id] = path self.category_caches = {lid:OrderedDict() for lid in self.lmap} self.search_caches = {lid:OrderedDict() for lid in self.lmap}
def __init__(self, libraries): self.lock = Lock() self.lmap = {} seen = set() for i, path in enumerate(os.path.abspath(p) for p in libraries): if path in seen: continue seen.add(path) if not LibraryDatabase.exists_at(path): continue bname = library_id = force_unicode(os.path.basename(path), filesystem_encoding).replace(' ', '_') c = 0 while library_id in self.lmap: c += 1 library_id = bname + '%d' % c if i == 0: self.default_library = library_id self.lmap[library_id] = path self.category_caches = {lid:OrderedDict() for lid in self.lmap} self.search_caches = {lid:OrderedDict() for lid in self.lmap} self.tag_browser_caches = {lid:OrderedDict() for lid in self.lmap}
def __init__(self, libraries): self.lock = Lock() self.lmap = {} seen = set() for i, path in enumerate(os.path.abspath(p) for p in libraries): if path in seen: continue seen.add(path) if not LibraryDatabase.exists_at(path): continue bname = library_id = force_unicode(os.path.basename(path), filesystem_encoding) c = 0 while library_id in self.lmap: c += 1 library_id = bname + '%d' % c if i == 0: self.default_library = library_id self.lmap[library_id] = path self.category_caches = {lid: OrderedDict() for lid in self.lmap} self.search_caches = {lid: OrderedDict() for lid in self.lmap} self.tag_browser_caches = {lid: OrderedDict() for lid in self.lmap}
def main(opts, args, dbctx): if opts.report is None: checks = CHECKS else: checks = [] for r in opts.report.split(','): found = False for c in CHECKS: if c[0] == r: checks.append(c) found = True break if not found: prints(_('Unknown report check'), r) return 1 if opts.names is None: names = [] else: names = [f.strip() for f in opts.names.split(',') if f.strip()] if opts.exts is None: exts = [] else: exts = [f.strip() for f in opts.exts.split(',') if f.strip()] if not LibraryDatabase.exists_at(dbctx.library_path): prints('No library found at', dbctx.library_path, file=sys.stderr) raise SystemExit(1) db = LibraryDatabase(dbctx.library_path) prints(_('Vacuuming database...')) db.new_api.vacuum() checker = CheckLibrary(dbctx.library_path, db) checker.scan_library(names, exts) for check in checks: _print_check_library_results(checker, check, as_csv=opts.csv) return 0
def is_library_dir_suitable(self, x): from calibre.db.legacy import LibraryDatabase try: return LibraryDatabase.exists_at(x) or not os.listdir(x) except: return False
def is_library_dir_suitable(self, x): try: return LibraryDatabase.exists_at(x) or not os.listdir(x) except: return False