commit/galaxy-central: greg: Contributions from Bjorn Gruning - add support for a template_command action type in tool dependency definitions for the tool shed. An example of the new action tag is <action type="template_command" language="cheetah">...</action>. This is a slightly modified version of Bjorn's original patch contribution.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/afec613d77fa/ Changeset: afec613d77fa User: greg Date: 2013-07-08 17:31:29 Summary: Contributions from Bjorn Gruning - add support for a template_command action type in tool dependency definitions for the tool shed. An example of the new action tag is <action type="template_command" language="cheetah">...</action>. This is a slightly modified version of Bjorn's original patch contribution. Affected #: 4 files diff -r a691d69caa99ec771062d5dd5312a516af5ff6c1 -r afec613d77fa58ad0de7066a2d9b18daad8cdb88 lib/galaxy/util/template.py --- a/lib/galaxy/util/template.py +++ b/lib/galaxy/util/template.py @@ -6,4 +6,4 @@ def fill_template( template_text, context=None, **kwargs ): if not context: context = kwargs - return str( Template( source=template_text, searchList=[context] ) ) \ No newline at end of file + return str( Template( source=template_text, searchList=[context] ) ) diff -r a691d69caa99ec771062d5dd5312a516af5ff6c1 -r afec613d77fa58ad0de7066a2d9b18daad8cdb88 lib/tool_shed/galaxy_install/tool_dependencies/common_util.py --- a/lib/tool_shed/galaxy_install/tool_dependencies/common_util.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/common_util.py @@ -80,10 +80,6 @@ tar.extractall( path=file_path ) tar.close() -def format_traceback(): - ex_type, ex, tb = sys.exc_info() - return ''.join( traceback.format_tb( tb ) ) - def extract_zip( archive_path, extraction_path ): # TODO: change this method to use zipfile.Zipfile.extractall() when we stop supporting Python 2.5. if not zipfile_ok( archive_path ): @@ -99,6 +95,10 @@ zip_archive.close() return True +def format_traceback(): + ex_type, ex, tb = sys.exc_info() + return ''.join( traceback.format_tb( tb ) ) + def get_env_shell_file_path( installation_directory ): env_shell_file_name = 'env.sh' default_location = os.path.abspath( os.path.join( installation_directory, env_shell_file_name ) ) @@ -167,6 +167,14 @@ log.debug( error_message ) return env_shell_file_paths +def get_env_var_values( install_dir ): + env_var_dict = {} + env_var_dict[ 'INSTALL_DIR' ] = install_dir + env_var_dict[ 'system_install' ] = install_dir + # If the Python interpreter is 64bit then we can safely assume that the underlying system is also 64bit. + env_var_dict[ '__is64bit__' ] = sys.maxsize > 2**32 + return env_var_dict + def isbz2( file_path ): return checkers.is_bz2( file_path ) diff -r a691d69caa99ec771062d5dd5312a516af5ff6c1 -r afec613d77fa58ad0de7066a2d9b18daad8cdb88 lib/tool_shed/galaxy_install/tool_dependencies/fabric_util.py --- a/lib/tool_shed/galaxy_install/tool_dependencies/fabric_util.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/fabric_util.py @@ -8,8 +8,9 @@ import tempfile import shutil from contextlib import contextmanager +from galaxy.util.template import fill_template +from galaxy import eggs -from galaxy import eggs import pkg_resources pkg_resources.require('ssh' ) @@ -297,12 +298,28 @@ with settings( warn_only=True ): cmd = '' for env_shell_file_path in env_shell_file_paths: - for i, env_setting in enumerate( open( env_shell_file_path ) ): + for env_setting in open( env_shell_file_path ): cmd += '%s\n' % env_setting cmd += action_dict[ 'command' ] return_code = handle_command( app, tool_dependency, install_dir, cmd ) if return_code: return + elif action_type == 'template_command': + env_vars = dict() + for env_shell_file_path in env_shell_file_paths: + for env_setting in open( env_shell_file_path ): + env_string = env_setting.split( ';' )[ 0 ] + env_name, env_path = env_string.split( '=' ) + env_vars[ env_name ] = env_path + env_vars.update( common_util.get_env_var_values( install_dir ) ) + language = action_dict[ 'language' ] + with settings( warn_only=True, **env_vars ): + if language == 'cheetah': + # We need to import fabric.api.env so that we can access all collected environment variables. + cmd = fill_template( '#from fabric.api import env\n%s' % action_dict[ 'command' ], context=env_vars ) + return_code = handle_command( app, tool_dependency, install_dir, cmd ) + if return_code: + return elif action_type == 'download_file': # Download a single file to the current working directory. url = action_dict[ 'url' ] diff -r a691d69caa99ec771062d5dd5312a516af5ff6c1 -r afec613d77fa58ad0de7066a2d9b18daad8cdb88 lib/tool_shed/galaxy_install/tool_dependencies/install_util.py --- a/lib/tool_shed/galaxy_install/tool_dependencies/install_util.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/install_util.py @@ -361,12 +361,8 @@ sa_session = app.model.context.current def evaluate_template( text ): - """ Substitute variables defined in XML blocks obtained loaded from dependencies file. """ - # # Added for compatibility with CloudBioLinux. - # TODO: Add tool_version substitution for compat with CloudBioLinux. - substitutions = { "INSTALL_DIR" : install_dir, - "system_install" : install_dir } - return Template( text ).safe_substitute( substitutions ) + """ Substitute variables defined in XML blocks from dependencies file.""" + return Template( text ).safe_substitute( common_util.get_env_var_values( install_dir ) ) if not os.path.exists( install_dir ): os.makedirs( install_dir ) @@ -387,6 +383,25 @@ action_dict[ 'command' ] = action_elem_text else: continue + elif action_type == 'template_command': + # Default to Cheetah as it's the first template language supported. + language = action_elem.get( 'language', 'cheetah' ).lower() + if language == 'cheetah': + # Cheetah template syntax. + # <action type="template_command" language="cheetah"> + # #if env.PATH: + # make + # #end if + # </action> + action_elem_text = action_elem.text.strip() + if action_elem_text: + action_dict[ 'language' ] = language + action_dict[ 'command' ] = action_elem_text + else: + continue + else: + log.debug( "Unsupported template language '%s'. Not proceeding." % str( language ) ) + raise Exception( "Unsupported template language '%s' in tool dependency definition." % str( language ) ) elif action_type == 'download_by_url': # <action type="download_by_url">http://sourceforge.net/projects/samtools/files/samtools/0.1.18/samtools-0.1.18.tar.bz2</action> if action_elem.text: @@ -690,4 +705,4 @@ parts = [] for arg in args: parts.append( arg.strip( '/' ) ) - return '/'.join( parts ) \ No newline at end of file + return '/'.join( parts ) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org