Add a restriction argument to the content server command line. Includes changes to make the restriction work.

This commit is contained in:
Charles Haley 2010-08-17 13:31:31 +01:00
parent fa68736f6a
commit 35b0faf843
5 changed files with 13 additions and 5 deletions

View File

@ -57,13 +57,15 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache):
server_name = __appname__ + '/' + __version__ 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 self.db = db
for item in self.db: for item in self.db:
item item
break break
self.opts = opts self.opts = opts
self.embedded = embedded self.embedded = embedded
self.ignore_search_restriction=ignore_search_restriction
self.state_callback = None self.state_callback = None
self.max_cover_width, self.max_cover_height = \ self.max_cover_width, self.max_cover_height = \
map(int, self.opts.max_cover.split('x')) map(int, self.opts.max_cover.split('x'))

View File

@ -18,7 +18,7 @@ class Cache(object):
old = self._search_cache.pop(search, None) old = self._search_cache.pop(search, None)
if old is None or old[0] <= self.db.last_modified(): if old is None or old[0] <= self.db.last_modified():
matches = self.db.data.search(search, return_matches=True, matches = self.db.data.search(search, return_matches=True,
ignore_search_restriction=True) ignore_search_restriction=self.ignore_search_restriction)
if not matches: if not matches:
matches = [] matches = []
self._search_cache[search] = (utcnow(), frozenset(matches)) self._search_cache[search] = (utcnow(), frozenset(matches))

View File

@ -32,6 +32,8 @@ def option_parser():
help=_('Write process PID to the specified file')) help=_('Write process PID to the specified file'))
parser.add_option('--daemonize', default=False, action='store_true', parser.add_option('--daemonize', default=False, action='store_true',
help='Run process in background as a daemon. No effect on windows.') 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 return parser
def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 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: if opts.with_library is None:
opts.with_library = prefs['library_path'] opts.with_library = prefs['library_path']
db = LibraryDatabase2(opts.with_library) 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() server.start()
return 0 return 0

View File

@ -181,7 +181,8 @@ class MobileServer(object):
num = int(num) num = int(num)
except ValueError: except ValueError:
raise cherrypy.HTTPError(400, 'num: %s is not an integer'%num) 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 FM = self.db.FIELD_MAP
items = [r for r in iter(self.db) if r[FM['id']] in ids] items = [r for r in iter(self.db) if r[FM['id']] in ids]
if sort is not None: if sort is not None:

View File

@ -45,7 +45,8 @@ class XMLServer(object):
order = order.lower().strip() == 'ascending' 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 FM = self.db.FIELD_MAP