mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a restriction argument to the content server command line. Includes changes to make the restriction work.
This commit is contained in:
parent
fa68736f6a
commit
35b0faf843
@ -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'))
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user