Skip to content

Commit

Permalink
Galaxy 24.1 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gregvonkuster committed Sep 25, 2024
1 parent bf298ef commit 06cce3b
Show file tree
Hide file tree
Showing 18 changed files with 680 additions and 634 deletions.
Empty file.
34 changes: 20 additions & 14 deletions galaxy/coralsnp_reports/lib/galaxy/webapps/coralsnp_reports/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,46 @@
import sys
import time

import galaxy.model.corals
import galaxy.model.corals.mapping
from galaxy.config import configure_logging
from galaxy.model.base import SharedModelMapping
from galaxy.security import idencoding
from galaxy.web.stack import application_stack_instance
from galaxy.structured_app import BasicSharedApp
from galaxy.web_stack import application_stack_instance
from . import config

log = logging.getLogger(__name__)


class UniverseApplication(object):
class UniverseApplication(BasicSharedApp):
"""Encapsulates the state of a Universe application"""

def __init__(self, **kwargs):
log.debug("python path is: %s", ", ".join(sys.path))
super().__init__()
self[BasicSharedApp] = self
self.name = "coralsnp_reports"
# Read config file and check for errors
self.config = config.Configuration(**kwargs)
self.config.check()
config.configure_logging(self.config)
configure_logging(self.config)
log.debug("XXX kwargs: %s\n" % str(kwargs))
log.debug("XXX self.config: %s\n" % str(self.config))
log.debug("XXX self.config.corals_database_connection: %s\n" % self.config.corals_database_connection)
log.debug("python path is: %s", ", ".join(sys.path))
self.application_stack = application_stack_instance()
# Determine the database url
if self.config.database_connection:
db_url = self.config.database_connection
if self.config.corals_database_connection:
db_url = self.config.corals_database_connection
else:
db_url = "postgresql://galaxy:galaxy@localhost/stag"
db_url = f"sqlite:///{self.config.database}?isolation_level=IMMEDIATE"
# Setup the database engine and ORM
self.model = galaxy.model.corals.mapping.init(db_url,
self.config.database_engine_options)
if not self.config.database_connection:
self.targets_mysql = False
else:
self.targets_mysql = 'mysql' in self.config.database_connection
self.model = galaxy.model.corals.mapping.init(self.config.file_path, db_url, self.config.database_engine_options)
# Security helper
self.security = idencoding.IdEncodingHelper(id_secret=self.config.id_secret)

self._register_singleton(idencoding.IdEncodingHelper, self.security)
self._register_singleton(SharedModelMapping, self.model)

# used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
self.server_starttime = int(time.time())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@

from paste import httpexceptions

import galaxy.model.corals
import galaxy.web.framework.webapp
import galaxy.webapps.base.webapp
from galaxy.util import asbool
from galaxy.util.properties import load_app_properties
from galaxy.webapps.util import (
build_template_error_formatters,
MiddlewareWrapUnsupported,
wrap_if_allowed,
wrap_if_allowed_or_fail
)
from galaxy.web.framework.middleware.request_id import RequestIDMiddleware
from galaxy.webapps.util import wrap_if_allowed

log = logging.getLogger(__name__)


class CoralSNPReportsWebApplication(galaxy.web.framework.webapp.WebApplication):
class CoralSNPReportsWebApplication(galaxy.webapps.base.webapp.WebApplication):
pass


