diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py index 0097276348..57e5e702fa 100644 --- a/src/calibre/library/server/base.py +++ b/src/calibre/library/server/base.py @@ -57,13 +57,15 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache): server_name = __appname__ + '/' + __version__ - def __init__(self, db, opts, embedded=False, show_tracebacks=True): + def __init__(self, db, opts, embedded=False, show_tracebacks=True, + ignore_search_restriction=True): self.db = db for item in self.db: item break self.opts = opts self.embedded = embedded + self.ignore_search_restriction=ignore_search_restriction self.state_callback = None self.max_cover_width, self.max_cover_height = \ map(int, self.opts.max_cover.split('x')) diff --git a/src/calibre/library/server/cache.py b/src/calibre/library/server/cache.py index 9fec2c2737..6f6c21e60c 100644 --- a/src/calibre/library/server/cache.py +++ b/src/calibre/library/server/cache.py @@ -18,7 +18,7 @@ class Cache(object): old = self._search_cache.pop(search, None) if old is None or old[0] <= self.db.last_modified(): matches = self.db.data.search(search, return_matches=True, - ignore_search_restriction=True) + ignore_search_restriction=self.ignore_search_restriction) if not matches: matches = [] self._search_cache[search] = (utcnow(), frozenset(matches)) diff --git a/src/calibre/library/server/main.py b/src/calibre/library/server/main.py index 5ca82c6b98..2fad001a86 100644 --- a/src/calibre/library/server/main.py +++ b/src/calibre/library/server/main.py @@ -32,6 +32,8 @@ def option_parser(): help=_('Write process PID to the specified file')) parser.add_option('--daemonize', default=False, action='store_true', help='Run process in background as a daemon. No effect on windows.') + parser.add_option('--restriction', default=None, + help='Specifies a restriction to be used for this invocation.') return parser def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): @@ -83,7 +85,9 @@ def main(args=sys.argv): if opts.with_library is None: opts.with_library = prefs['library_path'] db = LibraryDatabase2(opts.with_library) - server = LibraryServer(db, opts) + server = LibraryServer(db, opts, ignore_search_restriction=False) + if opts.restriction: + db.data.set_search_restriction('search:' + opts.restriction) server.start() return 0 diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py index c3667a2077..391ad70bfd 100644 --- a/src/calibre/library/server/mobile.py +++ b/src/calibre/library/server/mobile.py @@ -181,7 +181,8 @@ class MobileServer(object): num = int(num) except ValueError: raise cherrypy.HTTPError(400, 'num: %s is not an integer'%num) - ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set() + ids = self.db.search(search, return_matches=True, + ignore_search_restriction=self.ignore_search_restriction) FM = self.db.FIELD_MAP items = [r for r in iter(self.db) if r[FM['id']] in ids] if sort is not None: diff --git a/src/calibre/library/server/xml.py b/src/calibre/library/server/xml.py index 036a2051bf..5649208036 100644 --- a/src/calibre/library/server/xml.py +++ b/src/calibre/library/server/xml.py @@ -45,7 +45,8 @@ class XMLServer(object): order = order.lower().strip() == 'ascending' - ids = self.db.data.parse(search) if search and search.strip() else self.db.data.universal_set() + ids = self.db.search(search, return_matches=True, + ignore_search_restriction=self.ignore_search_restriction) FM = self.db.FIELD_MAP