refactor setup_webapp so that it only does webapp setup stuff
Gitea/photolib/pipeline/head This commit looks good Details

This commit is contained in:
dave 2023-01-30 21:58:54 -08:00
parent cb328659cc
commit d8cac3f641
2 changed files with 26 additions and 21 deletions

View File

@ -621,34 +621,30 @@ class SearchView(object):
def setup_webapp( def setup_webapp(
database_url, database_engine,
library_url, library_client,
cache_url, cache_client,
thumb_service_url, thumb_service_url,
debug=False, debug=False,
db_debug=False, db_debug=False,
max_upload=1024**3 max_upload=1024**3
): ):
# Get database connection
engine = get_db_engine(database_url, debug=db_debug)
# Setup database in web framework # Setup database in web framework
cherrypy.tools.db = SATool() cherrypy.tools.db = SATool()
SAEnginePlugin(cherrypy.engine, engine).subscribe() SAEnginePlugin(cherrypy.engine, database_engine).subscribe()
cherrypy.tools.user = UserTool()
# Create various internal tools # Create various internal tools
library_storage = uri_to_storage(library_url) #TODO move thumbtool outside of setup_webapp and use the cherrypy bus to connect with it
library_manager = LibraryManager(library_storage) thumbnail_tool = ThumbGenerator(library_client, cache_client, thumb_service_url)
thumbnail_tool = ThumbGenerator(library_manager, uri_to_storage(cache_url), thumb_service_url)
jobs_client = JobsClient(engine)
JobSubscriber(jobs_client)
# Setup and mount web ui # Setup and mount web ui
tpl_dir = os.path.join(APPROOT, "templates") if not debug else "templates" tpl_dir = os.path.join(APPROOT, "templates") if not debug else "templates"
web = PhotosWeb(library_manager, thumbnail_tool, tpl_dir) web = PhotosWeb(library_client, thumbnail_tool, tpl_dir)
cherrypy.tree.mount(web, '/', {'/': {'tools.trailing_slash.on': False, cherrypy.tree.mount(web, '/', {'/': {'tools.trailing_slash.on': False,
'tools.db.on': True, 'tools.db.on': True,
'tools.user.on': True,
'error_page.403': web.error, 'error_page.403': web.error,
'error_page.404': web.error}, 'error_page.404': web.error},
'/static': {"tools.staticdir.on": True, '/static': {"tools.staticdir.on": True,
@ -661,7 +657,7 @@ def setup_webapp(
'tools.auth_basic.checkpassword': validate_password}}) 'tools.auth_basic.checkpassword': validate_password}})
# Setup and mount API # Setup and mount API
api = PhotosApi(library_manager) api = PhotosApi(library_client)
cherrypy.tree.mount(api, '/api', {'/': {'tools.sessions.on': False, cherrypy.tree.mount(api, '/api', {'/': {'tools.sessions.on': False,
'tools.trailing_slash.on': False, 'tools.trailing_slash.on': False,
'tools.auth_basic.on': True, 'tools.auth_basic.on': True,
@ -718,10 +714,16 @@ def main():
if not args.thumb_service: if not args.thumb_service:
logging.warning("THUMB_SERVICE_URL not set. Video thumbnails will be unavailable") logging.warning("THUMB_SERVICE_URL not set. Video thumbnails will be unavailable")
# Get database connections
library_storage = uri_to_storage(args.library)
library_manager = LibraryManager(library_storage)
cache_manager = uri_to_storage(args.cache)
# set up webapp
setup_webapp( setup_webapp(
args.database, get_db_engine(args.database, debug=args.db_debug),
args.library, library_manager,
args.cache, cache_manager,
args.thumb_service, args.thumb_service,
debug=args.debug, debug=args.debug,
db_debug=args.db_debug, db_debug=args.db_debug,

View File

@ -6,6 +6,9 @@ import cherrypy
from cherrypy.test import helper from cherrypy.test import helper
from photoapp.daemon import setup_webapp from photoapp.daemon import setup_webapp
from photoapp.dbutils import get_db_engine
from photoapp.api import LibraryManager
from photoapp.storage import uri_to_storage
class MockAuth: class MockAuth:
@ -24,9 +27,9 @@ class PhotolibTest(helper.CPWebCase):
os.mkdir(cached) os.mkdir(cached)
setup_webapp( setup_webapp(
"sqlite:///{}".format(os.path.join(cls.tmpd.name, "testing.db")), get_db_engine("sqlite:///{}".format(os.path.join(cls.tmpd.name, "testing.db"))),
"file://{}".format(libd), LibraryManager(uri_to_storage("file://{}".format(libd))),
"file://{}".format(cached), uri_to_storage("file://{}".format(cached)),
None, None,
debug=True, debug=True,
) )