Workaround for the toolshed's hgweb.

This commit is contained in:
Dave Bouvier
2016-04-07 16:54:43 -04:00
parent a85d6d5566
commit b4e768b828
2 changed files with 56 additions and 63 deletions
+26 -23
View File
@@ -80,7 +80,7 @@ def app_factory( global_conf, **kwargs ):
image_file=None )
webapp.add_route( '/{controller}/{action}', action='index' )
webapp.add_route( '/{action}', controller='repository', action='index' )
webapp.add_route( '/repos/*path_info', controller='hg', action='handle_request', path_info='/' )
webapp.add_route( '/repos/{owner}/{name}/*path_info', controller='hg', action='handle_request', path_info='/' )
# Add the web API. # A good resource for RESTful services - http://routes.readthedocs.org/en/latest/restful.html
webapp.add_api_controllers( 'galaxy.webapps.tool_shed.api', app )
webapp.mapper.connect( 'api_key_retrieval',
@@ -204,6 +204,9 @@ def wrap_in_middleware( app, global_conf, **local_conf ):
# other middleware):
app = httpexceptions.make_middleware( app, conf )
log.debug( "Enabling 'httpexceptions' middleware" )
# Then load the Hg middleware.
app = hg.Hg( app, conf )
log.debug( "Enabling 'hg' middleware" )
# If we're using remote_user authentication, add middleware that
# protects Galaxy from improperly configured authentication in the
# upstream server
@@ -220,26 +223,6 @@ def wrap_in_middleware( app, global_conf, **local_conf ):
from paste import recursive
app = recursive.RecursiveMiddleware( app, conf )
log.debug( "Enabling 'recursive' middleware" )
# 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 = lint.make_middleware( app, conf )
log.debug( "Enabling 'lint' middleware" )
# Middleware to run the python profiler on each request
if asbool( conf.get( 'use_profile', False ) ):
import profile
app = profile.ProfileMiddleware( app, conf )
log.debug( "Enabling 'profile' middleware" )
# 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 = prints.PrintDebugMiddleware( app, conf )
log.debug( "Enabling 'print debug' middleware" )
if debug and asbool( conf.get( 'use_interactive', False ) ) and not process_is_uwsgi:
# Interactive exception debugging, scary dangerous if publicly
# accessible, if not enabled we'll use the regular error printing
@@ -273,8 +256,28 @@ def wrap_in_middleware( app, global_conf, **local_conf ):
from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware
app = XForwardedHostMiddleware( app )
log.debug( "Enabling 'x-forwarded-host' middleware" )
app = hg.Hg( app, conf )
log.debug( "Enabling hg middleware" )
# Various debug middleware that can only be turned on if the debug
# flag is set, either because they are insecure or greatly hurt
# performance. The print debug middleware needs to be loaded last,
# since there is a quirk in its behavior that breaks some (but not
# all) subsequent middlewares.
if debug:
# Middleware to check for WSGI compliance
if asbool( conf.get( 'use_lint', True ) ):
from paste import lint
app = lint.make_middleware( app, conf )
log.debug( "Enabling 'lint' middleware" )
# Middleware to run the python profiler on each request
if asbool( conf.get( 'use_profile', False ) ):
import profile
app = profile.ProfileMiddleware( app, conf )
log.debug( "Enabling 'profile' middleware" )
# 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 = prints.PrintDebugMiddleware( app, conf )
log.debug( "Enabling 'print debug' middleware" )
return app
+30 -40
View File
@@ -2,7 +2,6 @@ import logging
from galaxy import web
from galaxy.web.base.controller import BaseUIController
from tool_shed.util.common_util import generate_clone_url_for_repository_in_tool_shed
from tool_shed.util.shed_util_common import get_repository_by_name_and_owner
from tool_shed.util.hg_util import update_repository
from tool_shed.metadata import repository_metadata_manager
@@ -17,19 +16,18 @@ log = logging.getLogger(__name__)
class HgController( BaseUIController ):
@web.expose
def handle_request( self, trans, **kwd ):
def handle_request( self, trans, owner, name, **kwd ):
# The os command that results in this method being called will look something like:
# hg clone http://test@127.0.0.1:9009/repos/test/convert_characters1
hg_version = mercurial.__version__.version
cmd = kwd.get( 'cmd', None )
hgweb_config = trans.app.hgweb_config_manager.hgweb_config
def make_web_app():
hgwebapp = hgwebdir( hgweb_config )
return hgwebapp
wsgi_app = wsgiapplication( make_web_app )
if hg_version >= '2.2.3' and cmd == 'pushkey':
repository = get_repository_by_name_and_owner( trans.app, name, owner )
if repository:
repo = hg.repository( ui.ui(), repository.repo_path( trans.app ) )
if hg_version >= '2.2.3' and cmd == 'pushkey' and repository:
# When doing an "hg push" from the command line, the following commands, in order, will be
# retrieved from environ, depending upon the mercurial version being used. In mercurial
# version 2.2.3, section 15.2. Command changes includes a new feature:
@@ -37,35 +35,27 @@ class HgController( BaseUIController ):
# (see http://mercurial.selenic.com/wiki/WhatsNew#Mercurial_2.2.3_.282012-07-01.29).
# We require version 2.2.3 since the pushkey hook was added in that version.
# If mercurial version >= '2.2.3': capabilities -> batch -> branchmap -> unbundle -> listkeys -> pushkey
path_info = kwd.get( 'path_info', None )
if path_info:
owner, name = path_info.split( '/' )
repository = get_repository_by_name_and_owner( trans.app, name, owner )
if repository:
if hg_version >= '2.2.3':
# Update the repository on disk to the tip revision, because the web upload
# form uses the on-disk working directory. If the repository is not updated
# on disk, pushing from the command line and then uploading via the web
# interface will result in a new head being created.
repo = hg.repository( ui.ui(), repository.repo_path( trans.app ) )
update_repository( repo, ctx_rev=None )
repository_clone_url = generate_clone_url_for_repository_in_tool_shed( trans.user, repository )
# Set metadata using the repository files on disk.
rmm = repository_metadata_manager.RepositoryMetadataManager( app=trans.app,
user=trans.user,
repository=repository,
changeset_revision=repository.tip( trans.app ),
repository_clone_url=repository_clone_url,
relative_install_dir=repository.repo_path( trans.app ),
repository_files_dir=None,
resetting_all_metadata_on_repository=False,
updating_installed_repository=False,
persist=False )
error_message, status = rmm.set_repository_metadata( trans.request.host )
if status == 'ok' and error_message:
log.debug( "Successfully reset metadata on repository %s owned by %s, but encountered problem: %s" %
( str( repository.name ), str( repository.user.username ), error_message ) )
elif status != 'ok' and error_message:
log.debug( "Error resetting metadata on repository %s owned by %s: %s" %
( str( repository.name ), str( repository.user.username ), error_message ) )
return wsgi_app
# Update the repository on disk to the tip revision, because the web upload
# form uses the on-disk working directory. If the repository is not updated
# on disk, pushing from the command line and then uploading via the web
# interface will result in a new head being created.
update_repository( repo, ctx_rev=None )
# Set metadata using the repository files on disk.
rmm = repository_metadata_manager.RepositoryMetadataManager( app=trans.app,
user=trans.user,
repository=repository,
changeset_revision=repository.tip( trans.app ),
repository_clone_url=repository_clone_url,
relative_install_dir=repository.repo_path( trans.app ),
repository_files_dir=None,
resetting_all_metadata_on_repository=False,
updating_installed_repository=False,
persist=False )
error_message, status = rmm.set_repository_metadata( trans.request.host )
if status == 'ok' and error_message:
log.debug( "Successfully reset metadata on repository %s owned by %s, but encountered problem: %s" %
( str( repository.name ), str( repository.user.username ), error_message ) )
elif status != 'ok' and error_message:
log.debug( "Error resetting metadata on repository %s owned by %s: %s" %
( str( repository.name ), str( repository.user.username ), error_message ) )
return hgwebdir( hgweb_config )