Expand All @@ -31,9 +26,9 @@ def add_ui_controllers(webapp, app):
Search for controllers in the 'galaxy.webapps.coralsnp_reports.controllers'
module and add them to the webapp.
"""
#from galaxy.web.base.controller import BaseUIController
import galaxy.webapps.coralsnp_reports.controllers
from galaxy.webapps.coralsnp_reports.controllers import BaseUIController
from galaxy.webapps.base.controller import BaseUIController

controller_dir = galaxy.webapps.coralsnp_reports.controllers.__path__[0]
for fname in os.listdir(controller_dir):
if not fname.startswith("_") and fname.endswith(".py"):
Expand All @@ -52,10 +47,8 @@ def add_ui_controllers(webapp, app):
def app_factory(global_conf, load_app_kwds={}, **kwargs):
"""Return a wsgi application serving the root object"""
# Create the Galaxy application unless passed in
kwargs = load_app_properties(
kwds=kwargs,
**load_app_kwds
)
load_app_kwds = load_app_kwds or {}
kwargs = load_app_properties(kwds=kwargs, **load_app_kwds)
if 'app' in kwargs:
app = kwargs.pop('app')
else:
Expand All @@ -73,15 +66,7 @@ def app_factory(global_conf, load_app_kwds={}, **kwargs):
if kwargs.get('middleware', True):
webapp = wrap_in_middleware(webapp, global_conf, app.application_stack, **kwargs)
if asbool(kwargs.get('static_enabled', True)):
webapp = wrap_if_allowed(webapp, app.application_stack, wrap_in_static,
args=(global_conf,),
kwargs=kwargs)
# Close any pooled database connections before forking
try:
galaxy.model.corals.mapping.metadata.bind.dispose()
except Exception:
log.exception("Unable to dispose of pooled coralsnp_reports model database connections.")
# Return
webapp = wrap_if_allowed(webapp, app.application_stack, galaxy.webapps.base.webapp.build_url_map, args=(global_conf,), kwargs=kwargs)
return webapp


Expand All @@ -91,7 +76,6 @@ def wrap_in_middleware(app, global_conf, application_stack, **local_conf):
# Merge the global and local configurations
conf = global_conf.copy()
conf.update(local_conf)
debug = asbool(conf.get('debug', False))
# First put into place httpexceptions, which must be most closely
# wrapped around the application (it can interact poorly with
# other middleware):
Expand All @@ -101,54 +85,20 @@ def wrap_in_middleware(app, global_conf, application_stack, **local_conf):
if asbool(conf.get('use_recursive', True)):
from paste import recursive
app = wrap_if_allowed(app, stack, recursive.RecursiveMiddleware, args=(conf,))
# Various debug middleware that can only be turned on if the debug
# flag is set, either because they are insecure or greatly hurt
# performance
if debug:
# Middleware to check for WSGI compliance
if asbool(conf.get('use_lint', True)):
from paste import lint
app = wrap_if_allowed(app, stack, lint.make_middleware, name='paste.lint', args=(conf,))
# Middleware to run the python profiler on each request
if asbool(conf.get('use_profile', False)):
import profile
app = wrap_if_allowed(app, stack, profile.ProfileMiddleware, args=(conf,))
# Middleware that intercepts print statements and shows them on the
# returned page
if asbool(conf.get('use_printdebug', True)):
from paste.debug import prints
app = wrap_if_allowed(app, stack, prints.PrintDebugMiddleware, args=(conf,))
if debug and asbool(conf.get('use_interactive', False)):
# Interactive exception debugging, scary dangerous if publicly
# accessible, if not enabled we'll use the regular error printing
# middleware.
try:
from weberror import evalexception
app = wrap_if_allowed_or_fail(app, stack, evalexception.EvalException,
args=(conf,),
kwargs=dict(templating_formatters=build_template_error_formatters()))
except MiddlewareWrapUnsupported as exc:
log.warning(str(exc))
import galaxy.web.framework.middleware.error
app = wrap_if_allowed(app, stack, galaxy.web.framework.middleware.error.ErrorMiddleware, args=(conf,))
else:
# Not in interactive debug mode, just use the regular error middleware
import galaxy.web.framework.middleware.error
app = wrap_if_allowed(app, stack, galaxy.web.framework.middleware.error.ErrorMiddleware, args=(conf,))
# Error middleware
import galaxy.web.framework.middleware.error
app = wrap_if_allowed(app, stack, galaxy.web.framework.middleware.error.ErrorMiddleware, args=(conf,))
# Transaction logging (apache access.log style)
if asbool(conf.get('use_translogger', True)):
if asbool(conf.get("use_translogger", True)):
from paste.translogger import TransLogger
app = wrap_if_allowed(app, stack, TransLogger)
# X-Forwarded-Host handling
from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware
app = wrap_if_allowed(app, stack, XForwardedHostMiddleware)
return app

# Request ID middleware
app = wrap_if_allowed(app, stack, RequestIDMiddleware)
if asbool(conf.get("enable_per_request_sql_debugging", False)):
from galaxy.web.framework.middleware.sqldebug import SQLDebugMiddleware

def wrap_in_static(app, global_conf, **local_conf):
urlmap, _ = galaxy.web.framework.webapp.build_url_map(app, global_conf, local_conf)
return urlmap


def uwsgi_app():
return galaxy.web.framework.webapp.build_native_uwsgi_app(app_factory, "coralsnp_reports")
app = wrap_if_allowed(app, stack, SQLDebugMiddleware, args=(webapp, {}))
return app
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def resolve_path(path, root):
"""If 'path' is relative make absolute by prepending 'root'"""
if not(os.path.isabs(path)):
if not (os.path.isabs(path)):
path = os.path.join(root, path)
return path

Expand All @@ -26,7 +26,7 @@ def __init__(self, **kwargs):
self.root = kwargs.get('root_dir', '.')
# Database related configuration
self.database = resolve_path(kwargs.get("database_file", "database/universe.sqlite"), self.root)
self.database_connection = kwargs.get("database_connection", False)
self.corals_database_connection = kwargs.get("corals_database_connection", False)
self.database_engine_options = get_database_engine_options(kwargs)
# Where dataset files are stored
self.file_path = resolve_path(kwargs.get("file_path", "database/files"), self.root)
Expand All @@ -36,7 +36,7 @@ def __init__(self, **kwargs):
self.require_login = string_as_bool(kwargs.get("require_login", "False"))
self.session_duration = kwargs.get("session_duration", "0")
self.template_path = resolve_path(kwargs.get("template_path", "templates"), self.root)
self.template_cache = resolve_path(kwargs.get("template_cache_path", "database/compiled_templates/coralsnp_reports"), self.root)
self.template_cache_path = resolve_path(kwargs.get("template_cache_path", "database/compiled_templates/coralsnp_reports"), self.root)
self.allow_user_creation = string_as_bool(kwargs.get("allow_user_creation", "True"))
self.allow_user_deletion = string_as_bool(kwargs.get("allow_user_deletion", "False"))
self.log_actions = string_as_bool(kwargs.get('log_actions', 'False'))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
"""Galaxy coralsnp reports controllers."""
import logging

from galaxy import util

log = logging.getLogger(__name__)


class BaseController(object):
"""
Base class for CoralSNP Reports web application controllers.
"""

def __init__(self, app):
"""Initialize an interface for application 'app'"""
self.app = app
self.sa_session = app.model.context


class BaseUIController(BaseController):

def get_object(self, trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None):
try:
return BaseController.get_object(self, trans, id, class_name, check_ownership=check_ownership,
check_accessible=check_accessible, deleted=deleted)
except Exception:
log.exception("Exception in get_object check for %s %s:", class_name, str(id))
raise Exception('Server error retrieving %s id ( %s ).' % (class_name, str(id)))

def message_exception(self, trans, message, sanitize=True):
trans.response.status = 400
return {'err_msg': util.sanitize_text(message) if sanitize else message}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import sqlalchemy as sa
from markupsafe import escape

import galaxy.model
from galaxy.model import corals
from galaxy import util
from . import BaseUIController
from galaxy.web.base.controller import web
from galaxy.webapps.reports.controllers.query import ReportQueryBuilder
from galaxy.webapps.base.controller import (
BaseUIController,
web,
)
from galaxy.webapps.coralsnp_reports.controllers.query import ReportQueryBuilder

log = logging.getLogger(__name__)

Expand All @@ -19,14 +21,17 @@ def of_sample(self, trans, **kwd):
message = escape(util.restore_text(kwd.get('message', '')))
affy_id = kwd.get('affy_id')
allele_id = kwd.get('allele_id')
q = sa.select((galaxy.model.corals.Allele.table.c.id,
galaxy.model.corals.Allele.table.c.allele),
whereclause=galaxy.model.corals.Allele.table.c.id == allele_id,
from_obj=[galaxy.model.corals.Allele.table])
q = (
sa.select(
corals.Allele.id,
corals.Allele.allele
)
.select_from(corals.Allele.table)
.where(corals.Allele.table.c.id == allele_id)
)
alleles = []
for row in q.execute():
cols_tup = (row.id, row.allele)
alleles.append(cols_tup)
for row in trans.sa_session.execute(q):
alleles.append((row.id, row.allele))
return trans.fill_template('/webapps/coralsnp_reports/allele_of_sample.mako',
affy_id=affy_id,
alleles=alleles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import sqlalchemy as sa
from markupsafe import escape

import galaxy.model
from galaxy.model import corals
from galaxy import util
from . import BaseUIController
from galaxy.web.base.controller import web
from galaxy.webapps.reports.controllers.query import ReportQueryBuilder
from galaxy.webapps.base.controller import (
BaseUIController,
web,
)
from galaxy.webapps.coralsnp_reports.controllers.query import ReportQueryBuilder

log = logging.getLogger(__name__)

Expand All @@ -17,35 +19,32 @@ class Collectors(BaseUIController, ReportQueryBuilder):
@web.expose
def all(self, trans, **kwd):
message = escape(util.restore_text(kwd.get('message', '')))
q = sa.select((galaxy.model.corals.Person.table.c.id,
galaxy.model.corals.Person.table.c.last_name,
galaxy.model.corals.Person.table.c.first_name,
galaxy.model.corals.Person.table.c.organization,
galaxy.model.corals.Person.table.c.email),
from_obj=[galaxy.model.corals.Person.table],
order_by=[galaxy.model.corals.Person.table.c.last_name])
collectors = []
for row in q.execute():
cols_tup = (row.id, row.last_name, row.first_name, row.organization, row.email)
collectors.append(cols_tup)
return trans.fill_template('/webapps/coralsnp_reports/collectors.mako', collectors=collectors, message=message)
for row in trans.sa_session.query(corals.Person):
collectors.append((row.id, row.last_name, row.first_name, row.organization, row.email))
return trans.fill_template('/webapps/coralsnp_reports/collectors.mako',
collectors=collectors,
message=message)

@web.expose
def of_sample(self, trans, **kwd):
message = escape(util.restore_text(kwd.get('message', '')))
affy_id = kwd.get('affy_id')
collector_id = kwd.get('collector_id')
q = sa.select((galaxy.model.corals.Person.table.c.id,
galaxy.model.corals.Person.table.c.last_name,
galaxy.model.corals.Person.table.c.first_name,
galaxy.model.corals.Person.table.c.organization,
galaxy.model.corals.Person.table.c.email),
whereclause=galaxy.model.corals.Person.table.c.id == collector_id,
from_obj=[galaxy.model.corals.Person.table])
q = (
sa.select(
corals.Person.id,
corals.Person.last_name,
corals.Person.first_name,
corals.Person.organization,
corals.Person.email
)
.select_from(corals.Person.table)
.where(corals.Person.table.c.id == collector_id)
)
collectors = []
for row in q.execute():
cols_tup = (row.last_name, row.first_name, row.organization, row.email)
collectors.append(cols_tup)
for row in trans.sa_session.execute(q):
collectors.append((row.last_name, row.first_name, row.organization, row.email))
return trans.fill_template('/webapps/coralsnp_reports/collector_of_sample.mako',
affy_id=affy_id,
collectors=collectors,
Expand Down
Loading

0 comments on commit 06cce3b

Please sign in to comment.