galaxy-commits
Threads by month
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
July 2014
- 1 participants
- 146 discussions
5 new commits in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/c118476b5823/
Changeset: c118476b5823
User: jgoecks
Date: 2014-07-21 16:19:14
Summary: Use jquery to remove event handler.
Affected #: 1 file
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r c118476b5823c676267dbe5d48f7105711e3c15d static/scripts/viz/trackster.js
--- a/static/scripts/viz/trackster.js
+++ b/static/scripts/viz/trackster.js
@@ -356,7 +356,7 @@
buttons: {
"Cancel": function() { Galaxy.modal.hide(); },
"Leave without Saving" : function() {
- window.onbeforeunload = undefined;
+ $(window).off('beforeunload');
window.location = galaxy_config.root + 'visualization';
},
"Save" : function() {
https://bitbucket.org/galaxy/galaxy-central/commits/bca25a3bc9c7/
Changeset: bca25a3bc9c7
User: jgoecks
Date: 2014-07-21 16:26:18
Summary: Trackster: remove bottom label track because it is redundant.
Affected #: 1 file
diff -r c118476b5823c676267dbe5d48f7105711e3c15d -r bca25a3bc9c7618eb37fb467ae32564fa213aac5 static/scripts/viz/trackster/tracks.js
--- a/static/scripts/viz/trackster/tracks.js
+++ b/static/scripts/viz/trackster/tracks.js
@@ -885,8 +885,6 @@
});
});
});
- // Another label track at bottom
- this.nav_labeltrack = $("<div/>").addClass("nav-labeltrack").appendTo(this.bottom_container);
// Navigation at top
this.nav_container = $("<div/>").addClass("trackster-nav-container").prependTo(this.top_container);
this.nav = $("<div/>").addClass("trackster-nav").appendTo(this.nav_container);
@@ -1042,7 +1040,7 @@
// Dragging in the top label track allows selecting a region to zoom in on selected region.
this.top_labeltrack.bind( "dragstart", function( e, d ) {
return $("<div/>").addClass('zoom-area').css(
- "height", view.browser_content_div.height() + view.top_labeltrack.height() + view.nav_labeltrack.height() + 1
+ "height", view.browser_content_div.height() + view.top_labeltrack.height() + 1
).appendTo( $(this) );
}).bind( "drag", function( e, d ) {
$( d.proxy ).css({ left: Math.min( e.pageX, d.startX ) - view.container.offset().left, width: Math.abs( e.pageX - d.startX ) });
@@ -1091,7 +1089,6 @@
*/
this.add_label_track( new LabelTrack( this, { content_div: this.top_labeltrack } ) );
- this.add_label_track( new LabelTrack( this, { content_div: this.nav_labeltrack } ) );
$(window).bind("resize", function() {
// Stop previous timer.
https://bitbucket.org/galaxy/galaxy-central/commits/f9b47a91b7f2/
Changeset: f9b47a91b7f2
User: jgoecks
Date: 2014-07-21 16:27:44
Summary: Trackster: some fixes for vertical position element.
Affected #: 1 file
diff -r bca25a3bc9c7618eb37fb467ae32564fa213aac5 -r f9b47a91b7f2611c87c9dc7a0ceafc733f6bc181 static/scripts/viz/trackster/tracks.js
--- a/static/scripts/viz/trackster/tracks.js
+++ b/static/scripts/viz/trackster/tracks.js
@@ -1062,11 +1062,9 @@
view.request_redraw();
});
+ // FIXME: this is still wonky for embedded visualizations.
+ /*
// For vertical alignment, track mouse with simple line.
- // Fixes needed for this to work:
- // (a) make work with embedded visualizations;
- // (b) seems to get stuck on tile overlaps.
- /*
var mouse_tracker_div = $('<div/>').addClass('mouse-pos').appendTo(parent_element);
// Show tracker only when hovering over view.
@@ -1075,9 +1073,8 @@
mouse_tracker_div.show();
parent_element.mousemove(function(e) {
mouse_tracker_div.css({
- // -1 makes it appear next to the mouse w/o obscuring clicking
- // and dragging on view elements.
- left: e.pageX - 1
+ // -1 makes line appear next to the mouse w/o preventing mouse actions.
+ left: e.pageX - parent_element.offset().left - 1
});
});
},
https://bitbucket.org/galaxy/galaxy-central/commits/972a80267009/
Changeset: 972a80267009
User: jgoecks
Date: 2014-07-21 19:23:41
Summary: Trackster: do not reset overview when changing chromosome.
Affected #: 1 file
diff -r f9b47a91b7f2611c87c9dc7a0ceafc733f6bc181 -r 972a80267009126e558ba14142df48b897db48c8 static/scripts/viz/trackster/tracks.js
--- a/static/scripts/viz/trackster/tracks.js
+++ b/static/scripts/viz/trackster/tracks.js
@@ -1287,7 +1287,6 @@
}
}
- view.reset_overview();
view.request_redraw();
}
},
https://bitbucket.org/galaxy/galaxy-central/commits/e9de99ef7710/
Changeset: e9de99ef7710
User: jgoecks
Date: 2014-07-21 19:42:14
Summary: Automated merge
Affected #: 19 files
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
--- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
+++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
@@ -413,12 +413,12 @@
# Make sure the current user's API key proves he is an admin user in this Galaxy instance.
if not trans.user_is_admin():
raise HTTPForbidden( detail='You are not authorized to reset metadata on repositories installed into this Galaxy instance.' )
- query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=False, order=False )
+ irmm = InstalledRepositoryMetadataManager( trans.app )
+ query = irmm.get_query_for_setting_metadata_on_repositories( order=False )
# Now reset metadata on all remaining repositories.
for repository in query:
repository_id = trans.security.encode_id( repository.id )
try:
- irmm = InstalledRepositoryMetadataManager( trans.app )
invalid_file_tups, metadata_dict = irmm.reset_all_metadata_on_installed_repository( repository_id )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
--- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
+++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
@@ -30,6 +30,7 @@
from tool_shed.galaxy_install.metadata.installed_repository_metadata_manager import InstalledRepositoryMetadataManager
from tool_shed.galaxy_install.repair_repository_manager import RepairRepositoryManager
from tool_shed.galaxy_install.repository_dependencies import repository_dependency_manager
+from tool_shed.galaxy_install.tools import tool_panel_manager
log = logging.getLogger( __name__ )
@@ -244,10 +245,10 @@
if kwd.get( 'deactivate_or_uninstall_repository_button', False ):
if tool_shed_repository.includes_tools_for_display_in_tool_panel:
# Handle tool panel alterations.
- tool_util.remove_from_tool_panel( trans.app,
- tool_shed_repository,
- shed_tool_conf,
- uninstall=remove_from_disk_checked )
+ tpm = tool_panel_manager.ToolPanelManager( trans.app )
+ tpm.remove_from_tool_panel( tool_shed_repository,
+ shed_tool_conf,
+ uninstall=remove_from_disk_checked )
if tool_shed_repository.includes_data_managers:
data_manager_util.remove_from_data_manager( trans.app, tool_shed_repository )
if tool_shed_repository.includes_datatypes:
@@ -1336,13 +1337,14 @@
# its repository dependencies.
includes_tool_dependencies = tool_shed_repository.includes_tool_dependencies
if tool_shed_repository.includes_tools_for_display_in_tool_panel:
+ tpm = tool_panel_manager.ToolPanelManager( trans.app )
# Handle the selected tool panel location for loading tools included in the tool shed repository.
tool_section, tool_panel_section_key = \
- tool_util.handle_tool_panel_selection( toolbox=trans.app.toolbox,
- metadata=metadata,
- no_changes_checked=no_changes_checked,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_selection( toolbox=trans.app.toolbox,
+ metadata=metadata,
+ no_changes_checked=no_changes_checked,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
if tool_section is not None:
# Just in case the tool_section.id differs from tool_panel_section_id, which it shouldn't...
tool_panel_section_id = str( tool_section.id )
@@ -1706,13 +1708,13 @@
@web.expose
@web.require_admin
def reset_metadata_on_selected_installed_repositories( self, trans, **kwd ):
+ irmm = InstalledRepositoryMetadataManager( trans.app )
if 'reset_metadata_on_selected_repositories_button' in kwd:
- irmm = InstalledRepositoryMetadataManager( trans.app )
message, status = irmm.reset_metadata_on_selected_repositories( trans.user, **kwd )
else:
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
- repositories_select_field = suc.build_repository_ids_select_field( trans )
+ repositories_select_field = irmm.build_repository_ids_select_field( trans )
return trans.fill_template( '/admin/tool_shed_repository/reset_metadata_on_selected_repositories.mako',
repositories_select_field=repositories_select_field,
message=message,
@@ -1942,19 +1944,19 @@
updating_installed_repository=True,
persist=True )
if 'tools' in metadata_dict:
+ tpm = tool_panel_manager.ToolPanelManager( trans.app )
tool_panel_dict = metadata_dict.get( 'tool_panel_section', None )
if tool_panel_dict is None:
tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( trans.app, repository )
repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata_dict )
- tool_util.add_to_tool_panel( app=trans.app,
- repository_name=str( repository.name ),
- repository_clone_url=repository_clone_url,
- changeset_revision=str( repository.installed_changeset_revision ),
- repository_tools_tups=repository_tools_tups,
- owner=str( repository.owner ),
- shed_tool_conf=shed_tool_conf,
- tool_panel_dict=tool_panel_dict,
- new_install=False )
+ tpm.add_to_tool_panel( repository_name=str( repository.name ),
+ repository_clone_url=repository_clone_url,
+ changeset_revision=str( repository.installed_changeset_revision ),
+ repository_tools_tups=repository_tools_tups,
+ owner=str( repository.owner ),
+ shed_tool_conf=shed_tool_conf,
+ tool_panel_dict=tool_panel_dict,
+ new_install=False )
# Add new Data Manager entries
if 'data_manager' in metadata_dict:
new_data_managers = data_manager_util.install_data_managers( trans.app,
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/tool_shed/api/repositories.py
--- a/lib/galaxy/webapps/tool_shed/api/repositories.py
+++ b/lib/galaxy/webapps/tool_shed/api/repositories.py
@@ -392,7 +392,8 @@
my_writable = True
handled_repository_ids = []
repository_ids = []
- query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=False )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
+ query = rmm.get_query_for_setting_metadata_on_repositories( my_writable=my_writable, order=False )
# Make sure repositories of type tool_dependency_definition are first in the list.
for repository in query:
if repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids:
@@ -426,13 +427,12 @@
This param can be used as an alternative to the above encoded_ids_to_skip.
"""
- def handle_repository( trans, repository, results ):
+ def handle_repository( trans, rmm, repository, results ):
log.debug( "Resetting metadata on repository %s" % str( repository.name ) )
repository_id = trans.security.encode_id( repository.id )
try:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
invalid_file_tups, metadata_dict = \
- rmm.reset_all_metadata_on_repository_in_tool_shed( trans.user, repository_id )
+ rmm.reset_all_metadata_on_repository_in_tool_shed( repository_id )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
invalid_file_tups,
@@ -451,7 +451,7 @@
status = '%s : %s' % ( str( repository.name ), message )
results[ 'repository_status' ].append( status )
return results
-
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
start_time = strftime( "%Y-%m-%d %H:%M:%S" )
results = dict( start_time=start_time,
repository_status=[],
@@ -473,7 +473,7 @@
my_writable = util.asbool( payload.get( 'my_writable', False ) )
else:
my_writable = True
- query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=False )
+ query = rmm.get_query_for_setting_metadata_on_repositories( my_writable=my_writable, order=False )
# First reset metadata on all repositories of type repository_dependency_definition.
for repository in query:
encoded_id = trans.security.encode_id( repository.id )
@@ -481,7 +481,7 @@
log.debug( "Skipping repository with id %s because it is in encoded_ids_to_skip %s" % \
( str( repository.id ), str( encoded_ids_to_skip ) ) )
elif repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids:
- results = handle_repository( trans, repository, results )
+ results = handle_repository( trans, rmm, repository, results )
# Now reset metadata on all remaining repositories.
for repository in query:
encoded_id = trans.security.encode_id( repository.id )
@@ -489,7 +489,7 @@
log.debug( "Skipping repository with id %s because it is in encoded_ids_to_skip %s" % \
( str( repository.id ), str( encoded_ids_to_skip ) ) )
elif repository.type != rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids:
- results = handle_repository( trans, repository, results )
+ results = handle_repository( trans, rmm, repository, results )
stop_time = strftime( "%Y-%m-%d %H:%M:%S" )
results[ 'stop_time' ] = stop_time
return json.dumps( results, sort_keys=True, indent=4 )
@@ -511,10 +511,9 @@
results = dict( start_time=start_time,
repository_status=[] )
try:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
invalid_file_tups, metadata_dict = \
- rmm.reset_all_metadata_on_repository_in_tool_shed( trans.user,
- trans.security.encode_id( repository.id ) )
+ rmm.reset_all_metadata_on_repository_in_tool_shed( trans.security.encode_id( repository.id ) )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
invalid_file_tups,
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/tool_shed/controllers/admin.py
--- a/lib/galaxy/webapps/tool_shed/controllers/admin.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/admin.py
@@ -348,13 +348,16 @@
@web.expose
@web.require_admin
def reset_metadata_on_selected_repositories_in_tool_shed( self, trans, **kwd ):
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
if 'reset_metadata_on_selected_repositories_button' in kwd:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
- message, status = rmm.reset_metadata_on_selected_repositories( trans.user, **kwd )
+ message, status = rmm.reset_metadata_on_selected_repositories( **kwd )
else:
message = util.restore_text( kwd.get( 'message', '' ) )
status = kwd.get( 'status', 'done' )
- repositories_select_field = suc.build_repository_ids_select_field( trans )
+ repositories_select_field = rmm.build_repository_ids_select_field( name='repository_ids',
+ multiple=True,
+ display='checkboxes',
+ my_writable=False )
return trans.fill_template( '/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako',
repositories_select_field=repositories_select_field,
message=message,
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/tool_shed/controllers/hg.py
--- a/lib/galaxy/webapps/tool_shed/controllers/hg.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/hg.py
@@ -48,8 +48,8 @@
repo = hg.repository( ui.ui(), repository.repo_path( trans.app ) )
update_repository( repo, ctx_rev=None )
# Set metadata using the repository files on disk.
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
- error_message, status = rmm.set_repository_metadata( trans.request.host, trans.user, repository )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
+ error_message, status = rmm.set_repository_metadata( trans.request.host, repository )
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 ) )
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/tool_shed/controllers/repository.py
--- a/lib/galaxy/webapps/tool_shed/controllers/repository.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py
@@ -2753,9 +2753,9 @@
def reset_all_metadata( self, trans, id, **kwd ):
"""Reset all metadata on the complete changelog for a single repository in the tool shed."""
# This method is called only from the ~/templates/webapps/tool_shed/repository/manage_repository.mako template.
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
invalid_file_tups, metadata_dict = \
- rmm.reset_all_metadata_on_repository_in_tool_shed( trans.user, id, **kwd )
+ rmm.reset_all_metadata_on_repository_in_tool_shed( id, **kwd )
if invalid_file_tups:
repository = suc.get_repository_in_tool_shed( trans.app, id )
message = tool_util.generate_message_for_invalid_tools( trans.app,
@@ -2774,13 +2774,16 @@
@web.expose
def reset_metadata_on_my_writable_repositories_in_tool_shed( self, trans, **kwd ):
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
if 'reset_metadata_on_selected_repositories_button' in kwd:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
- message, status = rmm.reset_metadata_on_selected_repositories( trans.user, **kwd )
+ message, status = rmm.reset_metadata_on_selected_repositories( **kwd )
else:
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
- repositories_select_field = suc.build_repository_ids_select_field( trans, my_writable=True )
+ repositories_select_field = rmm.build_repository_ids_select_field( name='repository_ids',
+ multiple=True,
+ display='checkboxes',
+ my_writable=True )
return trans.fill_template( '/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako',
repositories_select_field=repositories_select_field,
message=message,
@@ -2840,9 +2843,8 @@
if tip == repository.tip( trans.app ):
message += 'No changes to repository. '
else:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
status, error_message = rmm.set_repository_metadata_due_to_new_tip( trans.request.host,
- trans.user,
repository,
**kwd )
if error_message:
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/galaxy/webapps/tool_shed/controllers/upload.py
--- a/lib/galaxy/webapps/tool_shed/controllers/upload.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/upload.py
@@ -262,10 +262,9 @@
( len( files_to_remove ), upload_point )
else:
message += " %d files were removed from the repository root. " % len( files_to_remove )
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
status, error_message = \
rmm.set_repository_metadata_due_to_new_tip( trans.request.host,
- trans.user,
repository,
content_alert_str=content_alert_str,
**kwd )
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/capsule/capsule_manager.py
--- a/lib/tool_shed/capsule/capsule_manager.py
+++ b/lib/tool_shed/capsule/capsule_manager.py
@@ -727,9 +727,8 @@
results_dict[ 'ok' ] = False
results_dict[ 'error_message' ] += error_message
try:
- rmm = repository_metadata_manager.RepositoryMetadataManager( self.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( self.app, self.user )
status, error_message = rmm.set_repository_metadata_due_to_new_tip( self.host,
- self.user,
repository,
content_alert_str=content_alert_str )
if error_message:
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/install_manager.py
--- a/lib/tool_shed/galaxy_install/install_manager.py
+++ b/lib/tool_shed/galaxy_install/install_manager.py
@@ -33,6 +33,7 @@
from tool_shed.galaxy_install.tool_dependencies.recipe.install_environment import InstallEnvironment
from tool_shed.galaxy_install.tool_dependencies.recipe.recipe_manager import StepManager
from tool_shed.galaxy_install.tool_dependencies.recipe.recipe_manager import TagManager
+from tool_shed.galaxy_install.tools import tool_panel_manager
log = logging.getLogger( __name__ )
@@ -535,7 +536,8 @@
self.app.config.shed_tool_data_table_config,
persist=True )
if 'tools' in metadata_dict:
- tool_panel_dict = tool_util.generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section )
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
+ tool_panel_dict = tpm.generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section )
sample_files = metadata_dict.get( 'sample_files', [] )
tool_index_sample_files = tool_util.get_tool_index_sample_files( sample_files )
tool_util.copy_sample_files( self.app, tool_index_sample_files, tool_path=tool_path )
@@ -555,16 +557,18 @@
sample_files_copied )
# Copy remaining sample files included in the repository to the ~/tool-data directory of the
# local Galaxy instance.
- tool_util.copy_sample_files( self.app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied )
- tool_util.add_to_tool_panel( app=self.app,
- repository_name=tool_shed_repository.name,
- repository_clone_url=repository_clone_url,
- changeset_revision=tool_shed_repository.installed_changeset_revision,
- repository_tools_tups=repository_tools_tups,
- owner=tool_shed_repository.owner,
- shed_tool_conf=shed_tool_conf,
- tool_panel_dict=tool_panel_dict,
- new_install=True )
+ tool_util.copy_sample_files( self.app,
+ sample_files,
+ tool_path=tool_path,
+ sample_files_copied=sample_files_copied )
+ tpm.add_to_tool_panel( repository_name=tool_shed_repository.name,
+ repository_clone_url=repository_clone_url,
+ changeset_revision=tool_shed_repository.installed_changeset_revision,
+ repository_tools_tups=repository_tools_tups,
+ owner=tool_shed_repository.owner,
+ shed_tool_conf=shed_tool_conf,
+ tool_panel_dict=tool_panel_dict,
+ new_install=True )
if 'data_manager' in metadata_dict:
new_data_managers = data_manager_util.install_data_managers( self.app,
self.app.config.shed_data_manager_config_file,
@@ -644,10 +648,11 @@
tool_shed_url = installation_dict[ 'tool_shed_url' ]
# Handle contained tools.
if includes_tools_for_display_in_tool_panel and ( new_tool_panel_section_label or tool_panel_section_id ):
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
tool_panel_section_key, tool_section = \
- tool_util.handle_tool_panel_section( self.app.toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_section( self.app.toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
else:
tool_panel_section_key = None
tool_section = None
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/installed_repository_manager.py
--- a/lib/tool_shed/galaxy_install/installed_repository_manager.py
+++ b/lib/tool_shed/galaxy_install/installed_repository_manager.py
@@ -11,11 +11,11 @@
from tool_shed.util import datatype_util
from tool_shed.util import shed_util_common as suc
from tool_shed.util import tool_dependency_util
-from tool_shed.util import tool_util
from tool_shed.util import xml_util
from galaxy.model.orm import and_
from tool_shed.galaxy_install.repository_dependencies import repository_dependency_manager
+from tool_shed.galaxy_install.tools import tool_panel_manager
log = logging.getLogger( __name__ )
@@ -80,19 +80,19 @@
repository.deleted = False
repository.status = self.install_model.ToolShedRepository.installation_status.INSTALLED
if repository.includes_tools_for_display_in_tool_panel:
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
metadata = repository.metadata
repository_tools_tups = suc.get_repository_tools_tups( self.app, metadata )
# Reload tools into the appropriate tool panel section.
tool_panel_dict = repository.metadata[ 'tool_panel_section' ]
- tool_util.add_to_tool_panel( self.app,
- repository.name,
- repository_clone_url,
- repository.installed_changeset_revision,
- repository_tools_tups,
- repository.owner,
- shed_tool_conf,
- tool_panel_dict,
- new_install=False )
+ tpm.add_to_tool_panel( repository.name,
+ repository_clone_url,
+ repository.installed_changeset_revision,
+ repository_tools_tups,
+ repository.owner,
+ shed_tool_conf,
+ tool_panel_dict,
+ new_install=False )
if repository.includes_data_managers:
tp, data_manager_relative_install_dir = repository.get_tool_relative_path( self.app )
# Hack to add repository.name here, which is actually the root of the installed repository
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py
--- a/lib/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py
+++ b/lib/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py
@@ -3,6 +3,7 @@
from galaxy import util
from galaxy.util import inflector
+from galaxy.web.form_builder import SelectField
from tool_shed.metadata import metadata_generator
@@ -19,6 +20,32 @@
super( InstalledRepositoryMetadataManager, self ).__init__( app )
self.app = app
+ def build_repository_ids_select_field( self, name='repository_ids', multiple=True, display='checkboxes' ):
+ """Generate the current list of repositories for resetting metadata."""
+ repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
+ query = self.get_query_for_setting_metadata_on_repositories( order=True )
+ for repository in query:
+ owner = str( repository.owner )
+ option_label = '%s (%s)' % ( str( repository.name ), owner )
+ option_value = '%s' % self.app.security.encode_id( repository.id )
+ repositories_select_field.add_option( option_label, option_value )
+ return repositories_select_field
+
+ def get_query_for_setting_metadata_on_repositories( self, order=True ):
+ """
+ Return a query containing repositories for resetting metadata. The order parameter
+ is used for displaying the list of repositories ordered alphabetically for display on
+ a page. When called from the Galaxy API, order is False.
+ """
+ if order:
+ return self.app.install_model.context.query( self.app.install_model.ToolShedRepository ) \
+ .filter( self.app.install_model.ToolShedRepository.table.c.uninstalled == False ) \
+ .order_by( self.app.install_model.ToolShedRepository.table.c.name,
+ self.app.install_model.ToolShedRepository.table.c.owner )
+ else:
+ return self.app.install_model.context.query( self.app.install_model.ToolShedRepository ) \
+ .filter( self.app.install_model.ToolShedRepository.table.c.uninstalled == False )
+
def reset_all_metadata_on_installed_repository( self, id ):
"""Reset all metadata on a single tool shed repository installed into a Galaxy instance."""
invalid_file_tups = []
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/repair_repository_manager.py
--- a/lib/tool_shed/galaxy_install/repair_repository_manager.py
+++ b/lib/tool_shed/galaxy_install/repair_repository_manager.py
@@ -5,13 +5,14 @@
from tool_shed.galaxy_install import install_manager
from tool_shed.galaxy_install.repository_dependencies import repository_dependency_manager
+from tool_shed.galaxy_install.tools import tool_panel_manager
from tool_shed.util import common_util
from tool_shed.util import container_util
from tool_shed.util import shed_util_common as suc
from tool_shed.util import repository_maintenance_util
from tool_shed.util import tool_dependency_util
-from tool_shed.util import tool_util
+
class RepairRepositoryManager():
@@ -119,10 +120,11 @@
tool_panel_section_id = section_dict[ 'id' ]
tool_panel_section_name = section_dict[ 'name' ]
if tool_panel_section_id:
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
tool_panel_section_key, tool_panel_section = \
- tool_util.get_or_create_tool_section( self.app.toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=tool_panel_section_name )
+ tpm.get_or_create_tool_section( self.app.toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=tool_panel_section_name )
else:
tool_dependencies = None
repo_info_dict = repository_maintenance_util.create_repo_info_dict( app=self.app,
@@ -156,15 +158,17 @@
log.debug( error_message )
repair_dict [ repository.name ] = error_message
elif repository.status not in [ self.app.install_model.ToolShedRepository.installation_status.INSTALLED ]:
- shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( self.app, repository )
+ shed_tool_conf, tool_path, relative_install_dir = \
+ suc.get_tool_panel_config_tool_path_install_dir( self.app, repository )
# Reset the repository attributes to the New state for installation.
if metadata:
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
tool_section, tool_panel_section_key = \
- tool_util.handle_tool_panel_selection( self.app.toolbox,
- metadata,
- no_changes_checked=True,
- tool_panel_section_id=None,
- new_tool_panel_section_label=None )
+ tpm.handle_tool_panel_selection( self.app.toolbox,
+ metadata,
+ no_changes_checked=True,
+ tool_panel_section_id=None,
+ new_tool_panel_section_label=None )
else:
# The tools will be loaded outside of any sections in the tool panel.
tool_panel_section_key = None
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
--- a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
+++ b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
@@ -10,11 +10,12 @@
from galaxy.util import asbool
+from tool_shed.galaxy_install.tools import tool_panel_manager
+
from tool_shed.util import common_util
from tool_shed.util import container_util
from tool_shed.util import encoding_util
from tool_shed.util import shed_util_common as suc
-from tool_shed.util import tool_util
log = logging.getLogger( __name__ )
@@ -216,19 +217,20 @@
if can_update_db_record:
# The database record for the tool shed repository currently being processed can be updated.
# Get the repository metadata to see where it was previously located in the tool panel.
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
if repository_db_record and repository_db_record.metadata:
tool_section, tool_panel_section_key = \
- tool_util.handle_tool_panel_selection( toolbox=self.app.toolbox,
- metadata=repository_db_record.metadata,
- no_changes_checked=no_changes_checked,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_selection( toolbox=self.app.toolbox,
+ metadata=repository_db_record.metadata,
+ no_changes_checked=no_changes_checked,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
else:
# We're installing a new tool shed repository that does not yet have a database record.
tool_panel_section_key, tool_section = \
- tool_util.handle_tool_panel_section( self.app.toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_section( self.app.toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
tool_shed_repository = \
suc.create_or_update_tool_shed_repository( app=self.app,
name=name,
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/tool_migration_manager.py
--- a/lib/tool_shed/galaxy_install/tool_migration_manager.py
+++ b/lib/tool_shed/galaxy_install/tool_migration_manager.py
@@ -14,6 +14,7 @@
from tool_shed.galaxy_install import install_manager
from tool_shed.galaxy_install.metadata.installed_repository_metadata_manager import InstalledRepositoryMetadataManager
+from tool_shed.galaxy_install.tools import tool_panel_manager
from tool_shed.util import basic_util
from tool_shed.util import common_util
@@ -30,23 +31,31 @@
class ToolMigrationManager( object ):
- def __init__( self, app, latest_migration_script_number, tool_shed_install_config, migrated_tools_config, install_dependencies ):
+ def __init__( self, app, latest_migration_script_number, tool_shed_install_config, migrated_tools_config,
+ install_dependencies ):
"""
- Check tool settings in tool_shed_install_config and install all repositories that are not already installed. The tool
- panel configuration file is the received migrated_tools_config, which is the reserved file named migrated_tools_conf.xml.
+ Check tool settings in tool_shed_install_config and install all repositories
+ that are not already installed. The tool panel configuration file is the received
+ migrated_tools_config, which is the reserved file named migrated_tools_conf.xml.
"""
self.app = app
self.toolbox = self.app.toolbox
self.migrated_tools_config = migrated_tools_config
- # If install_dependencies is True but tool_dependency_dir is not set, do not attempt to install but print informative error message.
+ self.tpm = tool_panel_manager.ToolPanelManager( self.app )
+ # If install_dependencies is True but tool_dependency_dir is not set, do not attempt
+ # to install but print informative error message.
if install_dependencies and app.config.tool_dependency_dir is None:
- message = 'You are attempting to install tool dependencies but do not have a value for "tool_dependency_dir" set in your universe_wsgi.ini '
- message += 'file. Set this location value to the path where you want tool dependencies installed and rerun the migration script.'
+ message = 'You are attempting to install tool dependencies but do not have a value '
+ message += 'for "tool_dependency_dir" set in your universe_wsgi.ini file. Set this '
+ message += 'location value to the path where you want tool dependencies installed and '
+ message += 'rerun the migration script.'
raise Exception( message )
- # Get the local non-shed related tool panel configs (there can be more than one, and the default name is tool_conf.xml).
+ # Get the local non-shed related tool panel configs (there can be more than one, and the
+ # default name is tool_conf.xml).
self.proprietary_tool_confs = self.non_shed_tool_panel_configs
self.proprietary_tool_panel_elems = self.get_proprietary_tool_panel_elems( latest_migration_script_number )
- # Set the location where the repositories will be installed by retrieving the tool_path setting from migrated_tools_config.
+ # Set the location where the repositories will be installed by retrieving the tool_path
+ # setting from migrated_tools_config.
tree, error_message = xml_util.parse_xml( migrated_tools_config )
if tree is None:
print error_message
@@ -66,21 +75,24 @@
self.tool_shed = common_util.remove_protocol_and_port_from_tool_shed_url( self.tool_shed_url )
self.repository_owner = common_util.REPOSITORY_OWNER
index, self.shed_config_dict = suc.get_shed_tool_conf_dict( app, self.migrated_tools_config )
- # Since tool migration scripts can be executed any number of times, we need to make sure the appropriate tools are defined in
- # tool_conf.xml. If no tools associated with the migration stage are defined, no repositories will be installed on disk.
- # The default behavior is that the tool shed is down.
+ # Since tool migration scripts can be executed any number of times, we need to
+ # make sure the appropriate tools are defined in tool_conf.xml. If no tools
+ # associated with the migration stage are defined, no repositories will be installed
+ # on disk. The default behavior is that the tool shed is down.
tool_shed_accessible = False
tool_panel_configs = common_util.get_non_shed_tool_panel_configs( app )
if tool_panel_configs:
# The missing_tool_configs_dict contents are something like:
# {'emboss_antigenic.xml': [('emboss', '5.0.0', 'package', '\nreadme blah blah blah\n')]}
- tool_shed_accessible, missing_tool_configs_dict = common_util.check_for_missing_tools( app,
- tool_panel_configs,
- latest_migration_script_number )
+ tool_shed_accessible, missing_tool_configs_dict = \
+ common_util.check_for_missing_tools( app,
+ tool_panel_configs,
+ latest_migration_script_number )
else:
- # It doesn't matter if the tool shed is accessible since there are no migrated tools defined in the local Galaxy instance, but
- # we have to set the value of tool_shed_accessible to True so that the value of migrate_tools.version can be correctly set in
- # the database.
+ # It doesn't matter if the tool shed is accessible since there are no migrated
+ # tools defined in the local Galaxy instance, but we have to set the value of
+ # tool_shed_accessible to True so that the value of migrate_tools.version can
+ # be correctly set in the database.
tool_shed_accessible = True
missing_tool_configs_dict = odict()
if tool_shed_accessible:
@@ -93,15 +105,18 @@
if missing_tool_configs_dict:
for proprietary_tool_conf in self.proprietary_tool_confs:
# Create a backup of the tool configuration in the un-migrated state.
- shutil.copy( proprietary_tool_conf, '%s-pre-stage-%04d' % ( proprietary_tool_conf, latest_migration_script_number ) )
+ shutil.copy( proprietary_tool_conf, '%s-pre-stage-%04d' % ( proprietary_tool_conf,
+ latest_migration_script_number ) )
for repository_elem in root:
# Make sure we have a valid repository tag.
if self.__is_valid_repository_tag( repository_elem ):
- # Get all repository dependencies for the repository defined by the current repository_elem. Repository dependency
- # definitions contained in tool shed repositories with migrated tools must never define a relationship to a repository
- # dependency that contains a tool. The repository dependency can only contain items that are not loaded into the Galaxy
- # tool panel (e.g., tool dependency definitions, custom datatypes, etc). This restriction must be followed down the
- # entire dependency hierarchy.
+ # Get all repository dependencies for the repository defined by the
+ # current repository_elem. Repository dependency definitions contained
+ # in tool shed repositories with migrated tools must never define a
+ # relationship to a repository dependency that contains a tool. The
+ # repository dependency can only contain items that are not loaded into
+ # the Galaxy tool panel (e.g., tool dependency definitions, custom datatypes,
+ # etc). This restriction must be followed down the entire dependency hierarchy.
name = repository_elem.get( 'name' )
changeset_revision = repository_elem.get( 'changeset_revision' )
tool_shed_accessible, repository_dependencies_dict = \
@@ -110,30 +125,38 @@
name,
self.repository_owner,
changeset_revision )
- # Make sure all repository dependency records exist (as tool_shed_repository table rows) in the Galaxy database.
- created_tool_shed_repositories = self.create_or_update_tool_shed_repository_records( name,
- changeset_revision,
- repository_dependencies_dict )
+ # Make sure all repository dependency records exist (as tool_shed_repository
+ # table rows) in the Galaxy database.
+ created_tool_shed_repositories = \
+ self.create_or_update_tool_shed_repository_records( name,
+ changeset_revision,
+ repository_dependencies_dict )
# Order the repositories for proper installation. This process is similar to the
# process used when installing tool shed repositories, but does not handle managing
# tool panel sections and other components since repository dependency definitions
# contained in tool shed repositories with migrated tools must never define a relationship
# to a repository dependency that contains a tool.
- ordered_tool_shed_repositories = self.order_repositories_for_installation( created_tool_shed_repositories,
- repository_dependencies_dict )
+ ordered_tool_shed_repositories = \
+ self.order_repositories_for_installation( created_tool_shed_repositories,
+ repository_dependencies_dict )
for tool_shed_repository in ordered_tool_shed_repositories:
- is_repository_dependency = self.__is_repository_dependency( name, changeset_revision, tool_shed_repository )
+ is_repository_dependency = self.__is_repository_dependency( name,
+ changeset_revision,
+ tool_shed_repository )
self.install_repository( repository_elem,
tool_shed_repository,
install_dependencies,
is_repository_dependency=is_repository_dependency )
else:
- message = "\nNo tools associated with migration stage %s are defined in your " % str( latest_migration_script_number )
- message += "file%s named %s,\nso no repositories will be installed on disk.\n" % ( plural, file_names )
+ message = "\nNo tools associated with migration stage %s are defined in your " % \
+ str( latest_migration_script_number )
+ message += "file%s named %s,\nso no repositories will be installed on disk.\n" % \
+ ( plural, file_names )
print message
else:
- message = "\nThe main Galaxy tool shed is not currently available, so skipped migration stage %s.\n" % str( latest_migration_script_number )
+ message = "\nThe main Galaxy tool shed is not currently available, so skipped migration stage %s.\n" % \
+ str( latest_migration_script_number )
message += "Try again later.\n"
print message
@@ -354,16 +377,21 @@
repo_install_dir = relative_install_dir
if not is_repository_dependency:
for tool_elem in repository_elem:
- # The tool_elem looks something like this: <tool id="EMBOSS: antigenic1" version="5.0.0" file="emboss_antigenic.xml" />
+ # The tool_elem looks something like this:
+ # <tool id="EMBOSS: antigenic1" version="5.0.0" file="emboss_antigenic.xml" />
tool_config = tool_elem.get( 'file' )
guid = self.get_guid( repository_clone_url, relative_install_dir, tool_config )
# See if tool_config is defined inside of a section in self.proprietary_tool_panel_elems.
is_displayed, tool_sections = self.get_containing_tool_sections( tool_config )
if is_displayed:
tool_panel_dict_for_tool_config = \
- tool_util.generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=tool_sections )
+ self.tpm.generate_tool_panel_dict_for_tool_config( guid,
+ tool_config,
+ tool_sections=tool_sections )
# The tool-panel_dict has the following structure.
- # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>,
+ # {<Tool guid> : [{ tool_config : <tool_config_file>,
+ # id: <ToolSection id>,
+ # version : <ToolSection version>,
# name : <TooSection name>}]}
for k, v in tool_panel_dict_for_tool_config.items():
tool_panel_dict_for_display[ k ] = v
@@ -433,15 +461,14 @@
tool_path=self.tool_path,
sample_files_copied=sample_files_copied )
if not is_repository_dependency:
- tool_util.add_to_tool_panel( self.app,
- tool_shed_repository.name,
- repository_clone_url,
- tool_shed_repository.installed_changeset_revision,
- repository_tools_tups,
- self.repository_owner,
- self.migrated_tools_config,
- tool_panel_dict=tool_panel_dict_for_display,
- new_install=True )
+ self.tpm.add_to_tool_panel( tool_shed_repository.name,
+ repository_clone_url,
+ tool_shed_repository.installed_changeset_revision,
+ repository_tools_tups,
+ self.repository_owner,
+ self.migrated_tools_config,
+ tool_panel_dict=tool_panel_dict_for_display,
+ new_install=True )
if install_dependencies and tool_dependencies and has_tool_dependencies:
# Install tool dependencies.
suc.update_tool_shed_repository_status( self.app,
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/galaxy_install/tools/tool_panel_manager.py
--- /dev/null
+++ b/lib/tool_shed/galaxy_install/tools/tool_panel_manager.py
@@ -0,0 +1,465 @@
+import logging
+import os
+
+import galaxy.tools
+from galaxy.tools.search import ToolBoxSearch
+from xml.etree import ElementTree as XmlET
+
+from tool_shed.util import basic_util
+from tool_shed.util import common_util
+from tool_shed.util import shed_util_common as suc
+from tool_shed.util import xml_util
+
+log = logging.getLogger( __name__ )
+
+
+class ToolPanelManager( object ):
+
+ def __init__( self, app ):
+ self.app = app
+
+ def add_to_shed_tool_config( self, shed_tool_conf_dict, elem_list ):
+ # A tool shed repository is being installed so change the shed_tool_conf file. Parse the
+ # config file to generate the entire list of config_elems instead of using the in-memory list
+ # since it will be a subset of the entire list if one or more repositories have been deactivated.
+ shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
+ tool_path = shed_tool_conf_dict[ 'tool_path' ]
+ config_elems = []
+ tree, error_message = xml_util.parse_xml( shed_tool_conf )
+ if tree:
+ root = tree.getroot()
+ for elem in root:
+ config_elems.append( elem )
+ # Add the elements to the in-memory list of config_elems.
+ for elem_entry in elem_list:
+ config_elems.append( elem_entry )
+ # Persist the altered shed_tool_config file.
+ suc.config_elems_to_xml_file( self.app, config_elems, shed_tool_conf, tool_path )
+
+ def add_to_tool_panel( self, repository_name, repository_clone_url, changeset_revision, repository_tools_tups, owner,
+ shed_tool_conf, tool_panel_dict, new_install=True ):
+ """A tool shed repository is being installed or updated so handle tool panel alterations accordingly."""
+ # We need to change the in-memory version and the file system version of the shed_tool_conf file.
+ index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( self.app, shed_tool_conf )
+ tool_path = shed_tool_conf_dict[ 'tool_path' ]
+ # Generate the list of ElementTree Element objects for each section or tool.
+ elem_list = self.generate_tool_panel_elem_list( repository_name,
+ repository_clone_url,
+ changeset_revision,
+ tool_panel_dict,
+ repository_tools_tups,
+ owner=owner )
+ if new_install:
+ # Add the new elements to the shed_tool_conf file on disk.
+ self.add_to_shed_tool_config( shed_tool_conf_dict, elem_list )
+ # Use the new elements to add entries to the
+ config_elems = shed_tool_conf_dict[ 'config_elems' ]
+ for config_elem in elem_list:
+ # Add the new elements to the in-memory list of config_elems.
+ config_elems.append( config_elem )
+ # Load the tools into the in-memory tool panel.
+ if config_elem.tag == 'section':
+ self.app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True )
+ elif config_elem.tag == 'workflow':
+ self.app.toolbox.load_workflow_tag_set( config_elem,
+ self.app.toolbox.tool_panel,
+ self.app.toolbox.integrated_tool_panel,
+ load_panel_dict=True )
+ elif config_elem.tag == 'tool':
+ guid = config_elem.get( 'guid' )
+ self.app.toolbox.load_tool_tag_set( config_elem,
+ self.app.toolbox.tool_panel,
+ self.app.toolbox.integrated_tool_panel,
+ tool_path,
+ load_panel_dict=True,
+ guid=guid )
+ # Replace the old list of in-memory config_elems with the new list for this shed_tool_conf_dict.
+ shed_tool_conf_dict[ 'config_elems' ] = config_elems
+ self.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
+ if self.app.config.update_integrated_tool_panel:
+ # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
+ self.app.toolbox.write_integrated_tool_panel_config_file()
+ self.app.toolbox_search = ToolBoxSearch( self.app.toolbox )
+
+ def generate_tool_panel_dict_for_new_install( self, tool_dicts, tool_section=None ):
+ """
+ When installing a repository that contains tools, all tools must currently be defined
+ within the same tool section in the tool panel or outside of any sections.
+ """
+ tool_panel_dict = {}
+ if tool_section:
+ section_id = tool_section.id
+ section_name = tool_section.name
+ section_version = tool_section.version or ''
+ else:
+ section_id = ''
+ section_name = ''
+ section_version = ''
+ for tool_dict in tool_dicts:
+ if tool_dict.get( 'add_to_tool_panel', True ):
+ guid = tool_dict[ 'guid' ]
+ tool_config = tool_dict[ 'tool_config' ]
+ tool_section_dict = dict( tool_config=tool_config, id=section_id, name=section_name, version=section_version )
+ if guid in tool_panel_dict:
+ tool_panel_dict[ guid ].append( tool_section_dict )
+ else:
+ tool_panel_dict[ guid ] = [ tool_section_dict ]
+ return tool_panel_dict
+
+ def generate_tool_panel_dict_for_tool_config( self, guid, tool_config, tool_sections=None ):
+ """
+ Create a dictionary of the following type for a single tool config file name.
+ The intent is to call this method for every tool config in a repository and
+ append each of these as entries to a tool panel dictionary for the repository.
+ This enables each tool to be loaded into a different section in the tool panel.
+ {<Tool guid> :
+ [{ tool_config : <tool_config_file>,
+ id: <ToolSection id>,
+ version : <ToolSection version>,
+ name : <TooSection name>}]}
+ """
+ tool_panel_dict = {}
+ file_name = basic_util.strip_path( tool_config )
+ tool_section_dicts = self. generate_tool_section_dicts( tool_config=file_name,
+ tool_sections=tool_sections )
+ tool_panel_dict[ guid ] = tool_section_dicts
+ return tool_panel_dict
+
+ def generate_tool_panel_elem_list( self, repository_name, repository_clone_url, changeset_revision,
+ tool_panel_dict, repository_tools_tups, owner='' ):
+ """Generate a list of ElementTree Element objects for each section or tool."""
+ elem_list = []
+ tool_elem = None
+ cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url( repository_clone_url )
+ if not owner:
+ owner = suc.get_repository_owner( cleaned_repository_clone_url )
+ tool_shed = cleaned_repository_clone_url.split( '/repos/' )[ 0 ].rstrip( '/' )
+ for guid, tool_section_dicts in tool_panel_dict.items():
+ for tool_section_dict in tool_section_dicts:
+ tool_section = None
+ inside_section = False
+ section_in_elem_list = False
+ if tool_section_dict[ 'id' ]:
+ inside_section = True
+ # Create a new section element only if we haven't already created it.
+ for index, elem in enumerate( elem_list ):
+ if elem.tag == 'section':
+ section_id = elem.get( 'id', None )
+ if section_id == tool_section_dict[ 'id' ]:
+ section_in_elem_list = True
+ tool_section = elem
+ break
+ if tool_section is None:
+ tool_section = self.generate_tool_section_element_from_dict( tool_section_dict )
+ # Find the tuple containing the current guid from the list of repository_tools_tups.
+ for repository_tool_tup in repository_tools_tups:
+ tool_file_path, tup_guid, tool = repository_tool_tup
+ if tup_guid == guid:
+ break
+ if inside_section:
+ tool_elem = suc.generate_tool_elem( tool_shed,
+ repository_name,
+ changeset_revision,
+ owner,
+ tool_file_path,
+ tool,
+ tool_section )
+ else:
+ tool_elem = suc.generate_tool_elem( tool_shed,
+ repository_name,
+ changeset_revision,
+ owner,
+ tool_file_path,
+ tool,
+ None )
+ if inside_section:
+ if section_in_elem_list:
+ elem_list[ index ] = tool_section
+ else:
+ elem_list.append( tool_section )
+ else:
+ elem_list.append( tool_elem )
+ return elem_list
+
+ def generate_tool_section_dicts( self, tool_config=None, tool_sections=None ):
+ tool_section_dicts = []
+ if tool_config is None:
+ tool_config = ''
+ if tool_sections:
+ for tool_section in tool_sections:
+ # The value of tool_section will be None if the tool is displayed outside
+ # of any sections in the tool panel.
+ if tool_section:
+ section_id = tool_section.id or ''
+ section_version = tool_section.version or ''
+ section_name = tool_section.name or ''
+ else:
+ section_id = ''
+ section_version = ''
+ section_name = ''
+ tool_section_dicts.append( dict( tool_config=tool_config,
+ id=section_id,
+ version=section_version,
+ name=section_name ) )
+ else:
+ tool_section_dicts.append( dict( tool_config=tool_config, id='', version='', name='' ) )
+ return tool_section_dicts
+
+ def generate_tool_section_element_from_dict( self, tool_section_dict ):
+ # The value of tool_section_dict looks like the following.
+ # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}
+ if tool_section_dict[ 'id' ]:
+ # Create a new tool section.
+ tool_section = XmlET.Element( 'section' )
+ tool_section.attrib[ 'id' ] = tool_section_dict[ 'id' ]
+ tool_section.attrib[ 'name' ] = tool_section_dict[ 'name' ]
+ tool_section.attrib[ 'version' ] = tool_section_dict[ 'version' ]
+ else:
+ tool_section = None
+ return tool_section
+
+ def get_or_create_tool_section( self, toolbox, tool_panel_section_id, new_tool_panel_section_label=None ):
+ tool_panel_section_key = str( tool_panel_section_id )
+ if tool_panel_section_key in toolbox.tool_panel:
+ # Appending a tool to an existing section in toolbox.tool_panel
+ tool_section = toolbox.tool_panel[ tool_panel_section_key ]
+ log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) )
+ else:
+ # Appending a new section to toolbox.tool_panel
+ if new_tool_panel_section_label is None:
+ # This might add an ugly section label to the tool panel, but, oh well...
+ new_tool_panel_section_label = tool_panel_section_id
+ elem = XmlET.Element( 'section' )
+ elem.attrib[ 'name' ] = new_tool_panel_section_label
+ elem.attrib[ 'id' ] = tool_panel_section_id
+ elem.attrib[ 'version' ] = ''
+ tool_section = galaxy.tools.ToolSection( elem )
+ toolbox.tool_panel[ tool_panel_section_key ] = tool_section
+ log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) )
+ return tool_panel_section_key, tool_section
+
+ def handle_tool_panel_section( self, toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ):
+ """Return a ToolSection object retrieved from the current in-memory tool_panel."""
+ # If tool_panel_section_id is received, the section exists in the tool panel. In this
+ # case, the value of the received tool_panel_section_id must be the id retrieved from a
+ # tool panel config (e.g., tool_conf.xml, which may have getext). If new_tool_panel_section_label
+ # is received, a new section will be added to the tool panel.
+ if new_tool_panel_section_label:
+ section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) )
+ tool_panel_section_key, tool_section = \
+ self.get_or_create_tool_section( toolbox,
+ tool_panel_section_id=section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
+ elif tool_panel_section_id:
+ tool_panel_section_key = str( tool_panel_section_id )
+ tool_section = toolbox.tool_panel[ tool_panel_section_key ]
+ else:
+ return None, None
+ return tool_panel_section_key, tool_section
+
+ def handle_tool_panel_selection( self, toolbox, metadata, no_changes_checked, tool_panel_section_id,
+ new_tool_panel_section_label ):
+ """
+ Handle the selected tool panel location for loading tools included in tool shed
+ repositories when installing or reinstalling them.
+ """
+ # Get the location in the tool panel in which each tool was originally loaded.
+ tool_section = None
+ tool_panel_section_key = None
+ if 'tools' in metadata:
+ # This forces everything to be loaded into the same section (or no section)
+ # in the tool panel.
+ if no_changes_checked:
+ # Make sure the no_changes check box overrides the new_tool_panel_section_label
+ # if the user checked the check box and entered something into the field.
+ new_tool_panel_section_label = None
+ if 'tool_panel_section' in metadata:
+ tool_panel_dict = metadata[ 'tool_panel_section' ]
+ if not tool_panel_dict:
+ tool_panel_dict = self.generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
+ else:
+ tool_panel_dict = self.generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
+ if tool_panel_dict:
+ # The tool_panel_dict is empty when tools exist but are not installed into a tool panel section.
+ tool_section_dicts = tool_panel_dict[ tool_panel_dict.keys()[ 0 ] ]
+ tool_section_dict = tool_section_dicts[ 0 ]
+ original_section_id = tool_section_dict[ 'id' ]
+ original_section_name = tool_section_dict[ 'name' ]
+ if original_section_id:
+ tool_panel_section_key, tool_section = \
+ self.get_or_create_tool_section( toolbox,
+ tool_panel_section_id=original_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
+ else:
+ # The user elected to change the tool panel section to contain the tools.
+ tool_panel_section_key, tool_section = \
+ self.handle_tool_panel_section( toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
+ return tool_section, tool_panel_section_key
+
+ def remove_from_shed_tool_config( self, shed_tool_conf_dict, guids_to_remove ):
+ # A tool shed repository is being uninstalled so change the shed_tool_conf file.
+ # Parse the config file to generate the entire list of config_elems instead of
+ # using the in-memory list since it will be a subset of the entire list if one
+ # or more repositories have been deactivated.
+ shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
+ tool_path = shed_tool_conf_dict[ 'tool_path' ]
+ config_elems = []
+ tree, error_message = xml_util.parse_xml( shed_tool_conf )
+ if tree:
+ root = tree.getroot()
+ for elem in root:
+ config_elems.append( elem )
+ config_elems_to_remove = []
+ for config_elem in config_elems:
+ if config_elem.tag == 'section':
+ tool_elems_to_remove = []
+ for tool_elem in config_elem:
+ if tool_elem.get( 'guid' ) in guids_to_remove:
+ tool_elems_to_remove.append( tool_elem )
+ for tool_elem in tool_elems_to_remove:
+ # Remove all of the appropriate tool sub-elements from the section element.
+ config_elem.remove( tool_elem )
+ if len( config_elem ) < 1:
+ # Keep a list of all empty section elements so they can be removed.
+ config_elems_to_remove.append( config_elem )
+ elif config_elem.tag == 'tool':
+ if config_elem.get( 'guid' ) in guids_to_remove:
+ config_elems_to_remove.append( config_elem )
+ for config_elem in config_elems_to_remove:
+ config_elems.remove( config_elem )
+ # Persist the altered in-memory version of the tool config.
+ suc.config_elems_to_xml_file( self.app, config_elems, shed_tool_conf, tool_path )
+
+ def remove_from_tool_panel( self, repository, shed_tool_conf, uninstall ):
+ """
+ A tool shed repository is being deactivated or uninstalled, so handle tool panel
+ alterations accordingly.
+ """
+ # Determine where the tools are currently defined in the tool panel and store this
+ # information so the tools can be displayed in the same way when the repository is
+ # activated or reinstalled.
+ tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( self.app, repository )
+ repository.metadata[ 'tool_panel_section' ] = tool_panel_dict
+ self.app.install_model.context.add( repository )
+ self.app.install_model.context.flush()
+ # Create a list of guids for all tools that will be removed from the in-memory tool panel
+ # and config file on disk.
+ guids_to_remove = [ k for k in tool_panel_dict.keys() ]
+ # Remove the tools from the toolbox's tools_by_id dictionary.
+ for guid_to_remove in guids_to_remove:
+ if guid_to_remove in self.app.toolbox.tools_by_id:
+ del self.app.toolbox.tools_by_id[ guid_to_remove ]
+ index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( self.app, shed_tool_conf )
+ if uninstall:
+ # Remove from the shed_tool_conf file on disk.
+ self.remove_from_shed_tool_config( shed_tool_conf_dict, guids_to_remove )
+ config_elems = shed_tool_conf_dict[ 'config_elems' ]
+ config_elems_to_remove = []
+ for config_elem in config_elems:
+ if config_elem.tag == 'section':
+ # Get the section key for the in-memory tool panel.
+ section_key = str( config_elem.get( "id" ) )
+ # Generate the list of tool elements to remove.
+ tool_elems_to_remove = []
+ for tool_elem in config_elem:
+ if tool_elem.get( 'guid' ) in guids_to_remove:
+ tool_elems_to_remove.append( tool_elem )
+ for tool_elem in tool_elems_to_remove:
+ if tool_elem in config_elem:
+ # Remove the tool sub-element from the section element.
+ config_elem.remove( tool_elem )
+ # Remove the tool from the section in the in-memory tool panel.
+ if section_key in self.app.toolbox.tool_panel:
+ tool_section = self.app.toolbox.tool_panel[ section_key ]
+ guid = tool_elem.get( 'guid' )
+ tool_key = 'tool_%s' % str( guid )
+ # Get the list of versions of this tool that are currently available in the toolbox.
+ available_tool_versions = self.app.toolbox.get_loaded_tools_by_lineage( guid )
+ if tool_key in tool_section.elems:
+ if available_tool_versions:
+ available_tool_versions.reverse()
+ replacement_tool_key = None
+ replacement_tool_version = None
+ # Since we are going to remove the tool from the section, replace it with the
+ # newest loaded version of the tool.
+ for available_tool_version in available_tool_versions:
+ available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
+ if available_tool_version.id in tool_section.elems.keys() or section_key == available_tool_section_id:
+ replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
+ replacement_tool_version = available_tool_version
+ break
+ if replacement_tool_key and replacement_tool_version:
+ # Get the index of the tool_key in the tool_section.
+ for tool_section_elems_index, key in enumerate( tool_section.elems.keys() ):
+ if key == tool_key:
+ break
+ # Remove the tool from the tool section.
+ del tool_section.elems[ tool_key ]
+ # Add the replacement tool at the same location in the tool section.
+ tool_section.elems.insert( tool_section_elems_index,
+ replacement_tool_key,
+ replacement_tool_version )
+ else:
+ del tool_section.elems[ tool_key ]
+ else:
+ del tool_section.elems[ tool_key ]
+ if uninstall:
+ # Remove the tool from the section in the in-memory integrated tool panel.
+ if section_key in self.app.toolbox.integrated_tool_panel:
+ tool_section = self.app.toolbox.integrated_tool_panel[ section_key ]
+ tool_key = 'tool_%s' % str( tool_elem.get( 'guid' ) )
+ if tool_key in tool_section.elems:
+ del tool_section.elems[ tool_key ]
+ if len( config_elem ) < 1:
+ # Keep a list of all empty section elements so they can be removed.
+ config_elems_to_remove.append( config_elem )
+ elif config_elem.tag == 'tool':
+ guid = config_elem.get( 'guid' )
+ if guid in guids_to_remove:
+ tool_key = 'tool_%s' % str( config_elem.get( 'guid' ) )
+ # Get the list of versions of this tool that are currently available in the toolbox.
+ available_tool_versions = self.app.toolbox.get_loaded_tools_by_lineage( guid )
+ if tool_key in self.app.toolbox.tool_panel:
+ if available_tool_versions:
+ available_tool_versions.reverse()
+ replacement_tool_key = None
+ replacement_tool_version = None
+ # Since we are going to remove the tool from the section, replace it with
+ # the newest loaded version of the tool.
+ for available_tool_version in available_tool_versions:
+ available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
+ if available_tool_version.id in self.app.toolbox.tool_panel.keys() or not available_tool_section_id:
+ replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
+ replacement_tool_version = available_tool_version
+ break
+ if replacement_tool_key and replacement_tool_version:
+ # Get the index of the tool_key in the tool_section.
+ for tool_panel_index, key in enumerate( self.app.toolbox.tool_panel.keys() ):
+ if key == tool_key:
+ break
+ # Remove the tool from the tool panel.
+ del self.app.toolbox.tool_panel[ tool_key ]
+ # Add the replacement tool at the same location in the tool panel.
+ self.app.toolbox.tool_panel.insert( tool_panel_index,
+ replacement_tool_key,
+ replacement_tool_version )
+ else:
+ del self.app.toolbox.tool_panel[ tool_key ]
+ else:
+ del self.app.toolbox.tool_panel[ tool_key ]
+ if uninstall:
+ if tool_key in self.app.toolbox.integrated_tool_panel:
+ del self.app.toolbox.integrated_tool_panel[ tool_key ]
+ config_elems_to_remove.append( config_elem )
+ for config_elem in config_elems_to_remove:
+ # Remove the element from the in-memory list of elements.
+ config_elems.remove( config_elem )
+ # Update the config_elems of the in-memory shed_tool_conf_dict.
+ shed_tool_conf_dict[ 'config_elems' ] = config_elems
+ self.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
+ self.app.toolbox_search = ToolBoxSearch( self.app.toolbox )
+ if uninstall and self.app.config.update_integrated_tool_panel:
+ # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
+ self.app.toolbox.write_integrated_tool_panel_config_file()
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/metadata/repository_metadata_manager.py
--- a/lib/tool_shed/metadata/repository_metadata_manager.py
+++ b/lib/tool_shed/metadata/repository_metadata_manager.py
@@ -2,11 +2,13 @@
import os
import tempfile
+from galaxy import util
from galaxy.util import inflector
-from galaxy import util
+from galaxy.web.form_builder import SelectField
from tool_shed.metadata import metadata_generator
from tool_shed.repository_types.metadata import TipOnly
+from tool_shed.repository_types import util as rt_util
from tool_shed.util import basic_util
from tool_shed.util import common_util
@@ -20,9 +22,10 @@
class RepositoryMetadataManager( metadata_generator.MetadataGenerator ):
- def __init__( self, app ):
+ def __init__( self, app, user ):
super( RepositoryMetadataManager, self ).__init__( app )
self.app = app
+ self.user = user
# Repository metadata comparisons for changeset revisions.
self.EQUAL = 'equal'
self.NO_METADATA = 'no metadata'
@@ -47,6 +50,18 @@
self.sa_session.add( repository_metadata )
self.sa_session.flush()
+ def build_repository_ids_select_field( self, name='repository_ids', multiple=True, display='checkboxes',
+ my_writable=False ):
+ """Generate the current list of repositories for resetting metadata."""
+ repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
+ query = self.get_query_for_setting_metadata_on_repositories( my_writable=my_writable, order=True )
+ for repository in query:
+ owner = str( repository.user.username )
+ option_label = '%s (%s)' % ( str( repository.name ), owner )
+ option_value = '%s' % self.app.security.encode_id( repository.id )
+ repositories_select_field.add_option( option_label, option_value )
+ return repositories_select_field
+
def clean_repository_metadata( self, id, changeset_revisions ):
# Delete all repository_metadata records associated with the repository that have
# a changeset_revision that is not in changeset_revisions. We sometimes see multiple
@@ -458,6 +473,54 @@
# The tool did not change through all of the changeset revisions.
return old_id
+ def get_query_for_setting_metadata_on_repositories( self, my_writable=False, order=True ):
+ """
+ Return a query containing repositories for resetting metadata. The order parameter
+ is used for displaying the list of repositories ordered alphabetically for display on
+ a page. When called from the Tool Shed API, order is False.
+ """
+ # When called from the Tool Shed API, the metadata is reset on all repositories of types
+ # repository_suite_definition and tool_dependency_definition in addition to other selected
+ # repositories.
+ if my_writable:
+ username = self.user.username
+ clause_list = []
+ for repository in self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.deleted == False ):
+ # Always reset metadata on all repositories of types repository_suite_definition and
+ # tool_dependency_definition.
+ if repository.type in [ rt_util.REPOSITORY_SUITE_DEFINITION, rt_util.TOOL_DEPENDENCY_DEFINITION ]:
+ clause_list.append( self.app.model.Repository.table.c.id == repository.id )
+ else:
+ allow_push = repository.allow_push( self.app )
+ if allow_push:
+ # Include all repositories that are writable by the current user.
+ allow_push_usernames = allow_push.split( ',' )
+ if username in allow_push_usernames:
+ clause_list.append( self.app.model.Repository.table.c.id == repository.id )
+ if clause_list:
+ if order:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( or_( *clause_list ) ) \
+ .order_by( self.app.model.Repository.table.c.name,
+ self.app.model.Repository.table.c.user_id )
+ else:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( or_( *clause_list ) )
+ else:
+ # Return an empty query.
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.id == -1 )
+ else:
+ if order:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.deleted == False ) \
+ .order_by( self.app.model.Repository.table.c.name,
+ self.app.model.Repository.table.c.user_id )
+ else:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.deleted == False )
+
def new_datatypes_metadata_required( self, repository_metadata, metadata_dict ):
"""
Compare the last saved metadata for each datatype in the repository with the new metadata
@@ -732,13 +795,13 @@
# repository_metadata table record is not needed.
return False
- def reset_all_metadata_on_repository_in_tool_shed( self, user, id ):
+ def reset_all_metadata_on_repository_in_tool_shed( self, id ):
"""Reset all metadata on a single repository in a tool shed."""
repository = suc.get_repository_in_tool_shed( self.app, id )
log.debug( "Resetting all metadata on repository: %s" % repository.name )
repo_dir = repository.repo_path( self.app )
repo = hg_util.get_repo_for_repository( self.app, repository=None, repo_path=repo_dir, create=False )
- repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( user, repository )
+ repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( self.user, repository )
# The list of changeset_revisions refers to repository_metadata records that have been created
# or updated. When the following loop completes, we'll delete all repository_metadata records
# for this repository that do not have a changeset_revision value in this list.
@@ -875,7 +938,7 @@
self.sa_session.add( repository_metadata )
self.sa_session.flush()
- def reset_metadata_on_selected_repositories( self, user, **kwd ):
+ def reset_metadata_on_selected_repositories( self, **kwd ):
"""
Inspect the repository changelog to reset metadata for all appropriate changeset revisions.
This method is called from both Galaxy and the Tool Shed.
@@ -892,7 +955,7 @@
repository = suc.get_repository_in_tool_shed( self.app, repository_id )
owner = str( repository.user.username )
invalid_file_tups, metadata_dict = \
- self.reset_all_metadata_on_repository_in_tool_shed( user, repository_id )
+ self.reset_all_metadata_on_repository_in_tool_shed( self.user, repository_id )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( self.app,
invalid_file_tups,
@@ -918,7 +981,7 @@
status = 'error'
return message, status
- def set_repository_metadata( self, host, user, repository, content_alert_str='', **kwd ):
+ def set_repository_metadata( self, host, repository, content_alert_str='', **kwd ):
"""
Set metadata using the repository's current disk files, returning specific error
messages (if any) to alert the repository owner that the changeset has problems.
@@ -926,7 +989,7 @@
message = ''
status = 'done'
encoded_id = self.app.security.encode_id( repository.id )
- repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( user, repository )
+ repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( self.user, repository )
repo_dir = repository.repo_path( self.app )
repo = hg_util.get_repo_for_repository( self.app, repository=None, repo_path=repo_dir, create=False )
metadata_dict, invalid_file_tups = \
@@ -1027,10 +1090,9 @@
tool_util.reset_tool_data_tables( self.app )
return message, status
- def set_repository_metadata_due_to_new_tip( self, host, user, repository, content_alert_str=None, **kwd ):
+ def set_repository_metadata_due_to_new_tip( self, host, repository, content_alert_str=None, **kwd ):
"""Set metadata on the repository tip in the tool shed."""
error_message, status = self.set_repository_metadata( host,
- user,
repository,
content_alert_str=content_alert_str,
**kwd )
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/util/shed_util_common.py
--- a/lib/tool_shed/util/shed_util_common.py
+++ b/lib/tool_shed/util/shed_util_common.py
@@ -84,20 +84,6 @@
'${host}'
"""
-def build_repository_ids_select_field( trans, name='repository_ids', multiple=True, display='checkboxes', my_writable=False ):
- """Method called from both Galaxy and the Tool Shed to generate the current list of repositories for resetting metadata."""
- repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
- query = get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=True )
- for repository in query:
- if trans.webapp.name == 'tool_shed':
- owner = str( repository.user.username )
- else:
- owner = str( repository.owner )
- option_label = '%s (%s)' % ( str( repository.name ), owner )
- option_value = '%s' % trans.security.encode_id( repository.id )
- repositories_select_field.add_option( option_label, option_value )
- return repositories_select_field
-
def build_tool_dependencies_select_field( app, tool_shed_repository, name, multiple=True, display='checkboxes', uninstalled_only=False ):
"""Method called from Galaxy to generate the current list of tool dependency ids for an installed tool shed repository."""
tool_dependencies_select_field = SelectField( name=name, multiple=multiple, display=display )
@@ -645,66 +631,6 @@
prior_import_or_install_required_dict[ encoded_repository_id ] = prior_import_or_install_ids
return prior_import_or_install_required_dict
-def get_query_for_setting_metadata_on_repositories( trans, my_writable=False, order=True ):
- """
- Return a query containing repositories for resetting metadata. This method is called from both the
- Tool Shed and Galaxy. The my_writable parameter is ignored unless called from the Tool Shed, and the
- order parameter is used for displaying the list of repositories ordered alphabetically for display on
- a page. When called from either the Tool Shed or Galaxy API, order is False.
- """
- if trans.webapp.name == 'tool_shed':
- # When called from the Tool Shed API, the metadata is reset on all repositories of types
- # repository_suite_definition and tool_dependency_definition in addition to other selected
- # repositories.
- if my_writable:
- username = trans.user.username
- clause_list = []
- for repository in trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.deleted == False ):
- # Always reset metadata on all repositories of types repository_suite_definition and
- # tool_dependency_definition.
- if repository.type in [ rt_util.REPOSITORY_SUITE_DEFINITION, rt_util.TOOL_DEPENDENCY_DEFINITION ]:
- clause_list.append( trans.model.Repository.table.c.id == repository.id )
- else:
- allow_push = repository.allow_push( trans.app )
- if allow_push:
- # Include all repositories that are writable by the current user.
- allow_push_usernames = allow_push.split( ',' )
- if username in allow_push_usernames:
- clause_list.append( trans.model.Repository.table.c.id == repository.id )
- if clause_list:
- if order:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( or_( *clause_list ) ) \
- .order_by( trans.model.Repository.table.c.name,
- trans.model.Repository.table.c.user_id )
- else:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( or_( *clause_list ) )
- else:
- # Return an empty query.
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.id == -1 )
- else:
- if order:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.deleted == False ) \
- .order_by( trans.model.Repository.table.c.name,
- trans.model.Repository.table.c.user_id )
- else:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.deleted == False )
- else:
- # We're in Galaxy.
- if order:
- return trans.install_model.context.query( trans.install_model.ToolShedRepository ) \
- .filter( trans.install_model.ToolShedRepository.table.c.uninstalled == False ) \
- .order_by( trans.install_model.ToolShedRepository.table.c.name,
- trans.install_model.ToolShedRepository.table.c.owner )
- else:
- return trans.install_model.context.query( trans.install_model.ToolShedRepository ) \
- .filter( trans.install_model.ToolShedRepository.table.c.uninstalled == False )
-
def get_repo_info_tuple_contents( repo_info_tuple ):
"""Take care in handling the repo_info_tuple as it evolves over time as new tool shed features are introduced."""
if len( repo_info_tuple ) == 6:
diff -r 972a80267009126e558ba14142df48b897db48c8 -r e9de99ef77105d221df55771724ca56b86485a4b lib/tool_shed/util/tool_util.py
--- a/lib/tool_shed/util/tool_util.py
+++ b/lib/tool_shed/util/tool_util.py
@@ -19,69 +19,6 @@
log = logging.getLogger( __name__ )
-def add_to_shed_tool_config( app, shed_tool_conf_dict, elem_list ):
- # A tool shed repository is being installed so change the shed_tool_conf file. Parse the
- # config file to generate the entire list of config_elems instead of using the in-memory list
- # since it will be a subset of the entire list if one or more repositories have been deactivated.
- shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
- tool_path = shed_tool_conf_dict[ 'tool_path' ]
- config_elems = []
- tree, error_message = xml_util.parse_xml( shed_tool_conf )
- if tree:
- root = tree.getroot()
- for elem in root:
- config_elems.append( elem )
- # Add the elements to the in-memory list of config_elems.
- for elem_entry in elem_list:
- config_elems.append( elem_entry )
- # Persist the altered shed_tool_config file.
- suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path )
-
-def add_to_tool_panel( app, repository_name, repository_clone_url, changeset_revision, repository_tools_tups, owner,
- shed_tool_conf, tool_panel_dict, new_install=True ):
- """A tool shed repository is being installed or updated so handle tool panel alterations accordingly."""
- # We need to change the in-memory version and the file system version of the shed_tool_conf file.
- index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf )
- tool_path = shed_tool_conf_dict[ 'tool_path' ]
- # Generate the list of ElementTree Element objects for each section or tool.
- elem_list = generate_tool_panel_elem_list( repository_name,
- repository_clone_url,
- changeset_revision,
- tool_panel_dict,
- repository_tools_tups,
- owner=owner )
- if new_install:
- # Add the new elements to the shed_tool_conf file on disk.
- add_to_shed_tool_config( app, shed_tool_conf_dict, elem_list )
- # Use the new elements to add entries to the
- config_elems = shed_tool_conf_dict[ 'config_elems' ]
- for config_elem in elem_list:
- # Add the new elements to the in-memory list of config_elems.
- config_elems.append( config_elem )
- # Load the tools into the in-memory tool panel.
- if config_elem.tag == 'section':
- app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True )
- elif config_elem.tag == 'workflow':
- app.toolbox.load_workflow_tag_set( config_elem,
- app.toolbox.tool_panel,
- app.toolbox.integrated_tool_panel,
- load_panel_dict=True )
- elif config_elem.tag == 'tool':
- guid = config_elem.get( 'guid' )
- app.toolbox.load_tool_tag_set( config_elem,
- app.toolbox.tool_panel,
- app.toolbox.integrated_tool_panel,
- tool_path,
- load_panel_dict=True,
- guid=guid )
- # Replace the old list of in-memory config_elems with the new list for this shed_tool_conf_dict.
- shed_tool_conf_dict[ 'config_elems' ] = config_elems
- app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
- if app.config.update_integrated_tool_panel:
- # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
- app.toolbox.write_integrated_tool_panel_config_file()
- app.toolbox_search = ToolBoxSearch( app.toolbox )
-
def build_shed_tool_conf_select_field( app ):
"""Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs."""
options = []
@@ -192,142 +129,6 @@
message += "%s%s%s - %s%s" % ( bold_start, tool_file, bold_end, correction_msg, new_line )
return message
-def generate_tool_panel_dict_for_new_install( tool_dicts, tool_section=None ):
- """
- When installing a repository that contains tools, all tools must currently be defined
- within the same tool section in the tool panel or outside of any sections.
- """
- tool_panel_dict = {}
- if tool_section:
- section_id = tool_section.id
- section_name = tool_section.name
- section_version = tool_section.version or ''
- else:
- section_id = ''
- section_name = ''
- section_version = ''
- for tool_dict in tool_dicts:
- if tool_dict.get( 'add_to_tool_panel', True ):
- guid = tool_dict[ 'guid' ]
- tool_config = tool_dict[ 'tool_config' ]
- tool_section_dict = dict( tool_config=tool_config, id=section_id, name=section_name, version=section_version )
- if guid in tool_panel_dict:
- tool_panel_dict[ guid ].append( tool_section_dict )
- else:
- tool_panel_dict[ guid ] = [ tool_section_dict ]
- return tool_panel_dict
-
-def generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=None ):
- """
- Create a dictionary of the following type for a single tool config file name.
- The intent is to call this method for every tool config in a repository and
- append each of these as entries to a tool panel dictionary for the repository.
- This allows for each tool to be loaded into a different section in the tool panel.
- {<Tool guid> :
- [{ tool_config : <tool_config_file>,
- id: <ToolSection id>,
- version : <ToolSection version>,
- name : <TooSection name>}]}
- """
- tool_panel_dict = {}
- file_name = basic_util.strip_path( tool_config )
- tool_section_dicts = generate_tool_section_dicts( tool_config=file_name, tool_sections=tool_sections )
- tool_panel_dict[ guid ] = tool_section_dicts
- return tool_panel_dict
-
-def generate_tool_panel_elem_list( repository_name, repository_clone_url, changeset_revision, tool_panel_dict,
- repository_tools_tups, owner='' ):
- """Generate a list of ElementTree Element objects for each section or tool."""
- elem_list = []
- tool_elem = None
- cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url( repository_clone_url )
- if not owner:
- owner = suc.get_repository_owner( cleaned_repository_clone_url )
- tool_shed = cleaned_repository_clone_url.split( '/repos/' )[ 0 ].rstrip( '/' )
- for guid, tool_section_dicts in tool_panel_dict.items():
- for tool_section_dict in tool_section_dicts:
- tool_section = None
- inside_section = False
- section_in_elem_list = False
- if tool_section_dict[ 'id' ]:
- inside_section = True
- # Create a new section element only if we haven't already created it.
- for index, elem in enumerate( elem_list ):
- if elem.tag == 'section':
- section_id = elem.get( 'id', None )
- if section_id == tool_section_dict[ 'id' ]:
- section_in_elem_list = True
- tool_section = elem
- break
- if tool_section is None:
- tool_section = generate_tool_section_element_from_dict( tool_section_dict )
- # Find the tuple containing the current guid from the list of repository_tools_tups.
- for repository_tool_tup in repository_tools_tups:
- tool_file_path, tup_guid, tool = repository_tool_tup
- if tup_guid == guid:
- break
- if inside_section:
- tool_elem = suc.generate_tool_elem( tool_shed,
- repository_name,
- changeset_revision,
- owner,
- tool_file_path,
- tool,
- tool_section )
- else:
- tool_elem = suc.generate_tool_elem( tool_shed,
- repository_name,
- changeset_revision,
- owner,
- tool_file_path,
- tool,
- None )
- if inside_section:
- if section_in_elem_list:
- elem_list[ index ] = tool_section
- else:
- elem_list.append( tool_section )
- else:
- elem_list.append( tool_elem )
- return elem_list
-
-def generate_tool_section_dicts( tool_config=None, tool_sections=None ):
- tool_section_dicts = []
- if tool_config is None:
- tool_config = ''
- if tool_sections:
- for tool_section in tool_sections:
- # The value of tool_section will be None if the tool is displayed outside
- # of any sections in the tool panel.
- if tool_section:
- section_id = tool_section.id or ''
- section_version = tool_section.version or ''
- section_name = tool_section.name or ''
- else:
- section_id = ''
- section_version = ''
- section_name = ''
- tool_section_dicts.append( dict( tool_config=tool_config,
- id=section_id,
- version=section_version,
- name=section_name ) )
- else:
- tool_section_dicts.append( dict( tool_config=tool_config, id='', version='', name='' ) )
- return tool_section_dicts
-
-def generate_tool_section_element_from_dict( tool_section_dict ):
- # The value of tool_section_dict looks like the following.
- # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}
- if tool_section_dict[ 'id' ]:
- # Create a new tool section.
- tool_section = XmlET.Element( 'section' )
- tool_section.attrib[ 'id' ] = tool_section_dict[ 'id' ]
- tool_section.attrib[ 'name' ] = tool_section_dict[ 'name' ]
- tool_section.attrib[ 'version' ] = tool_section_dict[ 'version' ]
- else:
- tool_section = None
- return tool_section
-
def get_headers( fname, sep, count=60, is_multi_byte=False ):
"""Returns a list with the first 'count' lines split by 'sep'."""
headers = []
@@ -341,26 +142,6 @@
break
return headers
-def get_or_create_tool_section( toolbox, tool_panel_section_id, new_tool_panel_section_label=None ):
- tool_panel_section_key = str( tool_panel_section_id )
- if tool_panel_section_key in toolbox.tool_panel:
- # Appending a tool to an existing section in toolbox.tool_panel
- tool_section = toolbox.tool_panel[ tool_panel_section_key ]
- log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) )
- else:
- # Appending a new section to toolbox.tool_panel
- if new_tool_panel_section_label is None:
- # This might add an ugly section label to the tool panel, but, oh well...
- new_tool_panel_section_label = tool_panel_section_id
- elem = XmlET.Element( 'section' )
- elem.attrib[ 'name' ] = new_tool_panel_section_label
- elem.attrib[ 'id' ] = tool_panel_section_id
- elem.attrib[ 'version' ] = ''
- tool_section = galaxy.tools.ToolSection( elem )
- toolbox.tool_panel[ tool_panel_section_key ] = tool_section
- log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) )
- return tool_panel_section_key, tool_section
-
def get_tool_path_install_dir( partial_install_dir, shed_tool_conf_dict, tool_dict, config_elems ):
for elem in config_elems:
if elem.tag == 'tool':
@@ -514,63 +295,6 @@
error = True
return error, message
-def handle_tool_panel_selection( toolbox, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ):
- """
- Handle the selected tool panel location for loading tools included in tool shed repositories when installing
- or reinstalling them.
- """
- # Get the location in the tool panel in which each tool was originally loaded.
- tool_section = None
- tool_panel_section_key = None
- if 'tools' in metadata:
- # This forces everything to be loaded into the same section (or no section) in the tool panel.
- if no_changes_checked:
- # Make sure the no_changes check box overrides the new_tool_panel_section_label if the user checked the check
- # box and entered something into the field.
- new_tool_panel_section_label = None
- if 'tool_panel_section' in metadata:
- tool_panel_dict = metadata[ 'tool_panel_section' ]
- if not tool_panel_dict:
- tool_panel_dict = generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
- else:
- tool_panel_dict = generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
- if tool_panel_dict:
- # The tool_panel_dict is empty when tools exist but are not installed into a tool panel section.
- tool_section_dicts = tool_panel_dict[ tool_panel_dict.keys()[ 0 ] ]
- tool_section_dict = tool_section_dicts[ 0 ]
- original_section_id = tool_section_dict[ 'id' ]
- original_section_name = tool_section_dict[ 'name' ]
- if original_section_id:
- tool_panel_section_key, tool_section = \
- get_or_create_tool_section( toolbox,
- tool_panel_section_id=original_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
- else:
- # The user elected to change the tool panel section to contain the tools.
- tool_panel_section_key, tool_section = handle_tool_panel_section( toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
- return tool_section, tool_panel_section_key
-
-def handle_tool_panel_section( toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ):
- """Return a ToolSection object retrieved from the current in-memory tool_panel."""
- # If tool_panel_section_id is received, the section exists in the tool panel. In this
- # case, the value of the received tool_panel_section_id must be the id retrieved from a
- # tool panel config (e.g., tool_conf.xml, which may have getext). If new_tool_panel_section_label
- # is received, a new section will be added to the tool panel.
- if new_tool_panel_section_label:
- section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) )
- tool_panel_section_key, tool_section = \
- get_or_create_tool_section( toolbox,
- tool_panel_section_id=section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
- elif tool_panel_section_id:
- tool_panel_section_key = str( tool_panel_section_id )
- tool_section = toolbox.tool_panel[ tool_panel_section_key ]
- else:
- return None, None
- return tool_panel_section_key, tool_section
-
def handle_tool_versions( app, tool_version_dicts, tool_shed_repository ):
"""
Using the list of tool_version_dicts retrieved from the tool shed (one per changeset
@@ -741,170 +465,6 @@
if isinstance( tool.tool_action, UploadToolAction ):
app.toolbox.reload_tool_by_id( tool_id )
-def remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ):
- # A tool shed repository is being uninstalled so change the shed_tool_conf file.
- # Parse the config file to generate the entire list of config_elems instead of
- # using the in-memory list since it will be a subset of the entire list if one
- # or more repositories have been deactivated.
- shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
- tool_path = shed_tool_conf_dict[ 'tool_path' ]
- config_elems = []
- tree, error_message = xml_util.parse_xml( shed_tool_conf )
- if tree:
- root = tree.getroot()
- for elem in root:
- config_elems.append( elem )
- config_elems_to_remove = []
- for config_elem in config_elems:
- if config_elem.tag == 'section':
- tool_elems_to_remove = []
- for tool_elem in config_elem:
- if tool_elem.get( 'guid' ) in guids_to_remove:
- tool_elems_to_remove.append( tool_elem )
- for tool_elem in tool_elems_to_remove:
- # Remove all of the appropriate tool sub-elements from the section element.
- config_elem.remove( tool_elem )
- if len( config_elem ) < 1:
- # Keep a list of all empty section elements so they can be removed.
- config_elems_to_remove.append( config_elem )
- elif config_elem.tag == 'tool':
- if config_elem.get( 'guid' ) in guids_to_remove:
- config_elems_to_remove.append( config_elem )
- for config_elem in config_elems_to_remove:
- config_elems.remove( config_elem )
- # Persist the altered in-memory version of the tool config.
- suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path )
-
-def remove_from_tool_panel( app, repository, shed_tool_conf, uninstall ):
- """
- A tool shed repository is being deactivated or uninstalled, so handle tool panel
- alterations accordingly.
- """
- # Determine where the tools are currently defined in the tool panel and store this
- # information so the tools can be displayed in the same way when the repository is
- # activated or reinstalled.
- tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( app, repository )
- repository.metadata[ 'tool_panel_section' ] = tool_panel_dict
- app.install_model.context.add( repository )
- app.install_model.context.flush()
- # Create a list of guids for all tools that will be removed from the in-memory tool panel
- # and config file on disk.
- guids_to_remove = [ k for k in tool_panel_dict.keys() ]
- # Remove the tools from the toolbox's tools_by_id dictionary.
- for guid_to_remove in guids_to_remove:
- if guid_to_remove in app.toolbox.tools_by_id:
- del app.toolbox.tools_by_id[ guid_to_remove ]
- index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf )
- if uninstall:
- # Remove from the shed_tool_conf file on disk.
- remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove )
- config_elems = shed_tool_conf_dict[ 'config_elems' ]
- config_elems_to_remove = []
- for config_elem in config_elems:
- if config_elem.tag == 'section':
- # Get the section key for the in-memory tool panel.
- section_key = str( config_elem.get( "id" ) )
- # Generate the list of tool elements to remove.
- tool_elems_to_remove = []
- for tool_elem in config_elem:
- if tool_elem.get( 'guid' ) in guids_to_remove:
- tool_elems_to_remove.append( tool_elem )
- for tool_elem in tool_elems_to_remove:
- if tool_elem in config_elem:
- # Remove the tool sub-element from the section element.
- config_elem.remove( tool_elem )
- # Remove the tool from the section in the in-memory tool panel.
- if section_key in app.toolbox.tool_panel:
- tool_section = app.toolbox.tool_panel[ section_key ]
- guid = tool_elem.get( 'guid' )
- tool_key = 'tool_%s' % str( guid )
- # Get the list of versions of this tool that are currently available in the toolbox.
- available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid )
- if tool_key in tool_section.elems:
- if available_tool_versions:
- available_tool_versions.reverse()
- replacement_tool_key = None
- replacement_tool_version = None
- # Since we are going to remove the tool from the section, replace it with the
- # newest loaded version of the tool.
- for available_tool_version in available_tool_versions:
- available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
- if available_tool_version.id in tool_section.elems.keys() or section_key == available_tool_section_id:
- replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
- replacement_tool_version = available_tool_version
- break
- if replacement_tool_key and replacement_tool_version:
- # Get the index of the tool_key in the tool_section.
- for tool_section_elems_index, key in enumerate( tool_section.elems.keys() ):
- if key == tool_key:
- break
- # Remove the tool from the tool section.
- del tool_section.elems[ tool_key ]
- # Add the replacement tool at the same location in the tool section.
- tool_section.elems.insert( tool_section_elems_index,
- replacement_tool_key,
- replacement_tool_version )
- else:
- del tool_section.elems[ tool_key ]
- else:
- del tool_section.elems[ tool_key ]
- if uninstall:
- # Remove the tool from the section in the in-memory integrated tool panel.
- if section_key in app.toolbox.integrated_tool_panel:
- tool_section = app.toolbox.integrated_tool_panel[ section_key ]
- tool_key = 'tool_%s' % str( tool_elem.get( 'guid' ) )
- if tool_key in tool_section.elems:
- del tool_section.elems[ tool_key ]
- if len( config_elem ) < 1:
- # Keep a list of all empty section elements so they can be removed.
- config_elems_to_remove.append( config_elem )
- elif config_elem.tag == 'tool':
- guid = config_elem.get( 'guid' )
- if guid in guids_to_remove:
- tool_key = 'tool_%s' % str( config_elem.get( 'guid' ) )
- # Get the list of versions of this tool that are currently available in the toolbox.
- available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid )
- if tool_key in app.toolbox.tool_panel:
- if available_tool_versions:
- available_tool_versions.reverse()
- replacement_tool_key = None
- replacement_tool_version = None
- # Since we are going to remove the tool from the section, replace it with
- # the newest loaded version of the tool.
- for available_tool_version in available_tool_versions:
- available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
- if available_tool_version.id in app.toolbox.tool_panel.keys() or not available_tool_section_id:
- replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
- replacement_tool_version = available_tool_version
- break
- if replacement_tool_key and replacement_tool_version:
- # Get the index of the tool_key in the tool_section.
- for tool_panel_index, key in enumerate( app.toolbox.tool_panel.keys() ):
- if key == tool_key:
- break
- # Remove the tool from the tool panel.
- del app.toolbox.tool_panel[ tool_key ]
- # Add the replacement tool at the same location in the tool panel.
- app.toolbox.tool_panel.insert( tool_panel_index, replacement_tool_key, replacement_tool_version )
- else:
- del app.toolbox.tool_panel[ tool_key ]
- else:
- del app.toolbox.tool_panel[ tool_key ]
- if uninstall:
- if tool_key in app.toolbox.integrated_tool_panel:
- del app.toolbox.integrated_tool_panel[ tool_key ]
- config_elems_to_remove.append( config_elem )
- for config_elem in config_elems_to_remove:
- # Remove the element from the in-memory list of elements.
- config_elems.remove( config_elem )
- # Update the config_elems of the in-memory shed_tool_conf_dict.
- shed_tool_conf_dict[ 'config_elems' ] = config_elems
- app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
- app.toolbox_search = ToolBoxSearch( app.toolbox )
- if uninstall and app.config.update_integrated_tool_panel:
- # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
- app.toolbox.write_integrated_tool_panel_config_file()
-
def reset_tool_data_tables( app ):
# Reset the tool_data_tables to an empty dictionary.
app.tool_data_tables.data_tables = {}
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.
1
0
commit/galaxy-central: greg: Some code cleanup for setting metadata on tool shed repositories.
by commits-noreply@bitbucket.org 21 Jul '14
by commits-noreply@bitbucket.org 21 Jul '14
21 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/0eaf1edd08e3/
Changeset: 0eaf1edd08e3
User: greg
Date: 2014-07-21 19:38:43
Summary: Some code cleanup for setting metadata on tool shed repositories.
Affected #: 11 files
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
--- a/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
+++ b/lib/galaxy/webapps/galaxy/api/tool_shed_repositories.py
@@ -413,12 +413,12 @@
# Make sure the current user's API key proves he is an admin user in this Galaxy instance.
if not trans.user_is_admin():
raise HTTPForbidden( detail='You are not authorized to reset metadata on repositories installed into this Galaxy instance.' )
- query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=False, order=False )
+ irmm = InstalledRepositoryMetadataManager( trans.app )
+ query = irmm.get_query_for_setting_metadata_on_repositories( order=False )
# Now reset metadata on all remaining repositories.
for repository in query:
repository_id = trans.security.encode_id( repository.id )
try:
- irmm = InstalledRepositoryMetadataManager( trans.app )
invalid_file_tups, metadata_dict = irmm.reset_all_metadata_on_installed_repository( repository_id )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
--- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
+++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
@@ -1708,13 +1708,13 @@
@web.expose
@web.require_admin
def reset_metadata_on_selected_installed_repositories( self, trans, **kwd ):
+ irmm = InstalledRepositoryMetadataManager( trans.app )
if 'reset_metadata_on_selected_repositories_button' in kwd:
- irmm = InstalledRepositoryMetadataManager( trans.app )
message, status = irmm.reset_metadata_on_selected_repositories( trans.user, **kwd )
else:
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
- repositories_select_field = suc.build_repository_ids_select_field( trans )
+ repositories_select_field = irmm.build_repository_ids_select_field( trans )
return trans.fill_template( '/admin/tool_shed_repository/reset_metadata_on_selected_repositories.mako',
repositories_select_field=repositories_select_field,
message=message,
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/tool_shed/api/repositories.py
--- a/lib/galaxy/webapps/tool_shed/api/repositories.py
+++ b/lib/galaxy/webapps/tool_shed/api/repositories.py
@@ -392,7 +392,8 @@
my_writable = True
handled_repository_ids = []
repository_ids = []
- query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=False )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
+ query = rmm.get_query_for_setting_metadata_on_repositories( my_writable=my_writable, order=False )
# Make sure repositories of type tool_dependency_definition are first in the list.
for repository in query:
if repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids:
@@ -426,13 +427,12 @@
This param can be used as an alternative to the above encoded_ids_to_skip.
"""
- def handle_repository( trans, repository, results ):
+ def handle_repository( trans, rmm, repository, results ):
log.debug( "Resetting metadata on repository %s" % str( repository.name ) )
repository_id = trans.security.encode_id( repository.id )
try:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
invalid_file_tups, metadata_dict = \
- rmm.reset_all_metadata_on_repository_in_tool_shed( trans.user, repository_id )
+ rmm.reset_all_metadata_on_repository_in_tool_shed( repository_id )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
invalid_file_tups,
@@ -451,7 +451,7 @@
status = '%s : %s' % ( str( repository.name ), message )
results[ 'repository_status' ].append( status )
return results
-
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
start_time = strftime( "%Y-%m-%d %H:%M:%S" )
results = dict( start_time=start_time,
repository_status=[],
@@ -473,7 +473,7 @@
my_writable = util.asbool( payload.get( 'my_writable', False ) )
else:
my_writable = True
- query = suc.get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=False )
+ query = rmm.get_query_for_setting_metadata_on_repositories( my_writable=my_writable, order=False )
# First reset metadata on all repositories of type repository_dependency_definition.
for repository in query:
encoded_id = trans.security.encode_id( repository.id )
@@ -481,7 +481,7 @@
log.debug( "Skipping repository with id %s because it is in encoded_ids_to_skip %s" % \
( str( repository.id ), str( encoded_ids_to_skip ) ) )
elif repository.type == rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids:
- results = handle_repository( trans, repository, results )
+ results = handle_repository( trans, rmm, repository, results )
# Now reset metadata on all remaining repositories.
for repository in query:
encoded_id = trans.security.encode_id( repository.id )
@@ -489,7 +489,7 @@
log.debug( "Skipping repository with id %s because it is in encoded_ids_to_skip %s" % \
( str( repository.id ), str( encoded_ids_to_skip ) ) )
elif repository.type != rt_util.TOOL_DEPENDENCY_DEFINITION and repository.id not in handled_repository_ids:
- results = handle_repository( trans, repository, results )
+ results = handle_repository( trans, rmm, repository, results )
stop_time = strftime( "%Y-%m-%d %H:%M:%S" )
results[ 'stop_time' ] = stop_time
return json.dumps( results, sort_keys=True, indent=4 )
@@ -511,10 +511,9 @@
results = dict( start_time=start_time,
repository_status=[] )
try:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
invalid_file_tups, metadata_dict = \
- rmm.reset_all_metadata_on_repository_in_tool_shed( trans.user,
- trans.security.encode_id( repository.id ) )
+ rmm.reset_all_metadata_on_repository_in_tool_shed( trans.security.encode_id( repository.id ) )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
invalid_file_tups,
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/tool_shed/controllers/admin.py
--- a/lib/galaxy/webapps/tool_shed/controllers/admin.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/admin.py
@@ -348,13 +348,16 @@
@web.expose
@web.require_admin
def reset_metadata_on_selected_repositories_in_tool_shed( self, trans, **kwd ):
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
if 'reset_metadata_on_selected_repositories_button' in kwd:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
- message, status = rmm.reset_metadata_on_selected_repositories( trans.user, **kwd )
+ message, status = rmm.reset_metadata_on_selected_repositories( **kwd )
else:
message = util.restore_text( kwd.get( 'message', '' ) )
status = kwd.get( 'status', 'done' )
- repositories_select_field = suc.build_repository_ids_select_field( trans )
+ repositories_select_field = rmm.build_repository_ids_select_field( name='repository_ids',
+ multiple=True,
+ display='checkboxes',
+ my_writable=False )
return trans.fill_template( '/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako',
repositories_select_field=repositories_select_field,
message=message,
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/tool_shed/controllers/hg.py
--- a/lib/galaxy/webapps/tool_shed/controllers/hg.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/hg.py
@@ -48,8 +48,8 @@
repo = hg.repository( ui.ui(), repository.repo_path( trans.app ) )
update_repository( repo, ctx_rev=None )
# Set metadata using the repository files on disk.
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
- error_message, status = rmm.set_repository_metadata( trans.request.host, trans.user, repository )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
+ error_message, status = rmm.set_repository_metadata( trans.request.host, repository )
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 ) )
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/tool_shed/controllers/repository.py
--- a/lib/galaxy/webapps/tool_shed/controllers/repository.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py
@@ -2753,9 +2753,9 @@
def reset_all_metadata( self, trans, id, **kwd ):
"""Reset all metadata on the complete changelog for a single repository in the tool shed."""
# This method is called only from the ~/templates/webapps/tool_shed/repository/manage_repository.mako template.
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
invalid_file_tups, metadata_dict = \
- rmm.reset_all_metadata_on_repository_in_tool_shed( trans.user, id, **kwd )
+ rmm.reset_all_metadata_on_repository_in_tool_shed( id, **kwd )
if invalid_file_tups:
repository = suc.get_repository_in_tool_shed( trans.app, id )
message = tool_util.generate_message_for_invalid_tools( trans.app,
@@ -2774,13 +2774,16 @@
@web.expose
def reset_metadata_on_my_writable_repositories_in_tool_shed( self, trans, **kwd ):
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
if 'reset_metadata_on_selected_repositories_button' in kwd:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
- message, status = rmm.reset_metadata_on_selected_repositories( trans.user, **kwd )
+ message, status = rmm.reset_metadata_on_selected_repositories( **kwd )
else:
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
- repositories_select_field = suc.build_repository_ids_select_field( trans, my_writable=True )
+ repositories_select_field = rmm.build_repository_ids_select_field( name='repository_ids',
+ multiple=True,
+ display='checkboxes',
+ my_writable=True )
return trans.fill_template( '/webapps/tool_shed/common/reset_metadata_on_selected_repositories.mako',
repositories_select_field=repositories_select_field,
message=message,
@@ -2840,9 +2843,8 @@
if tip == repository.tip( trans.app ):
message += 'No changes to repository. '
else:
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
status, error_message = rmm.set_repository_metadata_due_to_new_tip( trans.request.host,
- trans.user,
repository,
**kwd )
if error_message:
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/galaxy/webapps/tool_shed/controllers/upload.py
--- a/lib/galaxy/webapps/tool_shed/controllers/upload.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/upload.py
@@ -262,10 +262,9 @@
( len( files_to_remove ), upload_point )
else:
message += " %d files were removed from the repository root. " % len( files_to_remove )
- rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( trans.app, trans.user )
status, error_message = \
rmm.set_repository_metadata_due_to_new_tip( trans.request.host,
- trans.user,
repository,
content_alert_str=content_alert_str,
**kwd )
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/tool_shed/capsule/capsule_manager.py
--- a/lib/tool_shed/capsule/capsule_manager.py
+++ b/lib/tool_shed/capsule/capsule_manager.py
@@ -727,9 +727,8 @@
results_dict[ 'ok' ] = False
results_dict[ 'error_message' ] += error_message
try:
- rmm = repository_metadata_manager.RepositoryMetadataManager( self.app )
+ rmm = repository_metadata_manager.RepositoryMetadataManager( self.app, self.user )
status, error_message = rmm.set_repository_metadata_due_to_new_tip( self.host,
- self.user,
repository,
content_alert_str=content_alert_str )
if error_message:
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py
--- a/lib/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py
+++ b/lib/tool_shed/galaxy_install/metadata/installed_repository_metadata_manager.py
@@ -3,6 +3,7 @@
from galaxy import util
from galaxy.util import inflector
+from galaxy.web.form_builder import SelectField
from tool_shed.metadata import metadata_generator
@@ -19,6 +20,32 @@
super( InstalledRepositoryMetadataManager, self ).__init__( app )
self.app = app
+ def build_repository_ids_select_field( self, name='repository_ids', multiple=True, display='checkboxes' ):
+ """Generate the current list of repositories for resetting metadata."""
+ repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
+ query = self.get_query_for_setting_metadata_on_repositories( order=True )
+ for repository in query:
+ owner = str( repository.owner )
+ option_label = '%s (%s)' % ( str( repository.name ), owner )
+ option_value = '%s' % self.app.security.encode_id( repository.id )
+ repositories_select_field.add_option( option_label, option_value )
+ return repositories_select_field
+
+ def get_query_for_setting_metadata_on_repositories( self, order=True ):
+ """
+ Return a query containing repositories for resetting metadata. The order parameter
+ is used for displaying the list of repositories ordered alphabetically for display on
+ a page. When called from the Galaxy API, order is False.
+ """
+ if order:
+ return self.app.install_model.context.query( self.app.install_model.ToolShedRepository ) \
+ .filter( self.app.install_model.ToolShedRepository.table.c.uninstalled == False ) \
+ .order_by( self.app.install_model.ToolShedRepository.table.c.name,
+ self.app.install_model.ToolShedRepository.table.c.owner )
+ else:
+ return self.app.install_model.context.query( self.app.install_model.ToolShedRepository ) \
+ .filter( self.app.install_model.ToolShedRepository.table.c.uninstalled == False )
+
def reset_all_metadata_on_installed_repository( self, id ):
"""Reset all metadata on a single tool shed repository installed into a Galaxy instance."""
invalid_file_tups = []
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/tool_shed/metadata/repository_metadata_manager.py
--- a/lib/tool_shed/metadata/repository_metadata_manager.py
+++ b/lib/tool_shed/metadata/repository_metadata_manager.py
@@ -2,11 +2,13 @@
import os
import tempfile
+from galaxy import util
from galaxy.util import inflector
-from galaxy import util
+from galaxy.web.form_builder import SelectField
from tool_shed.metadata import metadata_generator
from tool_shed.repository_types.metadata import TipOnly
+from tool_shed.repository_types import util as rt_util
from tool_shed.util import basic_util
from tool_shed.util import common_util
@@ -20,9 +22,10 @@
class RepositoryMetadataManager( metadata_generator.MetadataGenerator ):
- def __init__( self, app ):
+ def __init__( self, app, user ):
super( RepositoryMetadataManager, self ).__init__( app )
self.app = app
+ self.user = user
# Repository metadata comparisons for changeset revisions.
self.EQUAL = 'equal'
self.NO_METADATA = 'no metadata'
@@ -47,6 +50,18 @@
self.sa_session.add( repository_metadata )
self.sa_session.flush()
+ def build_repository_ids_select_field( self, name='repository_ids', multiple=True, display='checkboxes',
+ my_writable=False ):
+ """Generate the current list of repositories for resetting metadata."""
+ repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
+ query = self.get_query_for_setting_metadata_on_repositories( my_writable=my_writable, order=True )
+ for repository in query:
+ owner = str( repository.user.username )
+ option_label = '%s (%s)' % ( str( repository.name ), owner )
+ option_value = '%s' % self.app.security.encode_id( repository.id )
+ repositories_select_field.add_option( option_label, option_value )
+ return repositories_select_field
+
def clean_repository_metadata( self, id, changeset_revisions ):
# Delete all repository_metadata records associated with the repository that have
# a changeset_revision that is not in changeset_revisions. We sometimes see multiple
@@ -458,6 +473,54 @@
# The tool did not change through all of the changeset revisions.
return old_id
+ def get_query_for_setting_metadata_on_repositories( self, my_writable=False, order=True ):
+ """
+ Return a query containing repositories for resetting metadata. The order parameter
+ is used for displaying the list of repositories ordered alphabetically for display on
+ a page. When called from the Tool Shed API, order is False.
+ """
+ # When called from the Tool Shed API, the metadata is reset on all repositories of types
+ # repository_suite_definition and tool_dependency_definition in addition to other selected
+ # repositories.
+ if my_writable:
+ username = self.user.username
+ clause_list = []
+ for repository in self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.deleted == False ):
+ # Always reset metadata on all repositories of types repository_suite_definition and
+ # tool_dependency_definition.
+ if repository.type in [ rt_util.REPOSITORY_SUITE_DEFINITION, rt_util.TOOL_DEPENDENCY_DEFINITION ]:
+ clause_list.append( self.app.model.Repository.table.c.id == repository.id )
+ else:
+ allow_push = repository.allow_push( self.app )
+ if allow_push:
+ # Include all repositories that are writable by the current user.
+ allow_push_usernames = allow_push.split( ',' )
+ if username in allow_push_usernames:
+ clause_list.append( self.app.model.Repository.table.c.id == repository.id )
+ if clause_list:
+ if order:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( or_( *clause_list ) ) \
+ .order_by( self.app.model.Repository.table.c.name,
+ self.app.model.Repository.table.c.user_id )
+ else:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( or_( *clause_list ) )
+ else:
+ # Return an empty query.
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.id == -1 )
+ else:
+ if order:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.deleted == False ) \
+ .order_by( self.app.model.Repository.table.c.name,
+ self.app.model.Repository.table.c.user_id )
+ else:
+ return self.sa_session.query( self.app.model.Repository ) \
+ .filter( self.app.model.Repository.table.c.deleted == False )
+
def new_datatypes_metadata_required( self, repository_metadata, metadata_dict ):
"""
Compare the last saved metadata for each datatype in the repository with the new metadata
@@ -732,13 +795,13 @@
# repository_metadata table record is not needed.
return False
- def reset_all_metadata_on_repository_in_tool_shed( self, user, id ):
+ def reset_all_metadata_on_repository_in_tool_shed( self, id ):
"""Reset all metadata on a single repository in a tool shed."""
repository = suc.get_repository_in_tool_shed( self.app, id )
log.debug( "Resetting all metadata on repository: %s" % repository.name )
repo_dir = repository.repo_path( self.app )
repo = hg_util.get_repo_for_repository( self.app, repository=None, repo_path=repo_dir, create=False )
- repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( user, repository )
+ repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( self.user, repository )
# The list of changeset_revisions refers to repository_metadata records that have been created
# or updated. When the following loop completes, we'll delete all repository_metadata records
# for this repository that do not have a changeset_revision value in this list.
@@ -875,7 +938,7 @@
self.sa_session.add( repository_metadata )
self.sa_session.flush()
- def reset_metadata_on_selected_repositories( self, user, **kwd ):
+ def reset_metadata_on_selected_repositories( self, **kwd ):
"""
Inspect the repository changelog to reset metadata for all appropriate changeset revisions.
This method is called from both Galaxy and the Tool Shed.
@@ -892,7 +955,7 @@
repository = suc.get_repository_in_tool_shed( self.app, repository_id )
owner = str( repository.user.username )
invalid_file_tups, metadata_dict = \
- self.reset_all_metadata_on_repository_in_tool_shed( user, repository_id )
+ self.reset_all_metadata_on_repository_in_tool_shed( self.user, repository_id )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( self.app,
invalid_file_tups,
@@ -918,7 +981,7 @@
status = 'error'
return message, status
- def set_repository_metadata( self, host, user, repository, content_alert_str='', **kwd ):
+ def set_repository_metadata( self, host, repository, content_alert_str='', **kwd ):
"""
Set metadata using the repository's current disk files, returning specific error
messages (if any) to alert the repository owner that the changeset has problems.
@@ -926,7 +989,7 @@
message = ''
status = 'done'
encoded_id = self.app.security.encode_id( repository.id )
- repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( user, repository )
+ repository_clone_url = common_util.generate_clone_url_for_repository_in_tool_shed( self.user, repository )
repo_dir = repository.repo_path( self.app )
repo = hg_util.get_repo_for_repository( self.app, repository=None, repo_path=repo_dir, create=False )
metadata_dict, invalid_file_tups = \
@@ -1027,10 +1090,9 @@
tool_util.reset_tool_data_tables( self.app )
return message, status
- def set_repository_metadata_due_to_new_tip( self, host, user, repository, content_alert_str=None, **kwd ):
+ def set_repository_metadata_due_to_new_tip( self, host, repository, content_alert_str=None, **kwd ):
"""Set metadata on the repository tip in the tool shed."""
error_message, status = self.set_repository_metadata( host,
- user,
repository,
content_alert_str=content_alert_str,
**kwd )
diff -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 -r 0eaf1edd08e3b79ebbbe68921baef2f94bb4804d lib/tool_shed/util/shed_util_common.py
--- a/lib/tool_shed/util/shed_util_common.py
+++ b/lib/tool_shed/util/shed_util_common.py
@@ -84,20 +84,6 @@
'${host}'
"""
-def build_repository_ids_select_field( trans, name='repository_ids', multiple=True, display='checkboxes', my_writable=False ):
- """Method called from both Galaxy and the Tool Shed to generate the current list of repositories for resetting metadata."""
- repositories_select_field = SelectField( name=name, multiple=multiple, display=display )
- query = get_query_for_setting_metadata_on_repositories( trans, my_writable=my_writable, order=True )
- for repository in query:
- if trans.webapp.name == 'tool_shed':
- owner = str( repository.user.username )
- else:
- owner = str( repository.owner )
- option_label = '%s (%s)' % ( str( repository.name ), owner )
- option_value = '%s' % trans.security.encode_id( repository.id )
- repositories_select_field.add_option( option_label, option_value )
- return repositories_select_field
-
def build_tool_dependencies_select_field( app, tool_shed_repository, name, multiple=True, display='checkboxes', uninstalled_only=False ):
"""Method called from Galaxy to generate the current list of tool dependency ids for an installed tool shed repository."""
tool_dependencies_select_field = SelectField( name=name, multiple=multiple, display=display )
@@ -645,66 +631,6 @@
prior_import_or_install_required_dict[ encoded_repository_id ] = prior_import_or_install_ids
return prior_import_or_install_required_dict
-def get_query_for_setting_metadata_on_repositories( trans, my_writable=False, order=True ):
- """
- Return a query containing repositories for resetting metadata. This method is called from both the
- Tool Shed and Galaxy. The my_writable parameter is ignored unless called from the Tool Shed, and the
- order parameter is used for displaying the list of repositories ordered alphabetically for display on
- a page. When called from either the Tool Shed or Galaxy API, order is False.
- """
- if trans.webapp.name == 'tool_shed':
- # When called from the Tool Shed API, the metadata is reset on all repositories of types
- # repository_suite_definition and tool_dependency_definition in addition to other selected
- # repositories.
- if my_writable:
- username = trans.user.username
- clause_list = []
- for repository in trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.deleted == False ):
- # Always reset metadata on all repositories of types repository_suite_definition and
- # tool_dependency_definition.
- if repository.type in [ rt_util.REPOSITORY_SUITE_DEFINITION, rt_util.TOOL_DEPENDENCY_DEFINITION ]:
- clause_list.append( trans.model.Repository.table.c.id == repository.id )
- else:
- allow_push = repository.allow_push( trans.app )
- if allow_push:
- # Include all repositories that are writable by the current user.
- allow_push_usernames = allow_push.split( ',' )
- if username in allow_push_usernames:
- clause_list.append( trans.model.Repository.table.c.id == repository.id )
- if clause_list:
- if order:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( or_( *clause_list ) ) \
- .order_by( trans.model.Repository.table.c.name,
- trans.model.Repository.table.c.user_id )
- else:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( or_( *clause_list ) )
- else:
- # Return an empty query.
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.id == -1 )
- else:
- if order:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.deleted == False ) \
- .order_by( trans.model.Repository.table.c.name,
- trans.model.Repository.table.c.user_id )
- else:
- return trans.sa_session.query( trans.model.Repository ) \
- .filter( trans.model.Repository.table.c.deleted == False )
- else:
- # We're in Galaxy.
- if order:
- return trans.install_model.context.query( trans.install_model.ToolShedRepository ) \
- .filter( trans.install_model.ToolShedRepository.table.c.uninstalled == False ) \
- .order_by( trans.install_model.ToolShedRepository.table.c.name,
- trans.install_model.ToolShedRepository.table.c.owner )
- else:
- return trans.install_model.context.query( trans.install_model.ToolShedRepository ) \
- .filter( trans.install_model.ToolShedRepository.table.c.uninstalled == False )
-
def get_repo_info_tuple_contents( repo_info_tuple ):
"""Take care in handling the repo_info_tuple as it evolves over time as new tool shed features are introduced."""
if len( repo_info_tuple ) == 6:
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.
1
0
commit/galaxy-central: greg: Add a ToolPanelManager for Galaxy installs from the Tool Shed.
by commits-noreply@bitbucket.org 21 Jul '14
by commits-noreply@bitbucket.org 21 Jul '14
21 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/f8bf7a37c694/
Changeset: f8bf7a37c694
User: greg
Date: 2014-07-21 17:36:29
Summary: Add a ToolPanelManager for Galaxy installs from the Tool Shed.
Affected #: 9 files
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
--- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
+++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
@@ -30,6 +30,7 @@
from tool_shed.galaxy_install.metadata.installed_repository_metadata_manager import InstalledRepositoryMetadataManager
from tool_shed.galaxy_install.repair_repository_manager import RepairRepositoryManager
from tool_shed.galaxy_install.repository_dependencies import repository_dependency_manager
+from tool_shed.galaxy_install.tools import tool_panel_manager
log = logging.getLogger( __name__ )
@@ -244,10 +245,10 @@
if kwd.get( 'deactivate_or_uninstall_repository_button', False ):
if tool_shed_repository.includes_tools_for_display_in_tool_panel:
# Handle tool panel alterations.
- tool_util.remove_from_tool_panel( trans.app,
- tool_shed_repository,
- shed_tool_conf,
- uninstall=remove_from_disk_checked )
+ tpm = tool_panel_manager.ToolPanelManager( trans.app )
+ tpm.remove_from_tool_panel( tool_shed_repository,
+ shed_tool_conf,
+ uninstall=remove_from_disk_checked )
if tool_shed_repository.includes_data_managers:
data_manager_util.remove_from_data_manager( trans.app, tool_shed_repository )
if tool_shed_repository.includes_datatypes:
@@ -1336,13 +1337,14 @@
# its repository dependencies.
includes_tool_dependencies = tool_shed_repository.includes_tool_dependencies
if tool_shed_repository.includes_tools_for_display_in_tool_panel:
+ tpm = tool_panel_manager.ToolPanelManager( trans.app )
# Handle the selected tool panel location for loading tools included in the tool shed repository.
tool_section, tool_panel_section_key = \
- tool_util.handle_tool_panel_selection( toolbox=trans.app.toolbox,
- metadata=metadata,
- no_changes_checked=no_changes_checked,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_selection( toolbox=trans.app.toolbox,
+ metadata=metadata,
+ no_changes_checked=no_changes_checked,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
if tool_section is not None:
# Just in case the tool_section.id differs from tool_panel_section_id, which it shouldn't...
tool_panel_section_id = str( tool_section.id )
@@ -1942,19 +1944,19 @@
updating_installed_repository=True,
persist=True )
if 'tools' in metadata_dict:
+ tpm = tool_panel_manager.ToolPanelManager( trans.app )
tool_panel_dict = metadata_dict.get( 'tool_panel_section', None )
if tool_panel_dict is None:
tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( trans.app, repository )
repository_tools_tups = suc.get_repository_tools_tups( trans.app, metadata_dict )
- tool_util.add_to_tool_panel( app=trans.app,
- repository_name=str( repository.name ),
- repository_clone_url=repository_clone_url,
- changeset_revision=str( repository.installed_changeset_revision ),
- repository_tools_tups=repository_tools_tups,
- owner=str( repository.owner ),
- shed_tool_conf=shed_tool_conf,
- tool_panel_dict=tool_panel_dict,
- new_install=False )
+ tpm.add_to_tool_panel( repository_name=str( repository.name ),
+ repository_clone_url=repository_clone_url,
+ changeset_revision=str( repository.installed_changeset_revision ),
+ repository_tools_tups=repository_tools_tups,
+ owner=str( repository.owner ),
+ shed_tool_conf=shed_tool_conf,
+ tool_panel_dict=tool_panel_dict,
+ new_install=False )
# Add new Data Manager entries
if 'data_manager' in metadata_dict:
new_data_managers = data_manager_util.install_data_managers( trans.app,
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/galaxy_install/install_manager.py
--- a/lib/tool_shed/galaxy_install/install_manager.py
+++ b/lib/tool_shed/galaxy_install/install_manager.py
@@ -33,6 +33,7 @@
from tool_shed.galaxy_install.tool_dependencies.recipe.install_environment import InstallEnvironment
from tool_shed.galaxy_install.tool_dependencies.recipe.recipe_manager import StepManager
from tool_shed.galaxy_install.tool_dependencies.recipe.recipe_manager import TagManager
+from tool_shed.galaxy_install.tools import tool_panel_manager
log = logging.getLogger( __name__ )
@@ -535,7 +536,8 @@
self.app.config.shed_tool_data_table_config,
persist=True )
if 'tools' in metadata_dict:
- tool_panel_dict = tool_util.generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section )
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
+ tool_panel_dict = tpm.generate_tool_panel_dict_for_new_install( metadata_dict[ 'tools' ], tool_section )
sample_files = metadata_dict.get( 'sample_files', [] )
tool_index_sample_files = tool_util.get_tool_index_sample_files( sample_files )
tool_util.copy_sample_files( self.app, tool_index_sample_files, tool_path=tool_path )
@@ -555,16 +557,18 @@
sample_files_copied )
# Copy remaining sample files included in the repository to the ~/tool-data directory of the
# local Galaxy instance.
- tool_util.copy_sample_files( self.app, sample_files, tool_path=tool_path, sample_files_copied=sample_files_copied )
- tool_util.add_to_tool_panel( app=self.app,
- repository_name=tool_shed_repository.name,
- repository_clone_url=repository_clone_url,
- changeset_revision=tool_shed_repository.installed_changeset_revision,
- repository_tools_tups=repository_tools_tups,
- owner=tool_shed_repository.owner,
- shed_tool_conf=shed_tool_conf,
- tool_panel_dict=tool_panel_dict,
- new_install=True )
+ tool_util.copy_sample_files( self.app,
+ sample_files,
+ tool_path=tool_path,
+ sample_files_copied=sample_files_copied )
+ tpm.add_to_tool_panel( repository_name=tool_shed_repository.name,
+ repository_clone_url=repository_clone_url,
+ changeset_revision=tool_shed_repository.installed_changeset_revision,
+ repository_tools_tups=repository_tools_tups,
+ owner=tool_shed_repository.owner,
+ shed_tool_conf=shed_tool_conf,
+ tool_panel_dict=tool_panel_dict,
+ new_install=True )
if 'data_manager' in metadata_dict:
new_data_managers = data_manager_util.install_data_managers( self.app,
self.app.config.shed_data_manager_config_file,
@@ -644,10 +648,11 @@
tool_shed_url = installation_dict[ 'tool_shed_url' ]
# Handle contained tools.
if includes_tools_for_display_in_tool_panel and ( new_tool_panel_section_label or tool_panel_section_id ):
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
tool_panel_section_key, tool_section = \
- tool_util.handle_tool_panel_section( self.app.toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_section( self.app.toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
else:
tool_panel_section_key = None
tool_section = None
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/galaxy_install/installed_repository_manager.py
--- a/lib/tool_shed/galaxy_install/installed_repository_manager.py
+++ b/lib/tool_shed/galaxy_install/installed_repository_manager.py
@@ -11,11 +11,11 @@
from tool_shed.util import datatype_util
from tool_shed.util import shed_util_common as suc
from tool_shed.util import tool_dependency_util
-from tool_shed.util import tool_util
from tool_shed.util import xml_util
from galaxy.model.orm import and_
from tool_shed.galaxy_install.repository_dependencies import repository_dependency_manager
+from tool_shed.galaxy_install.tools import tool_panel_manager
log = logging.getLogger( __name__ )
@@ -80,19 +80,19 @@
repository.deleted = False
repository.status = self.install_model.ToolShedRepository.installation_status.INSTALLED
if repository.includes_tools_for_display_in_tool_panel:
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
metadata = repository.metadata
repository_tools_tups = suc.get_repository_tools_tups( self.app, metadata )
# Reload tools into the appropriate tool panel section.
tool_panel_dict = repository.metadata[ 'tool_panel_section' ]
- tool_util.add_to_tool_panel( self.app,
- repository.name,
- repository_clone_url,
- repository.installed_changeset_revision,
- repository_tools_tups,
- repository.owner,
- shed_tool_conf,
- tool_panel_dict,
- new_install=False )
+ tpm.add_to_tool_panel( repository.name,
+ repository_clone_url,
+ repository.installed_changeset_revision,
+ repository_tools_tups,
+ repository.owner,
+ shed_tool_conf,
+ tool_panel_dict,
+ new_install=False )
if repository.includes_data_managers:
tp, data_manager_relative_install_dir = repository.get_tool_relative_path( self.app )
# Hack to add repository.name here, which is actually the root of the installed repository
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/galaxy_install/repair_repository_manager.py
--- a/lib/tool_shed/galaxy_install/repair_repository_manager.py
+++ b/lib/tool_shed/galaxy_install/repair_repository_manager.py
@@ -5,13 +5,14 @@
from tool_shed.galaxy_install import install_manager
from tool_shed.galaxy_install.repository_dependencies import repository_dependency_manager
+from tool_shed.galaxy_install.tools import tool_panel_manager
from tool_shed.util import common_util
from tool_shed.util import container_util
from tool_shed.util import shed_util_common as suc
from tool_shed.util import repository_maintenance_util
from tool_shed.util import tool_dependency_util
-from tool_shed.util import tool_util
+
class RepairRepositoryManager():
@@ -119,10 +120,11 @@
tool_panel_section_id = section_dict[ 'id' ]
tool_panel_section_name = section_dict[ 'name' ]
if tool_panel_section_id:
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
tool_panel_section_key, tool_panel_section = \
- tool_util.get_or_create_tool_section( self.app.toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=tool_panel_section_name )
+ tpm.get_or_create_tool_section( self.app.toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=tool_panel_section_name )
else:
tool_dependencies = None
repo_info_dict = repository_maintenance_util.create_repo_info_dict( app=self.app,
@@ -156,15 +158,17 @@
log.debug( error_message )
repair_dict [ repository.name ] = error_message
elif repository.status not in [ self.app.install_model.ToolShedRepository.installation_status.INSTALLED ]:
- shed_tool_conf, tool_path, relative_install_dir = suc.get_tool_panel_config_tool_path_install_dir( self.app, repository )
+ shed_tool_conf, tool_path, relative_install_dir = \
+ suc.get_tool_panel_config_tool_path_install_dir( self.app, repository )
# Reset the repository attributes to the New state for installation.
if metadata:
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
tool_section, tool_panel_section_key = \
- tool_util.handle_tool_panel_selection( self.app.toolbox,
- metadata,
- no_changes_checked=True,
- tool_panel_section_id=None,
- new_tool_panel_section_label=None )
+ tpm.handle_tool_panel_selection( self.app.toolbox,
+ metadata,
+ no_changes_checked=True,
+ tool_panel_section_id=None,
+ new_tool_panel_section_label=None )
else:
# The tools will be loaded outside of any sections in the tool panel.
tool_panel_section_key = None
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
--- a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
+++ b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py
@@ -10,11 +10,12 @@
from galaxy.util import asbool
+from tool_shed.galaxy_install.tools import tool_panel_manager
+
from tool_shed.util import common_util
from tool_shed.util import container_util
from tool_shed.util import encoding_util
from tool_shed.util import shed_util_common as suc
-from tool_shed.util import tool_util
log = logging.getLogger( __name__ )
@@ -216,19 +217,20 @@
if can_update_db_record:
# The database record for the tool shed repository currently being processed can be updated.
# Get the repository metadata to see where it was previously located in the tool panel.
+ tpm = tool_panel_manager.ToolPanelManager( self.app )
if repository_db_record and repository_db_record.metadata:
tool_section, tool_panel_section_key = \
- tool_util.handle_tool_panel_selection( toolbox=self.app.toolbox,
- metadata=repository_db_record.metadata,
- no_changes_checked=no_changes_checked,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_selection( toolbox=self.app.toolbox,
+ metadata=repository_db_record.metadata,
+ no_changes_checked=no_changes_checked,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
else:
# We're installing a new tool shed repository that does not yet have a database record.
tool_panel_section_key, tool_section = \
- tool_util.handle_tool_panel_section( self.app.toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
+ tpm.handle_tool_panel_section( self.app.toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
tool_shed_repository = \
suc.create_or_update_tool_shed_repository( app=self.app,
name=name,
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/galaxy_install/tool_migration_manager.py
--- a/lib/tool_shed/galaxy_install/tool_migration_manager.py
+++ b/lib/tool_shed/galaxy_install/tool_migration_manager.py
@@ -14,6 +14,7 @@
from tool_shed.galaxy_install import install_manager
from tool_shed.galaxy_install.metadata.installed_repository_metadata_manager import InstalledRepositoryMetadataManager
+from tool_shed.galaxy_install.tools import tool_panel_manager
from tool_shed.util import basic_util
from tool_shed.util import common_util
@@ -30,23 +31,31 @@
class ToolMigrationManager( object ):
- def __init__( self, app, latest_migration_script_number, tool_shed_install_config, migrated_tools_config, install_dependencies ):
+ def __init__( self, app, latest_migration_script_number, tool_shed_install_config, migrated_tools_config,
+ install_dependencies ):
"""
- Check tool settings in tool_shed_install_config and install all repositories that are not already installed. The tool
- panel configuration file is the received migrated_tools_config, which is the reserved file named migrated_tools_conf.xml.
+ Check tool settings in tool_shed_install_config and install all repositories
+ that are not already installed. The tool panel configuration file is the received
+ migrated_tools_config, which is the reserved file named migrated_tools_conf.xml.
"""
self.app = app
self.toolbox = self.app.toolbox
self.migrated_tools_config = migrated_tools_config
- # If install_dependencies is True but tool_dependency_dir is not set, do not attempt to install but print informative error message.
+ self.tpm = tool_panel_manager.ToolPanelManager( self.app )
+ # If install_dependencies is True but tool_dependency_dir is not set, do not attempt
+ # to install but print informative error message.
if install_dependencies and app.config.tool_dependency_dir is None:
- message = 'You are attempting to install tool dependencies but do not have a value for "tool_dependency_dir" set in your universe_wsgi.ini '
- message += 'file. Set this location value to the path where you want tool dependencies installed and rerun the migration script.'
+ message = 'You are attempting to install tool dependencies but do not have a value '
+ message += 'for "tool_dependency_dir" set in your universe_wsgi.ini file. Set this '
+ message += 'location value to the path where you want tool dependencies installed and '
+ message += 'rerun the migration script.'
raise Exception( message )
- # Get the local non-shed related tool panel configs (there can be more than one, and the default name is tool_conf.xml).
+ # Get the local non-shed related tool panel configs (there can be more than one, and the
+ # default name is tool_conf.xml).
self.proprietary_tool_confs = self.non_shed_tool_panel_configs
self.proprietary_tool_panel_elems = self.get_proprietary_tool_panel_elems( latest_migration_script_number )
- # Set the location where the repositories will be installed by retrieving the tool_path setting from migrated_tools_config.
+ # Set the location where the repositories will be installed by retrieving the tool_path
+ # setting from migrated_tools_config.
tree, error_message = xml_util.parse_xml( migrated_tools_config )
if tree is None:
print error_message
@@ -66,21 +75,24 @@
self.tool_shed = common_util.remove_protocol_and_port_from_tool_shed_url( self.tool_shed_url )
self.repository_owner = common_util.REPOSITORY_OWNER
index, self.shed_config_dict = suc.get_shed_tool_conf_dict( app, self.migrated_tools_config )
- # Since tool migration scripts can be executed any number of times, we need to make sure the appropriate tools are defined in
- # tool_conf.xml. If no tools associated with the migration stage are defined, no repositories will be installed on disk.
- # The default behavior is that the tool shed is down.
+ # Since tool migration scripts can be executed any number of times, we need to
+ # make sure the appropriate tools are defined in tool_conf.xml. If no tools
+ # associated with the migration stage are defined, no repositories will be installed
+ # on disk. The default behavior is that the tool shed is down.
tool_shed_accessible = False
tool_panel_configs = common_util.get_non_shed_tool_panel_configs( app )
if tool_panel_configs:
# The missing_tool_configs_dict contents are something like:
# {'emboss_antigenic.xml': [('emboss', '5.0.0', 'package', '\nreadme blah blah blah\n')]}
- tool_shed_accessible, missing_tool_configs_dict = common_util.check_for_missing_tools( app,
- tool_panel_configs,
- latest_migration_script_number )
+ tool_shed_accessible, missing_tool_configs_dict = \
+ common_util.check_for_missing_tools( app,
+ tool_panel_configs,
+ latest_migration_script_number )
else:
- # It doesn't matter if the tool shed is accessible since there are no migrated tools defined in the local Galaxy instance, but
- # we have to set the value of tool_shed_accessible to True so that the value of migrate_tools.version can be correctly set in
- # the database.
+ # It doesn't matter if the tool shed is accessible since there are no migrated
+ # tools defined in the local Galaxy instance, but we have to set the value of
+ # tool_shed_accessible to True so that the value of migrate_tools.version can
+ # be correctly set in the database.
tool_shed_accessible = True
missing_tool_configs_dict = odict()
if tool_shed_accessible:
@@ -93,15 +105,18 @@
if missing_tool_configs_dict:
for proprietary_tool_conf in self.proprietary_tool_confs:
# Create a backup of the tool configuration in the un-migrated state.
- shutil.copy( proprietary_tool_conf, '%s-pre-stage-%04d' % ( proprietary_tool_conf, latest_migration_script_number ) )
+ shutil.copy( proprietary_tool_conf, '%s-pre-stage-%04d' % ( proprietary_tool_conf,
+ latest_migration_script_number ) )
for repository_elem in root:
# Make sure we have a valid repository tag.
if self.__is_valid_repository_tag( repository_elem ):
- # Get all repository dependencies for the repository defined by the current repository_elem. Repository dependency
- # definitions contained in tool shed repositories with migrated tools must never define a relationship to a repository
- # dependency that contains a tool. The repository dependency can only contain items that are not loaded into the Galaxy
- # tool panel (e.g., tool dependency definitions, custom datatypes, etc). This restriction must be followed down the
- # entire dependency hierarchy.
+ # Get all repository dependencies for the repository defined by the
+ # current repository_elem. Repository dependency definitions contained
+ # in tool shed repositories with migrated tools must never define a
+ # relationship to a repository dependency that contains a tool. The
+ # repository dependency can only contain items that are not loaded into
+ # the Galaxy tool panel (e.g., tool dependency definitions, custom datatypes,
+ # etc). This restriction must be followed down the entire dependency hierarchy.
name = repository_elem.get( 'name' )
changeset_revision = repository_elem.get( 'changeset_revision' )
tool_shed_accessible, repository_dependencies_dict = \
@@ -110,30 +125,38 @@
name,
self.repository_owner,
changeset_revision )
- # Make sure all repository dependency records exist (as tool_shed_repository table rows) in the Galaxy database.
- created_tool_shed_repositories = self.create_or_update_tool_shed_repository_records( name,
- changeset_revision,
- repository_dependencies_dict )
+ # Make sure all repository dependency records exist (as tool_shed_repository
+ # table rows) in the Galaxy database.
+ created_tool_shed_repositories = \
+ self.create_or_update_tool_shed_repository_records( name,
+ changeset_revision,
+ repository_dependencies_dict )
# Order the repositories for proper installation. This process is similar to the
# process used when installing tool shed repositories, but does not handle managing
# tool panel sections and other components since repository dependency definitions
# contained in tool shed repositories with migrated tools must never define a relationship
# to a repository dependency that contains a tool.
- ordered_tool_shed_repositories = self.order_repositories_for_installation( created_tool_shed_repositories,
- repository_dependencies_dict )
+ ordered_tool_shed_repositories = \
+ self.order_repositories_for_installation( created_tool_shed_repositories,
+ repository_dependencies_dict )
for tool_shed_repository in ordered_tool_shed_repositories:
- is_repository_dependency = self.__is_repository_dependency( name, changeset_revision, tool_shed_repository )
+ is_repository_dependency = self.__is_repository_dependency( name,
+ changeset_revision,
+ tool_shed_repository )
self.install_repository( repository_elem,
tool_shed_repository,
install_dependencies,
is_repository_dependency=is_repository_dependency )
else:
- message = "\nNo tools associated with migration stage %s are defined in your " % str( latest_migration_script_number )
- message += "file%s named %s,\nso no repositories will be installed on disk.\n" % ( plural, file_names )
+ message = "\nNo tools associated with migration stage %s are defined in your " % \
+ str( latest_migration_script_number )
+ message += "file%s named %s,\nso no repositories will be installed on disk.\n" % \
+ ( plural, file_names )
print message
else:
- message = "\nThe main Galaxy tool shed is not currently available, so skipped migration stage %s.\n" % str( latest_migration_script_number )
+ message = "\nThe main Galaxy tool shed is not currently available, so skipped migration stage %s.\n" % \
+ str( latest_migration_script_number )
message += "Try again later.\n"
print message
@@ -354,16 +377,21 @@
repo_install_dir = relative_install_dir
if not is_repository_dependency:
for tool_elem in repository_elem:
- # The tool_elem looks something like this: <tool id="EMBOSS: antigenic1" version="5.0.0" file="emboss_antigenic.xml" />
+ # The tool_elem looks something like this:
+ # <tool id="EMBOSS: antigenic1" version="5.0.0" file="emboss_antigenic.xml" />
tool_config = tool_elem.get( 'file' )
guid = self.get_guid( repository_clone_url, relative_install_dir, tool_config )
# See if tool_config is defined inside of a section in self.proprietary_tool_panel_elems.
is_displayed, tool_sections = self.get_containing_tool_sections( tool_config )
if is_displayed:
tool_panel_dict_for_tool_config = \
- tool_util.generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=tool_sections )
+ self.tpm.generate_tool_panel_dict_for_tool_config( guid,
+ tool_config,
+ tool_sections=tool_sections )
# The tool-panel_dict has the following structure.
- # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>,
+ # {<Tool guid> : [{ tool_config : <tool_config_file>,
+ # id: <ToolSection id>,
+ # version : <ToolSection version>,
# name : <TooSection name>}]}
for k, v in tool_panel_dict_for_tool_config.items():
tool_panel_dict_for_display[ k ] = v
@@ -433,15 +461,14 @@
tool_path=self.tool_path,
sample_files_copied=sample_files_copied )
if not is_repository_dependency:
- tool_util.add_to_tool_panel( self.app,
- tool_shed_repository.name,
- repository_clone_url,
- tool_shed_repository.installed_changeset_revision,
- repository_tools_tups,
- self.repository_owner,
- self.migrated_tools_config,
- tool_panel_dict=tool_panel_dict_for_display,
- new_install=True )
+ self.tpm.add_to_tool_panel( tool_shed_repository.name,
+ repository_clone_url,
+ tool_shed_repository.installed_changeset_revision,
+ repository_tools_tups,
+ self.repository_owner,
+ self.migrated_tools_config,
+ tool_panel_dict=tool_panel_dict_for_display,
+ new_install=True )
if install_dependencies and tool_dependencies and has_tool_dependencies:
# Install tool dependencies.
suc.update_tool_shed_repository_status( self.app,
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/galaxy_install/tools/tool_panel_manager.py
--- /dev/null
+++ b/lib/tool_shed/galaxy_install/tools/tool_panel_manager.py
@@ -0,0 +1,465 @@
+import logging
+import os
+
+import galaxy.tools
+from galaxy.tools.search import ToolBoxSearch
+from xml.etree import ElementTree as XmlET
+
+from tool_shed.util import basic_util
+from tool_shed.util import common_util
+from tool_shed.util import shed_util_common as suc
+from tool_shed.util import xml_util
+
+log = logging.getLogger( __name__ )
+
+
+class ToolPanelManager( object ):
+
+ def __init__( self, app ):
+ self.app = app
+
+ def add_to_shed_tool_config( self, shed_tool_conf_dict, elem_list ):
+ # A tool shed repository is being installed so change the shed_tool_conf file. Parse the
+ # config file to generate the entire list of config_elems instead of using the in-memory list
+ # since it will be a subset of the entire list if one or more repositories have been deactivated.
+ shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
+ tool_path = shed_tool_conf_dict[ 'tool_path' ]
+ config_elems = []
+ tree, error_message = xml_util.parse_xml( shed_tool_conf )
+ if tree:
+ root = tree.getroot()
+ for elem in root:
+ config_elems.append( elem )
+ # Add the elements to the in-memory list of config_elems.
+ for elem_entry in elem_list:
+ config_elems.append( elem_entry )
+ # Persist the altered shed_tool_config file.
+ suc.config_elems_to_xml_file( self.app, config_elems, shed_tool_conf, tool_path )
+
+ def add_to_tool_panel( self, repository_name, repository_clone_url, changeset_revision, repository_tools_tups, owner,
+ shed_tool_conf, tool_panel_dict, new_install=True ):
+ """A tool shed repository is being installed or updated so handle tool panel alterations accordingly."""
+ # We need to change the in-memory version and the file system version of the shed_tool_conf file.
+ index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( self.app, shed_tool_conf )
+ tool_path = shed_tool_conf_dict[ 'tool_path' ]
+ # Generate the list of ElementTree Element objects for each section or tool.
+ elem_list = self.generate_tool_panel_elem_list( repository_name,
+ repository_clone_url,
+ changeset_revision,
+ tool_panel_dict,
+ repository_tools_tups,
+ owner=owner )
+ if new_install:
+ # Add the new elements to the shed_tool_conf file on disk.
+ self.add_to_shed_tool_config( shed_tool_conf_dict, elem_list )
+ # Use the new elements to add entries to the
+ config_elems = shed_tool_conf_dict[ 'config_elems' ]
+ for config_elem in elem_list:
+ # Add the new elements to the in-memory list of config_elems.
+ config_elems.append( config_elem )
+ # Load the tools into the in-memory tool panel.
+ if config_elem.tag == 'section':
+ self.app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True )
+ elif config_elem.tag == 'workflow':
+ self.app.toolbox.load_workflow_tag_set( config_elem,
+ self.app.toolbox.tool_panel,
+ self.app.toolbox.integrated_tool_panel,
+ load_panel_dict=True )
+ elif config_elem.tag == 'tool':
+ guid = config_elem.get( 'guid' )
+ self.app.toolbox.load_tool_tag_set( config_elem,
+ self.app.toolbox.tool_panel,
+ self.app.toolbox.integrated_tool_panel,
+ tool_path,
+ load_panel_dict=True,
+ guid=guid )
+ # Replace the old list of in-memory config_elems with the new list for this shed_tool_conf_dict.
+ shed_tool_conf_dict[ 'config_elems' ] = config_elems
+ self.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
+ if self.app.config.update_integrated_tool_panel:
+ # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
+ self.app.toolbox.write_integrated_tool_panel_config_file()
+ self.app.toolbox_search = ToolBoxSearch( self.app.toolbox )
+
+ def generate_tool_panel_dict_for_new_install( self, tool_dicts, tool_section=None ):
+ """
+ When installing a repository that contains tools, all tools must currently be defined
+ within the same tool section in the tool panel or outside of any sections.
+ """
+ tool_panel_dict = {}
+ if tool_section:
+ section_id = tool_section.id
+ section_name = tool_section.name
+ section_version = tool_section.version or ''
+ else:
+ section_id = ''
+ section_name = ''
+ section_version = ''
+ for tool_dict in tool_dicts:
+ if tool_dict.get( 'add_to_tool_panel', True ):
+ guid = tool_dict[ 'guid' ]
+ tool_config = tool_dict[ 'tool_config' ]
+ tool_section_dict = dict( tool_config=tool_config, id=section_id, name=section_name, version=section_version )
+ if guid in tool_panel_dict:
+ tool_panel_dict[ guid ].append( tool_section_dict )
+ else:
+ tool_panel_dict[ guid ] = [ tool_section_dict ]
+ return tool_panel_dict
+
+ def generate_tool_panel_dict_for_tool_config( self, guid, tool_config, tool_sections=None ):
+ """
+ Create a dictionary of the following type for a single tool config file name.
+ The intent is to call this method for every tool config in a repository and
+ append each of these as entries to a tool panel dictionary for the repository.
+ This enables each tool to be loaded into a different section in the tool panel.
+ {<Tool guid> :
+ [{ tool_config : <tool_config_file>,
+ id: <ToolSection id>,
+ version : <ToolSection version>,
+ name : <TooSection name>}]}
+ """
+ tool_panel_dict = {}
+ file_name = basic_util.strip_path( tool_config )
+ tool_section_dicts = self. generate_tool_section_dicts( tool_config=file_name,
+ tool_sections=tool_sections )
+ tool_panel_dict[ guid ] = tool_section_dicts
+ return tool_panel_dict
+
+ def generate_tool_panel_elem_list( self, repository_name, repository_clone_url, changeset_revision,
+ tool_panel_dict, repository_tools_tups, owner='' ):
+ """Generate a list of ElementTree Element objects for each section or tool."""
+ elem_list = []
+ tool_elem = None
+ cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url( repository_clone_url )
+ if not owner:
+ owner = suc.get_repository_owner( cleaned_repository_clone_url )
+ tool_shed = cleaned_repository_clone_url.split( '/repos/' )[ 0 ].rstrip( '/' )
+ for guid, tool_section_dicts in tool_panel_dict.items():
+ for tool_section_dict in tool_section_dicts:
+ tool_section = None
+ inside_section = False
+ section_in_elem_list = False
+ if tool_section_dict[ 'id' ]:
+ inside_section = True
+ # Create a new section element only if we haven't already created it.
+ for index, elem in enumerate( elem_list ):
+ if elem.tag == 'section':
+ section_id = elem.get( 'id', None )
+ if section_id == tool_section_dict[ 'id' ]:
+ section_in_elem_list = True
+ tool_section = elem
+ break
+ if tool_section is None:
+ tool_section = self.generate_tool_section_element_from_dict( tool_section_dict )
+ # Find the tuple containing the current guid from the list of repository_tools_tups.
+ for repository_tool_tup in repository_tools_tups:
+ tool_file_path, tup_guid, tool = repository_tool_tup
+ if tup_guid == guid:
+ break
+ if inside_section:
+ tool_elem = suc.generate_tool_elem( tool_shed,
+ repository_name,
+ changeset_revision,
+ owner,
+ tool_file_path,
+ tool,
+ tool_section )
+ else:
+ tool_elem = suc.generate_tool_elem( tool_shed,
+ repository_name,
+ changeset_revision,
+ owner,
+ tool_file_path,
+ tool,
+ None )
+ if inside_section:
+ if section_in_elem_list:
+ elem_list[ index ] = tool_section
+ else:
+ elem_list.append( tool_section )
+ else:
+ elem_list.append( tool_elem )
+ return elem_list
+
+ def generate_tool_section_dicts( self, tool_config=None, tool_sections=None ):
+ tool_section_dicts = []
+ if tool_config is None:
+ tool_config = ''
+ if tool_sections:
+ for tool_section in tool_sections:
+ # The value of tool_section will be None if the tool is displayed outside
+ # of any sections in the tool panel.
+ if tool_section:
+ section_id = tool_section.id or ''
+ section_version = tool_section.version or ''
+ section_name = tool_section.name or ''
+ else:
+ section_id = ''
+ section_version = ''
+ section_name = ''
+ tool_section_dicts.append( dict( tool_config=tool_config,
+ id=section_id,
+ version=section_version,
+ name=section_name ) )
+ else:
+ tool_section_dicts.append( dict( tool_config=tool_config, id='', version='', name='' ) )
+ return tool_section_dicts
+
+ def generate_tool_section_element_from_dict( self, tool_section_dict ):
+ # The value of tool_section_dict looks like the following.
+ # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}
+ if tool_section_dict[ 'id' ]:
+ # Create a new tool section.
+ tool_section = XmlET.Element( 'section' )
+ tool_section.attrib[ 'id' ] = tool_section_dict[ 'id' ]
+ tool_section.attrib[ 'name' ] = tool_section_dict[ 'name' ]
+ tool_section.attrib[ 'version' ] = tool_section_dict[ 'version' ]
+ else:
+ tool_section = None
+ return tool_section
+
+ def get_or_create_tool_section( self, toolbox, tool_panel_section_id, new_tool_panel_section_label=None ):
+ tool_panel_section_key = str( tool_panel_section_id )
+ if tool_panel_section_key in toolbox.tool_panel:
+ # Appending a tool to an existing section in toolbox.tool_panel
+ tool_section = toolbox.tool_panel[ tool_panel_section_key ]
+ log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) )
+ else:
+ # Appending a new section to toolbox.tool_panel
+ if new_tool_panel_section_label is None:
+ # This might add an ugly section label to the tool panel, but, oh well...
+ new_tool_panel_section_label = tool_panel_section_id
+ elem = XmlET.Element( 'section' )
+ elem.attrib[ 'name' ] = new_tool_panel_section_label
+ elem.attrib[ 'id' ] = tool_panel_section_id
+ elem.attrib[ 'version' ] = ''
+ tool_section = galaxy.tools.ToolSection( elem )
+ toolbox.tool_panel[ tool_panel_section_key ] = tool_section
+ log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) )
+ return tool_panel_section_key, tool_section
+
+ def handle_tool_panel_section( self, toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ):
+ """Return a ToolSection object retrieved from the current in-memory tool_panel."""
+ # If tool_panel_section_id is received, the section exists in the tool panel. In this
+ # case, the value of the received tool_panel_section_id must be the id retrieved from a
+ # tool panel config (e.g., tool_conf.xml, which may have getext). If new_tool_panel_section_label
+ # is received, a new section will be added to the tool panel.
+ if new_tool_panel_section_label:
+ section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) )
+ tool_panel_section_key, tool_section = \
+ self.get_or_create_tool_section( toolbox,
+ tool_panel_section_id=section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
+ elif tool_panel_section_id:
+ tool_panel_section_key = str( tool_panel_section_id )
+ tool_section = toolbox.tool_panel[ tool_panel_section_key ]
+ else:
+ return None, None
+ return tool_panel_section_key, tool_section
+
+ def handle_tool_panel_selection( self, toolbox, metadata, no_changes_checked, tool_panel_section_id,
+ new_tool_panel_section_label ):
+ """
+ Handle the selected tool panel location for loading tools included in tool shed
+ repositories when installing or reinstalling them.
+ """
+ # Get the location in the tool panel in which each tool was originally loaded.
+ tool_section = None
+ tool_panel_section_key = None
+ if 'tools' in metadata:
+ # This forces everything to be loaded into the same section (or no section)
+ # in the tool panel.
+ if no_changes_checked:
+ # Make sure the no_changes check box overrides the new_tool_panel_section_label
+ # if the user checked the check box and entered something into the field.
+ new_tool_panel_section_label = None
+ if 'tool_panel_section' in metadata:
+ tool_panel_dict = metadata[ 'tool_panel_section' ]
+ if not tool_panel_dict:
+ tool_panel_dict = self.generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
+ else:
+ tool_panel_dict = self.generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
+ if tool_panel_dict:
+ # The tool_panel_dict is empty when tools exist but are not installed into a tool panel section.
+ tool_section_dicts = tool_panel_dict[ tool_panel_dict.keys()[ 0 ] ]
+ tool_section_dict = tool_section_dicts[ 0 ]
+ original_section_id = tool_section_dict[ 'id' ]
+ original_section_name = tool_section_dict[ 'name' ]
+ if original_section_id:
+ tool_panel_section_key, tool_section = \
+ self.get_or_create_tool_section( toolbox,
+ tool_panel_section_id=original_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
+ else:
+ # The user elected to change the tool panel section to contain the tools.
+ tool_panel_section_key, tool_section = \
+ self.handle_tool_panel_section( toolbox,
+ tool_panel_section_id=tool_panel_section_id,
+ new_tool_panel_section_label=new_tool_panel_section_label )
+ return tool_section, tool_panel_section_key
+
+ def remove_from_shed_tool_config( self, shed_tool_conf_dict, guids_to_remove ):
+ # A tool shed repository is being uninstalled so change the shed_tool_conf file.
+ # Parse the config file to generate the entire list of config_elems instead of
+ # using the in-memory list since it will be a subset of the entire list if one
+ # or more repositories have been deactivated.
+ shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
+ tool_path = shed_tool_conf_dict[ 'tool_path' ]
+ config_elems = []
+ tree, error_message = xml_util.parse_xml( shed_tool_conf )
+ if tree:
+ root = tree.getroot()
+ for elem in root:
+ config_elems.append( elem )
+ config_elems_to_remove = []
+ for config_elem in config_elems:
+ if config_elem.tag == 'section':
+ tool_elems_to_remove = []
+ for tool_elem in config_elem:
+ if tool_elem.get( 'guid' ) in guids_to_remove:
+ tool_elems_to_remove.append( tool_elem )
+ for tool_elem in tool_elems_to_remove:
+ # Remove all of the appropriate tool sub-elements from the section element.
+ config_elem.remove( tool_elem )
+ if len( config_elem ) < 1:
+ # Keep a list of all empty section elements so they can be removed.
+ config_elems_to_remove.append( config_elem )
+ elif config_elem.tag == 'tool':
+ if config_elem.get( 'guid' ) in guids_to_remove:
+ config_elems_to_remove.append( config_elem )
+ for config_elem in config_elems_to_remove:
+ config_elems.remove( config_elem )
+ # Persist the altered in-memory version of the tool config.
+ suc.config_elems_to_xml_file( self.app, config_elems, shed_tool_conf, tool_path )
+
+ def remove_from_tool_panel( self, repository, shed_tool_conf, uninstall ):
+ """
+ A tool shed repository is being deactivated or uninstalled, so handle tool panel
+ alterations accordingly.
+ """
+ # Determine where the tools are currently defined in the tool panel and store this
+ # information so the tools can be displayed in the same way when the repository is
+ # activated or reinstalled.
+ tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( self.app, repository )
+ repository.metadata[ 'tool_panel_section' ] = tool_panel_dict
+ self.app.install_model.context.add( repository )
+ self.app.install_model.context.flush()
+ # Create a list of guids for all tools that will be removed from the in-memory tool panel
+ # and config file on disk.
+ guids_to_remove = [ k for k in tool_panel_dict.keys() ]
+ # Remove the tools from the toolbox's tools_by_id dictionary.
+ for guid_to_remove in guids_to_remove:
+ if guid_to_remove in self.app.toolbox.tools_by_id:
+ del self.app.toolbox.tools_by_id[ guid_to_remove ]
+ index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( self.app, shed_tool_conf )
+ if uninstall:
+ # Remove from the shed_tool_conf file on disk.
+ self.remove_from_shed_tool_config( shed_tool_conf_dict, guids_to_remove )
+ config_elems = shed_tool_conf_dict[ 'config_elems' ]
+ config_elems_to_remove = []
+ for config_elem in config_elems:
+ if config_elem.tag == 'section':
+ # Get the section key for the in-memory tool panel.
+ section_key = str( config_elem.get( "id" ) )
+ # Generate the list of tool elements to remove.
+ tool_elems_to_remove = []
+ for tool_elem in config_elem:
+ if tool_elem.get( 'guid' ) in guids_to_remove:
+ tool_elems_to_remove.append( tool_elem )
+ for tool_elem in tool_elems_to_remove:
+ if tool_elem in config_elem:
+ # Remove the tool sub-element from the section element.
+ config_elem.remove( tool_elem )
+ # Remove the tool from the section in the in-memory tool panel.
+ if section_key in self.app.toolbox.tool_panel:
+ tool_section = self.app.toolbox.tool_panel[ section_key ]
+ guid = tool_elem.get( 'guid' )
+ tool_key = 'tool_%s' % str( guid )
+ # Get the list of versions of this tool that are currently available in the toolbox.
+ available_tool_versions = self.app.toolbox.get_loaded_tools_by_lineage( guid )
+ if tool_key in tool_section.elems:
+ if available_tool_versions:
+ available_tool_versions.reverse()
+ replacement_tool_key = None
+ replacement_tool_version = None
+ # Since we are going to remove the tool from the section, replace it with the
+ # newest loaded version of the tool.
+ for available_tool_version in available_tool_versions:
+ available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
+ if available_tool_version.id in tool_section.elems.keys() or section_key == available_tool_section_id:
+ replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
+ replacement_tool_version = available_tool_version
+ break
+ if replacement_tool_key and replacement_tool_version:
+ # Get the index of the tool_key in the tool_section.
+ for tool_section_elems_index, key in enumerate( tool_section.elems.keys() ):
+ if key == tool_key:
+ break
+ # Remove the tool from the tool section.
+ del tool_section.elems[ tool_key ]
+ # Add the replacement tool at the same location in the tool section.
+ tool_section.elems.insert( tool_section_elems_index,
+ replacement_tool_key,
+ replacement_tool_version )
+ else:
+ del tool_section.elems[ tool_key ]
+ else:
+ del tool_section.elems[ tool_key ]
+ if uninstall:
+ # Remove the tool from the section in the in-memory integrated tool panel.
+ if section_key in self.app.toolbox.integrated_tool_panel:
+ tool_section = self.app.toolbox.integrated_tool_panel[ section_key ]
+ tool_key = 'tool_%s' % str( tool_elem.get( 'guid' ) )
+ if tool_key in tool_section.elems:
+ del tool_section.elems[ tool_key ]
+ if len( config_elem ) < 1:
+ # Keep a list of all empty section elements so they can be removed.
+ config_elems_to_remove.append( config_elem )
+ elif config_elem.tag == 'tool':
+ guid = config_elem.get( 'guid' )
+ if guid in guids_to_remove:
+ tool_key = 'tool_%s' % str( config_elem.get( 'guid' ) )
+ # Get the list of versions of this tool that are currently available in the toolbox.
+ available_tool_versions = self.app.toolbox.get_loaded_tools_by_lineage( guid )
+ if tool_key in self.app.toolbox.tool_panel:
+ if available_tool_versions:
+ available_tool_versions.reverse()
+ replacement_tool_key = None
+ replacement_tool_version = None
+ # Since we are going to remove the tool from the section, replace it with
+ # the newest loaded version of the tool.
+ for available_tool_version in available_tool_versions:
+ available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
+ if available_tool_version.id in self.app.toolbox.tool_panel.keys() or not available_tool_section_id:
+ replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
+ replacement_tool_version = available_tool_version
+ break
+ if replacement_tool_key and replacement_tool_version:
+ # Get the index of the tool_key in the tool_section.
+ for tool_panel_index, key in enumerate( self.app.toolbox.tool_panel.keys() ):
+ if key == tool_key:
+ break
+ # Remove the tool from the tool panel.
+ del self.app.toolbox.tool_panel[ tool_key ]
+ # Add the replacement tool at the same location in the tool panel.
+ self.app.toolbox.tool_panel.insert( tool_panel_index,
+ replacement_tool_key,
+ replacement_tool_version )
+ else:
+ del self.app.toolbox.tool_panel[ tool_key ]
+ else:
+ del self.app.toolbox.tool_panel[ tool_key ]
+ if uninstall:
+ if tool_key in self.app.toolbox.integrated_tool_panel:
+ del self.app.toolbox.integrated_tool_panel[ tool_key ]
+ config_elems_to_remove.append( config_elem )
+ for config_elem in config_elems_to_remove:
+ # Remove the element from the in-memory list of elements.
+ config_elems.remove( config_elem )
+ # Update the config_elems of the in-memory shed_tool_conf_dict.
+ shed_tool_conf_dict[ 'config_elems' ] = config_elems
+ self.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
+ self.app.toolbox_search = ToolBoxSearch( self.app.toolbox )
+ if uninstall and self.app.config.update_integrated_tool_panel:
+ # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
+ self.app.toolbox.write_integrated_tool_panel_config_file()
diff -r cbca66cc16bfed165f3b38399857ad0b85d14489 -r f8bf7a37c69469d3b4350e0d6b1965cc87dc7a49 lib/tool_shed/util/tool_util.py
--- a/lib/tool_shed/util/tool_util.py
+++ b/lib/tool_shed/util/tool_util.py
@@ -19,69 +19,6 @@
log = logging.getLogger( __name__ )
-def add_to_shed_tool_config( app, shed_tool_conf_dict, elem_list ):
- # A tool shed repository is being installed so change the shed_tool_conf file. Parse the
- # config file to generate the entire list of config_elems instead of using the in-memory list
- # since it will be a subset of the entire list if one or more repositories have been deactivated.
- shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
- tool_path = shed_tool_conf_dict[ 'tool_path' ]
- config_elems = []
- tree, error_message = xml_util.parse_xml( shed_tool_conf )
- if tree:
- root = tree.getroot()
- for elem in root:
- config_elems.append( elem )
- # Add the elements to the in-memory list of config_elems.
- for elem_entry in elem_list:
- config_elems.append( elem_entry )
- # Persist the altered shed_tool_config file.
- suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path )
-
-def add_to_tool_panel( app, repository_name, repository_clone_url, changeset_revision, repository_tools_tups, owner,
- shed_tool_conf, tool_panel_dict, new_install=True ):
- """A tool shed repository is being installed or updated so handle tool panel alterations accordingly."""
- # We need to change the in-memory version and the file system version of the shed_tool_conf file.
- index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf )
- tool_path = shed_tool_conf_dict[ 'tool_path' ]
- # Generate the list of ElementTree Element objects for each section or tool.
- elem_list = generate_tool_panel_elem_list( repository_name,
- repository_clone_url,
- changeset_revision,
- tool_panel_dict,
- repository_tools_tups,
- owner=owner )
- if new_install:
- # Add the new elements to the shed_tool_conf file on disk.
- add_to_shed_tool_config( app, shed_tool_conf_dict, elem_list )
- # Use the new elements to add entries to the
- config_elems = shed_tool_conf_dict[ 'config_elems' ]
- for config_elem in elem_list:
- # Add the new elements to the in-memory list of config_elems.
- config_elems.append( config_elem )
- # Load the tools into the in-memory tool panel.
- if config_elem.tag == 'section':
- app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True )
- elif config_elem.tag == 'workflow':
- app.toolbox.load_workflow_tag_set( config_elem,
- app.toolbox.tool_panel,
- app.toolbox.integrated_tool_panel,
- load_panel_dict=True )
- elif config_elem.tag == 'tool':
- guid = config_elem.get( 'guid' )
- app.toolbox.load_tool_tag_set( config_elem,
- app.toolbox.tool_panel,
- app.toolbox.integrated_tool_panel,
- tool_path,
- load_panel_dict=True,
- guid=guid )
- # Replace the old list of in-memory config_elems with the new list for this shed_tool_conf_dict.
- shed_tool_conf_dict[ 'config_elems' ] = config_elems
- app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
- if app.config.update_integrated_tool_panel:
- # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
- app.toolbox.write_integrated_tool_panel_config_file()
- app.toolbox_search = ToolBoxSearch( app.toolbox )
-
def build_shed_tool_conf_select_field( app ):
"""Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs."""
options = []
@@ -192,142 +129,6 @@
message += "%s%s%s - %s%s" % ( bold_start, tool_file, bold_end, correction_msg, new_line )
return message
-def generate_tool_panel_dict_for_new_install( tool_dicts, tool_section=None ):
- """
- When installing a repository that contains tools, all tools must currently be defined
- within the same tool section in the tool panel or outside of any sections.
- """
- tool_panel_dict = {}
- if tool_section:
- section_id = tool_section.id
- section_name = tool_section.name
- section_version = tool_section.version or ''
- else:
- section_id = ''
- section_name = ''
- section_version = ''
- for tool_dict in tool_dicts:
- if tool_dict.get( 'add_to_tool_panel', True ):
- guid = tool_dict[ 'guid' ]
- tool_config = tool_dict[ 'tool_config' ]
- tool_section_dict = dict( tool_config=tool_config, id=section_id, name=section_name, version=section_version )
- if guid in tool_panel_dict:
- tool_panel_dict[ guid ].append( tool_section_dict )
- else:
- tool_panel_dict[ guid ] = [ tool_section_dict ]
- return tool_panel_dict
-
-def generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=None ):
- """
- Create a dictionary of the following type for a single tool config file name.
- The intent is to call this method for every tool config in a repository and
- append each of these as entries to a tool panel dictionary for the repository.
- This allows for each tool to be loaded into a different section in the tool panel.
- {<Tool guid> :
- [{ tool_config : <tool_config_file>,
- id: <ToolSection id>,
- version : <ToolSection version>,
- name : <TooSection name>}]}
- """
- tool_panel_dict = {}
- file_name = basic_util.strip_path( tool_config )
- tool_section_dicts = generate_tool_section_dicts( tool_config=file_name, tool_sections=tool_sections )
- tool_panel_dict[ guid ] = tool_section_dicts
- return tool_panel_dict
-
-def generate_tool_panel_elem_list( repository_name, repository_clone_url, changeset_revision, tool_panel_dict,
- repository_tools_tups, owner='' ):
- """Generate a list of ElementTree Element objects for each section or tool."""
- elem_list = []
- tool_elem = None
- cleaned_repository_clone_url = common_util.remove_protocol_and_user_from_clone_url( repository_clone_url )
- if not owner:
- owner = suc.get_repository_owner( cleaned_repository_clone_url )
- tool_shed = cleaned_repository_clone_url.split( '/repos/' )[ 0 ].rstrip( '/' )
- for guid, tool_section_dicts in tool_panel_dict.items():
- for tool_section_dict in tool_section_dicts:
- tool_section = None
- inside_section = False
- section_in_elem_list = False
- if tool_section_dict[ 'id' ]:
- inside_section = True
- # Create a new section element only if we haven't already created it.
- for index, elem in enumerate( elem_list ):
- if elem.tag == 'section':
- section_id = elem.get( 'id', None )
- if section_id == tool_section_dict[ 'id' ]:
- section_in_elem_list = True
- tool_section = elem
- break
- if tool_section is None:
- tool_section = generate_tool_section_element_from_dict( tool_section_dict )
- # Find the tuple containing the current guid from the list of repository_tools_tups.
- for repository_tool_tup in repository_tools_tups:
- tool_file_path, tup_guid, tool = repository_tool_tup
- if tup_guid == guid:
- break
- if inside_section:
- tool_elem = suc.generate_tool_elem( tool_shed,
- repository_name,
- changeset_revision,
- owner,
- tool_file_path,
- tool,
- tool_section )
- else:
- tool_elem = suc.generate_tool_elem( tool_shed,
- repository_name,
- changeset_revision,
- owner,
- tool_file_path,
- tool,
- None )
- if inside_section:
- if section_in_elem_list:
- elem_list[ index ] = tool_section
- else:
- elem_list.append( tool_section )
- else:
- elem_list.append( tool_elem )
- return elem_list
-
-def generate_tool_section_dicts( tool_config=None, tool_sections=None ):
- tool_section_dicts = []
- if tool_config is None:
- tool_config = ''
- if tool_sections:
- for tool_section in tool_sections:
- # The value of tool_section will be None if the tool is displayed outside
- # of any sections in the tool panel.
- if tool_section:
- section_id = tool_section.id or ''
- section_version = tool_section.version or ''
- section_name = tool_section.name or ''
- else:
- section_id = ''
- section_version = ''
- section_name = ''
- tool_section_dicts.append( dict( tool_config=tool_config,
- id=section_id,
- version=section_version,
- name=section_name ) )
- else:
- tool_section_dicts.append( dict( tool_config=tool_config, id='', version='', name='' ) )
- return tool_section_dicts
-
-def generate_tool_section_element_from_dict( tool_section_dict ):
- # The value of tool_section_dict looks like the following.
- # { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}
- if tool_section_dict[ 'id' ]:
- # Create a new tool section.
- tool_section = XmlET.Element( 'section' )
- tool_section.attrib[ 'id' ] = tool_section_dict[ 'id' ]
- tool_section.attrib[ 'name' ] = tool_section_dict[ 'name' ]
- tool_section.attrib[ 'version' ] = tool_section_dict[ 'version' ]
- else:
- tool_section = None
- return tool_section
-
def get_headers( fname, sep, count=60, is_multi_byte=False ):
"""Returns a list with the first 'count' lines split by 'sep'."""
headers = []
@@ -341,26 +142,6 @@
break
return headers
-def get_or_create_tool_section( toolbox, tool_panel_section_id, new_tool_panel_section_label=None ):
- tool_panel_section_key = str( tool_panel_section_id )
- if tool_panel_section_key in toolbox.tool_panel:
- # Appending a tool to an existing section in toolbox.tool_panel
- tool_section = toolbox.tool_panel[ tool_panel_section_key ]
- log.debug( "Appending to tool panel section: %s" % str( tool_section.name ) )
- else:
- # Appending a new section to toolbox.tool_panel
- if new_tool_panel_section_label is None:
- # This might add an ugly section label to the tool panel, but, oh well...
- new_tool_panel_section_label = tool_panel_section_id
- elem = XmlET.Element( 'section' )
- elem.attrib[ 'name' ] = new_tool_panel_section_label
- elem.attrib[ 'id' ] = tool_panel_section_id
- elem.attrib[ 'version' ] = ''
- tool_section = galaxy.tools.ToolSection( elem )
- toolbox.tool_panel[ tool_panel_section_key ] = tool_section
- log.debug( "Loading new tool panel section: %s" % str( tool_section.name ) )
- return tool_panel_section_key, tool_section
-
def get_tool_path_install_dir( partial_install_dir, shed_tool_conf_dict, tool_dict, config_elems ):
for elem in config_elems:
if elem.tag == 'tool':
@@ -514,63 +295,6 @@
error = True
return error, message
-def handle_tool_panel_selection( toolbox, metadata, no_changes_checked, tool_panel_section_id, new_tool_panel_section_label ):
- """
- Handle the selected tool panel location for loading tools included in tool shed repositories when installing
- or reinstalling them.
- """
- # Get the location in the tool panel in which each tool was originally loaded.
- tool_section = None
- tool_panel_section_key = None
- if 'tools' in metadata:
- # This forces everything to be loaded into the same section (or no section) in the tool panel.
- if no_changes_checked:
- # Make sure the no_changes check box overrides the new_tool_panel_section_label if the user checked the check
- # box and entered something into the field.
- new_tool_panel_section_label = None
- if 'tool_panel_section' in metadata:
- tool_panel_dict = metadata[ 'tool_panel_section' ]
- if not tool_panel_dict:
- tool_panel_dict = generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
- else:
- tool_panel_dict = generate_tool_panel_dict_for_new_install( metadata[ 'tools' ] )
- if tool_panel_dict:
- # The tool_panel_dict is empty when tools exist but are not installed into a tool panel section.
- tool_section_dicts = tool_panel_dict[ tool_panel_dict.keys()[ 0 ] ]
- tool_section_dict = tool_section_dicts[ 0 ]
- original_section_id = tool_section_dict[ 'id' ]
- original_section_name = tool_section_dict[ 'name' ]
- if original_section_id:
- tool_panel_section_key, tool_section = \
- get_or_create_tool_section( toolbox,
- tool_panel_section_id=original_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
- else:
- # The user elected to change the tool panel section to contain the tools.
- tool_panel_section_key, tool_section = handle_tool_panel_section( toolbox,
- tool_panel_section_id=tool_panel_section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
- return tool_section, tool_panel_section_key
-
-def handle_tool_panel_section( toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ):
- """Return a ToolSection object retrieved from the current in-memory tool_panel."""
- # If tool_panel_section_id is received, the section exists in the tool panel. In this
- # case, the value of the received tool_panel_section_id must be the id retrieved from a
- # tool panel config (e.g., tool_conf.xml, which may have getext). If new_tool_panel_section_label
- # is received, a new section will be added to the tool panel.
- if new_tool_panel_section_label:
- section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) )
- tool_panel_section_key, tool_section = \
- get_or_create_tool_section( toolbox,
- tool_panel_section_id=section_id,
- new_tool_panel_section_label=new_tool_panel_section_label )
- elif tool_panel_section_id:
- tool_panel_section_key = str( tool_panel_section_id )
- tool_section = toolbox.tool_panel[ tool_panel_section_key ]
- else:
- return None, None
- return tool_panel_section_key, tool_section
-
def handle_tool_versions( app, tool_version_dicts, tool_shed_repository ):
"""
Using the list of tool_version_dicts retrieved from the tool shed (one per changeset
@@ -741,170 +465,6 @@
if isinstance( tool.tool_action, UploadToolAction ):
app.toolbox.reload_tool_by_id( tool_id )
-def remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ):
- # A tool shed repository is being uninstalled so change the shed_tool_conf file.
- # Parse the config file to generate the entire list of config_elems instead of
- # using the in-memory list since it will be a subset of the entire list if one
- # or more repositories have been deactivated.
- shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
- tool_path = shed_tool_conf_dict[ 'tool_path' ]
- config_elems = []
- tree, error_message = xml_util.parse_xml( shed_tool_conf )
- if tree:
- root = tree.getroot()
- for elem in root:
- config_elems.append( elem )
- config_elems_to_remove = []
- for config_elem in config_elems:
- if config_elem.tag == 'section':
- tool_elems_to_remove = []
- for tool_elem in config_elem:
- if tool_elem.get( 'guid' ) in guids_to_remove:
- tool_elems_to_remove.append( tool_elem )
- for tool_elem in tool_elems_to_remove:
- # Remove all of the appropriate tool sub-elements from the section element.
- config_elem.remove( tool_elem )
- if len( config_elem ) < 1:
- # Keep a list of all empty section elements so they can be removed.
- config_elems_to_remove.append( config_elem )
- elif config_elem.tag == 'tool':
- if config_elem.get( 'guid' ) in guids_to_remove:
- config_elems_to_remove.append( config_elem )
- for config_elem in config_elems_to_remove:
- config_elems.remove( config_elem )
- # Persist the altered in-memory version of the tool config.
- suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path )
-
-def remove_from_tool_panel( app, repository, shed_tool_conf, uninstall ):
- """
- A tool shed repository is being deactivated or uninstalled, so handle tool panel
- alterations accordingly.
- """
- # Determine where the tools are currently defined in the tool panel and store this
- # information so the tools can be displayed in the same way when the repository is
- # activated or reinstalled.
- tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( app, repository )
- repository.metadata[ 'tool_panel_section' ] = tool_panel_dict
- app.install_model.context.add( repository )
- app.install_model.context.flush()
- # Create a list of guids for all tools that will be removed from the in-memory tool panel
- # and config file on disk.
- guids_to_remove = [ k for k in tool_panel_dict.keys() ]
- # Remove the tools from the toolbox's tools_by_id dictionary.
- for guid_to_remove in guids_to_remove:
- if guid_to_remove in app.toolbox.tools_by_id:
- del app.toolbox.tools_by_id[ guid_to_remove ]
- index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf )
- if uninstall:
- # Remove from the shed_tool_conf file on disk.
- remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove )
- config_elems = shed_tool_conf_dict[ 'config_elems' ]
- config_elems_to_remove = []
- for config_elem in config_elems:
- if config_elem.tag == 'section':
- # Get the section key for the in-memory tool panel.
- section_key = str( config_elem.get( "id" ) )
- # Generate the list of tool elements to remove.
- tool_elems_to_remove = []
- for tool_elem in config_elem:
- if tool_elem.get( 'guid' ) in guids_to_remove:
- tool_elems_to_remove.append( tool_elem )
- for tool_elem in tool_elems_to_remove:
- if tool_elem in config_elem:
- # Remove the tool sub-element from the section element.
- config_elem.remove( tool_elem )
- # Remove the tool from the section in the in-memory tool panel.
- if section_key in app.toolbox.tool_panel:
- tool_section = app.toolbox.tool_panel[ section_key ]
- guid = tool_elem.get( 'guid' )
- tool_key = 'tool_%s' % str( guid )
- # Get the list of versions of this tool that are currently available in the toolbox.
- available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid )
- if tool_key in tool_section.elems:
- if available_tool_versions:
- available_tool_versions.reverse()
- replacement_tool_key = None
- replacement_tool_version = None
- # Since we are going to remove the tool from the section, replace it with the
- # newest loaded version of the tool.
- for available_tool_version in available_tool_versions:
- available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
- if available_tool_version.id in tool_section.elems.keys() or section_key == available_tool_section_id:
- replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
- replacement_tool_version = available_tool_version
- break
- if replacement_tool_key and replacement_tool_version:
- # Get the index of the tool_key in the tool_section.
- for tool_section_elems_index, key in enumerate( tool_section.elems.keys() ):
- if key == tool_key:
- break
- # Remove the tool from the tool section.
- del tool_section.elems[ tool_key ]
- # Add the replacement tool at the same location in the tool section.
- tool_section.elems.insert( tool_section_elems_index,
- replacement_tool_key,
- replacement_tool_version )
- else:
- del tool_section.elems[ tool_key ]
- else:
- del tool_section.elems[ tool_key ]
- if uninstall:
- # Remove the tool from the section in the in-memory integrated tool panel.
- if section_key in app.toolbox.integrated_tool_panel:
- tool_section = app.toolbox.integrated_tool_panel[ section_key ]
- tool_key = 'tool_%s' % str( tool_elem.get( 'guid' ) )
- if tool_key in tool_section.elems:
- del tool_section.elems[ tool_key ]
- if len( config_elem ) < 1:
- # Keep a list of all empty section elements so they can be removed.
- config_elems_to_remove.append( config_elem )
- elif config_elem.tag == 'tool':
- guid = config_elem.get( 'guid' )
- if guid in guids_to_remove:
- tool_key = 'tool_%s' % str( config_elem.get( 'guid' ) )
- # Get the list of versions of this tool that are currently available in the toolbox.
- available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid )
- if tool_key in app.toolbox.tool_panel:
- if available_tool_versions:
- available_tool_versions.reverse()
- replacement_tool_key = None
- replacement_tool_version = None
- # Since we are going to remove the tool from the section, replace it with
- # the newest loaded version of the tool.
- for available_tool_version in available_tool_versions:
- available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
- if available_tool_version.id in app.toolbox.tool_panel.keys() or not available_tool_section_id:
- replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
- replacement_tool_version = available_tool_version
- break
- if replacement_tool_key and replacement_tool_version:
- # Get the index of the tool_key in the tool_section.
- for tool_panel_index, key in enumerate( app.toolbox.tool_panel.keys() ):
- if key == tool_key:
- break
- # Remove the tool from the tool panel.
- del app.toolbox.tool_panel[ tool_key ]
- # Add the replacement tool at the same location in the tool panel.
- app.toolbox.tool_panel.insert( tool_panel_index, replacement_tool_key, replacement_tool_version )
- else:
- del app.toolbox.tool_panel[ tool_key ]
- else:
- del app.toolbox.tool_panel[ tool_key ]
- if uninstall:
- if tool_key in app.toolbox.integrated_tool_panel:
- del app.toolbox.integrated_tool_panel[ tool_key ]
- config_elems_to_remove.append( config_elem )
- for config_elem in config_elems_to_remove:
- # Remove the element from the in-memory list of elements.
- config_elems.remove( config_elem )
- # Update the config_elems of the in-memory shed_tool_conf_dict.
- shed_tool_conf_dict[ 'config_elems' ] = config_elems
- app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
- app.toolbox_search = ToolBoxSearch( app.toolbox )
- if uninstall and app.config.update_integrated_tool_panel:
- # Write the current in-memory version of the integrated_tool_panel.xml file to disk.
- app.toolbox.write_integrated_tool_panel_config_file()
-
def reset_tool_data_tables( app ):
# Reset the tool_data_tables to an empty dictionary.
app.tool_data_tables.data_tables = {}
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.
1
0
commit/galaxy-central: greg: Add a missing function to the ToolValidator.
by commits-noreply@bitbucket.org 18 Jul '14
by commits-noreply@bitbucket.org 18 Jul '14
18 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/cbca66cc16bf/
Changeset: cbca66cc16bf
User: greg
Date: 2014-07-18 22:44:54
Summary: Add a missing function to the ToolValidator.
Affected #: 2 files
diff -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff -r cbca66cc16bfed165f3b38399857ad0b85d14489 lib/tool_shed/tools/tool_validator.py
--- a/lib/tool_shed/tools/tool_validator.py
+++ b/lib/tool_shed/tools/tool_validator.py
@@ -149,6 +149,45 @@
return tmp_filename
return None
+ def get_list_of_copied_sample_files( self, repo, ctx, dir ):
+ """
+ Find all sample files (files in the repository with the special .sample extension)
+ in the reversed repository manifest up to ctx. Copy each discovered file to dir and
+ return the list of filenames. If a .sample file was added in a changeset and then
+ deleted in a later changeset, it will be returned in the deleted_sample_files list.
+ The caller will set the value of app.config.tool_data_path to dir in order to load
+ the tools and generate metadata for them.
+ """
+ deleted_sample_files = []
+ sample_files = []
+ for changeset in hg_util.reversed_upper_bounded_changelog( repo, ctx ):
+ changeset_ctx = repo.changectx( changeset )
+ for ctx_file in changeset_ctx.files():
+ ctx_file_name = basic_util.strip_path( ctx_file )
+ # If we decide in the future that files deleted later in the changelog should
+ # not be used, we can use the following if statement. if ctx_file_name.endswith( '.sample' )
+ # and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files:
+ if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files:
+ fctx = hg_util.get_file_context_from_ctx( changeset_ctx, ctx_file )
+ if fctx in [ 'DELETED' ]:
+ # Since the possibly future used if statement above is commented out, the
+ # same file that was initially added will be discovered in an earlier changeset
+ # in the change log and fall through to the else block below. In other words,
+ # if a file named blast2go.loc.sample was added in change set 0 and then deleted
+ # in changeset 3, the deleted file in changeset 3 will be handled here, but the
+ # later discovered file in changeset 0 will be handled in the else block below.
+ # In this way, the file contents will always be found for future tools even though
+ # the file was deleted.
+ if ctx_file_name not in deleted_sample_files:
+ deleted_sample_files.append( ctx_file_name )
+ else:
+ sample_files.append( ctx_file_name )
+ tmp_ctx_file_name = os.path.join( dir, ctx_file_name.replace( '.sample', '' ) )
+ fh = open( tmp_ctx_file_name, 'wb' )
+ fh.write( fctx.data() )
+ fh.close()
+ return sample_files, deleted_sample_files
+
def handle_sample_files_and_load_tool_from_disk( self, repo_files_dir, repository_id, tool_config_filepath, work_dir ):
"""
Copy all sample files from disk to a temporary directory since the sample files may
@@ -172,7 +211,7 @@
ctx = hg_util.get_changectx_for_changeset( repo, changeset_revision )
# We're not currently doing anything with the returned list of deleted_sample_files here. It is
# intended to help handle sample files that are in the manifest, but have been deleted from disk.
- sample_files, deleted_sample_files = get_list_of_copied_sample_files( repo, ctx, dir=work_dir )
+ sample_files, deleted_sample_files = self.get_list_of_copied_sample_files( repo, ctx, dir=work_dir )
if sample_files:
self.app.config.tool_data_path = work_dir
if 'tool_data_table_conf.xml.sample' in sample_files:
diff -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff -r cbca66cc16bfed165f3b38399857ad0b85d14489 lib/tool_shed/util/tool_util.py
--- a/lib/tool_shed/util/tool_util.py
+++ b/lib/tool_shed/util/tool_util.py
@@ -341,45 +341,6 @@
break
return headers
-def get_list_of_copied_sample_files( repo, ctx, dir ):
- """
- Find all sample files (files in the repository with the special .sample extension)
- in the reversed repository manifest up to ctx. Copy each discovered file to dir and
- return the list of filenames. If a .sample file was added in a changeset and then
- deleted in a later changeset, it will be returned in the deleted_sample_files list.
- The caller will set the value of app.config.tool_data_path to dir in order to load
- the tools and generate metadata for them.
- """
- deleted_sample_files = []
- sample_files = []
- for changeset in hg_util.reversed_upper_bounded_changelog( repo, ctx ):
- changeset_ctx = repo.changectx( changeset )
- for ctx_file in changeset_ctx.files():
- ctx_file_name = basic_util.strip_path( ctx_file )
- # If we decide in the future that files deleted later in the changelog should
- # not be used, we can use the following if statement. if ctx_file_name.endswith( '.sample' )
- # and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files:
- if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files:
- fctx = hg_util.get_file_context_from_ctx( changeset_ctx, ctx_file )
- if fctx in [ 'DELETED' ]:
- # Since the possibly future used if statement above is commented out, the
- # same file that was initially added will be discovered in an earlier changeset
- # in the change log and fall through to the else block below. In other words,
- # if a file named blast2go.loc.sample was added in change set 0 and then deleted
- # in changeset 3, the deleted file in changeset 3 will be handled here, but the
- # later discovered file in changeset 0 will be handled in the else block below.
- # In this way, the file contents will always be found for future tools even though
- # the file was deleted.
- if ctx_file_name not in deleted_sample_files:
- deleted_sample_files.append( ctx_file_name )
- else:
- sample_files.append( ctx_file_name )
- tmp_ctx_file_name = os.path.join( dir, ctx_file_name.replace( '.sample', '' ) )
- fh = open( tmp_ctx_file_name, 'wb' )
- fh.write( fctx.data() )
- fh.close()
- return sample_files, deleted_sample_files
-
def get_or_create_tool_section( toolbox, tool_panel_section_id, new_tool_panel_section_label=None ):
tool_panel_section_key = str( tool_panel_section_id )
if tool_panel_section_key in toolbox.tool_panel:
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.
1
0
commit/galaxy-central: greg: Add a ToolValidator to validate tools contained in tool shed repositories.
by commits-noreply@bitbucket.org 18 Jul '14
by commits-noreply@bitbucket.org 18 Jul '14
18 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/24437efed65c/
Changeset: 24437efed65c
User: greg
Date: 2014-07-18 22:38:57
Summary: Add a ToolValidator to validate tools contained in tool shed repositories.
Affected #: 6 files
diff -r cd5d9bf32d865657208b0b657b08c9142b357e25 -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff lib/galaxy/webapps/tool_shed/controllers/repository.py
--- a/lib/galaxy/webapps/tool_shed/controllers/repository.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py
@@ -20,6 +20,7 @@
from tool_shed.galaxy_install import dependency_display
from tool_shed.metadata import repository_metadata_manager
+from tool_shed.tools import tool_validator
from tool_shed.util import basic_util
from tool_shed.util import common_util
@@ -1164,10 +1165,10 @@
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
render_repository_actions_for = kwd.get( 'render_repository_actions_for', 'tool_shed' )
- repository, tool, message = tool_util.load_tool_from_changeset_revision( trans.app,
- repository_id,
- changeset_revision,
- tool_config )
+ tv = tool_validator.ToolValidator( trans.app )
+ repository, tool, message = tv.load_tool_from_changeset_revision( repository_id,
+ changeset_revision,
+ tool_config )
if message:
status = 'error'
tool_state = tool_util.new_state( trans, tool, invalid=False )
@@ -2147,18 +2148,17 @@
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'error' )
render_repository_actions_for = kwd.get( 'render_repository_actions_for', 'tool_shed' )
- repository, tool, error_message = tool_util.load_tool_from_changeset_revision( trans.app,
- repository_id,
- changeset_revision,
- tool_config )
+ tv = tool_validator.ToolValidator( trans.app )
+ repository, tool, error_message = tv.load_tool_from_changeset_revision( repository_id,
+ changeset_revision,
+ tool_config )
tool_state = tool_util.new_state( trans, tool, invalid=True )
invalid_file_tups = []
if tool:
- invalid_file_tups = tool_util.check_tool_input_params( trans.app,
- repository.repo_path( trans.app ),
- tool_config,
- tool,
- [] )
+ invalid_file_tups = tv.check_tool_input_params( repository.repo_path( trans.app ),
+ tool_config,
+ tool,
+ [] )
if invalid_file_tups:
message = tool_util.generate_message_for_invalid_tools( trans.app,
invalid_file_tups,
@@ -3397,6 +3397,7 @@
metadata = repository_metadata.metadata
if metadata:
if 'tools' in metadata:
+ tv = tool_validator.ToolValidator( trans.app )
for tool_metadata_dict in metadata[ 'tools' ]:
if tool_metadata_dict[ 'id' ] == tool_id:
work_dir = tempfile.mkdtemp()
@@ -3404,29 +3405,26 @@
guid = tool_metadata_dict[ 'guid' ]
full_path_to_tool_config = os.path.abspath( relative_path_to_tool_config )
full_path_to_dir, tool_config_filename = os.path.split( full_path_to_tool_config )
- can_use_disk_file = tool_util.can_use_tool_config_disk_file( trans.app,
- repository,
- repo,
- full_path_to_tool_config,
- changeset_revision )
+ can_use_disk_file = tv.can_use_tool_config_disk_file( repository,
+ repo,
+ full_path_to_tool_config,
+ changeset_revision )
if can_use_disk_file:
trans.app.config.tool_data_path = work_dir
tool, valid, message, sample_files = \
- tool_util.handle_sample_files_and_load_tool_from_disk( trans.app,
- repo_files_dir,
- repository_id,
- full_path_to_tool_config,
- work_dir )
+ tv.handle_sample_files_and_load_tool_from_disk( repo_files_dir,
+ repository_id,
+ full_path_to_tool_config,
+ work_dir )
if message:
status = 'error'
else:
tool, message, sample_files = \
- tool_util.handle_sample_files_and_load_tool_from_tmp_config( trans.app,
- repo,
- repository_id,
- changeset_revision,
- tool_config_filename,
- work_dir )
+ tv.handle_sample_files_and_load_tool_from_tmp_config( repo,
+ repository_id,
+ changeset_revision,
+ tool_config_filename,
+ work_dir )
if message:
status = 'error'
basic_util.remove_dir( work_dir )
diff -r cd5d9bf32d865657208b0b657b08c9142b357e25 -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff lib/tool_shed/metadata/metadata_generator.py
--- a/lib/tool_shed/metadata/metadata_generator.py
+++ b/lib/tool_shed/metadata/metadata_generator.py
@@ -10,6 +10,7 @@
from galaxy.web import url_for
from tool_shed.repository_types import util as rt_util
+from tool_shed.tools import tool_validator
from tool_shed.util import basic_util
from tool_shed.util import common_util
@@ -128,7 +129,7 @@
log.debug( 'Loaded Data Manager tool_files: %s' % ( tool_file ) )
return metadata_dict
- def generate_datatypes_metadata( self, repository, repository_clone_url, repository_files_dir, datatypes_config,
+ def generate_datatypes_metadata( self, tv, repository, repository_clone_url, repository_files_dir, datatypes_config,
metadata_dict ):
"""Update the received metadata_dict with information from the parsed datatypes_config."""
tree, error_message = xml_util.parse_xml( datatypes_config )
@@ -178,7 +179,7 @@
tool_config_path = hg_util.get_config_from_disk( tool_config, repository_files_dir )
full_path = os.path.abspath( tool_config_path )
tool, valid, error_message = \
- tool_util.load_tool_from_config( self.app, self.app.security.encode_id( repository.id ), full_path )
+ tv.load_tool_from_config( self.app.security.encode_id( repository.id ), full_path )
if tool is None:
guid = None
else:
@@ -245,6 +246,7 @@
tool_data_table_conf.xml.sample file, in which case the entries should ultimately be
persisted to the file referred to by self.app.config.shed_tool_data_table_config.
"""
+ tv = tool_validator.ToolValidator( self.app )
if shed_config_dict is None:
shed_config_dict = {}
if updating_installed_repository:
@@ -290,7 +292,8 @@
# Handle proprietary datatypes, if any.
datatypes_config = hg_util.get_config_from_disk( suc.DATATYPES_CONFIG_FILENAME, files_dir )
if datatypes_config:
- metadata_dict = self.generate_datatypes_metadata( repository,
+ metadata_dict = self.generate_datatypes_metadata( tv,
+ repository,
repository_clone_url,
files_dir,
datatypes_config,
@@ -361,20 +364,18 @@
is_tool = element_tree_root.tag == 'tool'
if is_tool:
tool, valid, error_message = \
- tool_util.load_tool_from_config( self.app,
- self.app.security.encode_id( repository.id ),
- full_path )
+ tv.load_tool_from_config( self.app.security.encode_id( repository.id ),
+ full_path )
if tool is None:
if not valid:
invalid_tool_configs.append( name )
invalid_file_tups.append( ( name, error_message ) )
else:
invalid_files_and_errors_tups = \
- tool_util.check_tool_input_params( self.app,
- files_dir,
- name,
- tool,
- sample_file_copy_paths )
+ tv.check_tool_input_params( files_dir,
+ name,
+ tool,
+ sample_file_copy_paths )
can_set_metadata = True
for tup in invalid_files_and_errors_tups:
if name in tup:
diff -r cd5d9bf32d865657208b0b657b08c9142b357e25 -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff lib/tool_shed/tools/tool_validator.py
--- /dev/null
+++ b/lib/tool_shed/tools/tool_validator.py
@@ -0,0 +1,289 @@
+import filecmp
+import logging
+import os
+import tempfile
+
+from galaxy.tools import parameters
+from galaxy.tools.parameters import dynamic_options
+
+from tool_shed.util import basic_util
+from tool_shed.util import hg_util
+from tool_shed.util import shed_util_common as suc
+from tool_shed.util import tool_util
+
+log = logging.getLogger( __name__ )
+
+
+class ToolValidator( object ):
+
+ def __init__( self, app ):
+ self.app = app
+
+ def can_use_tool_config_disk_file( self, repository, repo, file_path, changeset_revision ):
+ """
+ Determine if repository's tool config file on disk can be used. This method
+ is restricted to tool config files since, with the exception of tool config
+ files, multiple files with the same name will likely be in various directories
+ in the repository and we're comparing file names only (not relative paths).
+ """
+ if not file_path or not os.path.exists( file_path ):
+ # The file no longer exists on disk, so it must have been deleted at some previous
+ # point in the change log.
+ return False
+ if changeset_revision == repository.tip( self.app ):
+ return True
+ file_name = basic_util.strip_path( file_path )
+ latest_version_of_file = \
+ self.get_latest_tool_config_revision_from_repository_manifest( repo, file_name, changeset_revision )
+ can_use_disk_file = filecmp.cmp( file_path, latest_version_of_file )
+ try:
+ os.unlink( latest_version_of_file )
+ except:
+ pass
+ return can_use_disk_file
+
+ def check_tool_input_params( self, repo_dir, tool_config_name, tool, sample_files ):
+ """
+ Check all of the tool's input parameters, looking for any that are dynamically
+ generated using external data files to make sure the files exist.
+ """
+ invalid_files_and_errors_tups = []
+ correction_msg = ''
+ for input_param in tool.input_params:
+ if isinstance( input_param, parameters.basic.SelectToolParameter ) and input_param.is_dynamic:
+ # If the tool refers to .loc files or requires an entry in the tool_data_table_conf.xml,
+ # make sure all requirements exist.
+ options = input_param.dynamic_options or input_param.options
+ if options and isinstance( options, dynamic_options.DynamicOptions ):
+ if options.tool_data_table or options.missing_tool_data_table_name:
+ # Make sure the repository contains a tool_data_table_conf.xml.sample file.
+ sample_tool_data_table_conf = hg_util.get_config_from_disk( 'tool_data_table_conf.xml.sample', repo_dir )
+ if sample_tool_data_table_conf:
+ error, correction_msg = \
+ tool_util.handle_sample_tool_data_table_conf_file( self.app, sample_tool_data_table_conf )
+ if error:
+ invalid_files_and_errors_tups.append( ( 'tool_data_table_conf.xml.sample', correction_msg ) )
+ else:
+ options.missing_tool_data_table_name = None
+ else:
+ correction_msg = "This file requires an entry in the tool_data_table_conf.xml file. "
+ correction_msg += "Upload a file named tool_data_table_conf.xml.sample to the repository "
+ correction_msg += "that includes the required entry to correct this error.<br/>"
+ invalid_tup = ( tool_config_name, correction_msg )
+ if invalid_tup not in invalid_files_and_errors_tups:
+ invalid_files_and_errors_tups.append( invalid_tup )
+ if options.index_file or options.missing_index_file:
+ # Make sure the repository contains the required xxx.loc.sample file.
+ index_file = options.index_file or options.missing_index_file
+ index_file_name = basic_util.strip_path( index_file )
+ sample_found = False
+ for sample_file in sample_files:
+ sample_file_name = basic_util.strip_path( sample_file )
+ if sample_file_name == '%s.sample' % index_file_name:
+ options.index_file = index_file_name
+ options.missing_index_file = None
+ if options.tool_data_table:
+ options.tool_data_table.missing_index_file = None
+ sample_found = True
+ break
+ if not sample_found:
+ correction_msg = "This file refers to a file named <b>%s</b>. " % str( index_file_name )
+ correction_msg += "Upload a file named <b>%s.sample</b> to the repository to correct this error." % \
+ str( index_file_name )
+ invalid_files_and_errors_tups.append( ( tool_config_name, correction_msg ) )
+ return invalid_files_and_errors_tups
+
+ def concat_messages( self, msg1, msg2 ):
+ if msg1:
+ if msg2:
+ message = '%s %s' % ( msg1, msg2 )
+ else:
+ message = msg1
+ elif msg2:
+ message = msg2
+ else:
+ message = ''
+ return message
+
+ def copy_disk_sample_files_to_dir( self, repo_files_dir, dest_path ):
+ """
+ Copy all files currently on disk that end with the .sample extension to the
+ directory to which dest_path refers.
+ """
+ sample_files = []
+ for root, dirs, files in os.walk( repo_files_dir ):
+ if root.find( '.hg' ) < 0:
+ for name in files:
+ if name.endswith( '.sample' ):
+ relative_path = os.path.join( root, name )
+ tool_util.copy_sample_file( self.app, relative_path, dest_path=dest_path )
+ sample_files.append( name )
+ return sample_files
+
+ def get_latest_tool_config_revision_from_repository_manifest( self, repo, filename, changeset_revision ):
+ """
+ Get the latest revision of a tool config file named filename from the repository
+ manifest up to the value of changeset_revision. This method is restricted to tool_config
+ files rather than any file since it is likely that, with the exception of tool config
+ files, multiple files will have the same name in various directories within the repository.
+ """
+ stripped_filename = basic_util.strip_path( filename )
+ for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ):
+ manifest_ctx = repo.changectx( changeset )
+ for ctx_file in manifest_ctx.files():
+ ctx_file_name = basic_util.strip_path( ctx_file )
+ if ctx_file_name == stripped_filename:
+ try:
+ fctx = manifest_ctx[ ctx_file ]
+ except LookupError:
+ # The ctx_file may have been moved in the change set. For example,
+ # 'ncbi_blastp_wrapper.xml' was moved to 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml',
+ # so keep looking for the file until we find the new location.
+ continue
+ fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-gltcrfrm" )
+ tmp_filename = fh.name
+ fh.close()
+ fh = open( tmp_filename, 'wb' )
+ fh.write( fctx.data() )
+ fh.close()
+ return tmp_filename
+ return None
+
+ def handle_sample_files_and_load_tool_from_disk( self, repo_files_dir, repository_id, tool_config_filepath, work_dir ):
+ """
+ Copy all sample files from disk to a temporary directory since the sample files may
+ be in multiple directories.
+ """
+ message = ''
+ sample_files = self.copy_disk_sample_files_to_dir( repo_files_dir, work_dir )
+ if sample_files:
+ if 'tool_data_table_conf.xml.sample' in sample_files:
+ # Load entries into the tool_data_tables if the tool requires them.
+ tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' )
+ error, message = tool_util.handle_sample_tool_data_table_conf_file( self.app, tool_data_table_config )
+ tool, valid, message2 = self.load_tool_from_config( repository_id, tool_config_filepath )
+ message = self.concat_messages( message, message2 )
+ return tool, valid, message, sample_files
+
+ def handle_sample_files_and_load_tool_from_tmp_config( self, repo, repository_id, changeset_revision,
+ tool_config_filename, work_dir ):
+ tool = None
+ message = ''
+ ctx = hg_util.get_changectx_for_changeset( repo, changeset_revision )
+ # We're not currently doing anything with the returned list of deleted_sample_files here. It is
+ # intended to help handle sample files that are in the manifest, but have been deleted from disk.
+ sample_files, deleted_sample_files = get_list_of_copied_sample_files( repo, ctx, dir=work_dir )
+ if sample_files:
+ self.app.config.tool_data_path = work_dir
+ if 'tool_data_table_conf.xml.sample' in sample_files:
+ # Load entries into the tool_data_tables if the tool requires them.
+ tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' )
+ if tool_data_table_config:
+ error, message = tool_util.handle_sample_tool_data_table_conf_file( self.app, tool_data_table_config )
+ if error:
+ log.debug( message )
+ manifest_ctx, ctx_file = hg_util.get_ctx_file_path_from_manifest( tool_config_filename, repo, changeset_revision )
+ if manifest_ctx and ctx_file:
+ tool, message2 = self.load_tool_from_tmp_config( repo, repository_id, manifest_ctx, ctx_file, work_dir )
+ message = self.concat_messages( message, message2 )
+ return tool, message, sample_files
+
+ def load_tool_from_changeset_revision( self, repository_id, changeset_revision, tool_config_filename ):
+ """
+ Return a loaded tool whose tool config file name (e.g., filtering.xml) is the value
+ of tool_config_filename. The value of changeset_revision is a valid (downloadable)
+ changeset revision. The tool config will be located in the repository manifest between
+ the received valid changeset revision and the first changeset revision in the repository,
+ searching backwards.
+ """
+ original_tool_data_path = self.app.config.tool_data_path
+ repository = suc.get_repository_in_tool_shed( self.app, repository_id )
+ repo_files_dir = repository.repo_path( self.app )
+ repo = hg_util.get_repo_for_repository( self.app, repository=None, repo_path=repo_files_dir, create=False )
+ message = ''
+ tool = None
+ can_use_disk_file = False
+ tool_config_filepath = suc.get_absolute_path_to_file_in_repository( repo_files_dir, tool_config_filename )
+ work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-ltfcr" )
+ can_use_disk_file = self.can_use_tool_config_disk_file( repository,
+ repo,
+ tool_config_filepath,
+ changeset_revision )
+ if can_use_disk_file:
+ self.app.config.tool_data_path = work_dir
+ tool, valid, message, sample_files = \
+ self.handle_sample_files_and_load_tool_from_disk( repo_files_dir,
+ repository_id,
+ tool_config_filepath,
+ work_dir )
+ if tool is not None:
+ invalid_files_and_errors_tups = \
+ self.check_tool_input_params( repo_files_dir,
+ tool_config_filename,
+ tool,
+ sample_files )
+ if invalid_files_and_errors_tups:
+ message2 = tool_util.generate_message_for_invalid_tools( self.app,
+ invalid_files_and_errors_tups,
+ repository,
+ metadata_dict=None,
+ as_html=True,
+ displaying_invalid_tool=True )
+ message = self.concat_messages( message, message2 )
+ else:
+ tool, message, sample_files = \
+ self.handle_sample_files_and_load_tool_from_tmp_config( repo,
+ repository_id,
+ changeset_revision,
+ tool_config_filename,
+ work_dir )
+ basic_util.remove_dir( work_dir )
+ self.app.config.tool_data_path = original_tool_data_path
+ # Reset the tool_data_tables by loading the empty tool_data_table_conf.xml file.
+ tool_util.reset_tool_data_tables( self.app )
+ return repository, tool, message
+
+ def load_tool_from_config( self, repository_id, full_path ):
+ try:
+ tool = self.app.toolbox.load_tool( full_path, repository_id=repository_id )
+ valid = True
+ error_message = None
+ except KeyError, e:
+ tool = None
+ valid = False
+ error_message = 'This file requires an entry for "%s" in the tool_data_table_conf.xml file. Upload a file ' % str( e )
+ error_message += 'named tool_data_table_conf.xml.sample to the repository that includes the required entry to correct '
+ error_message += 'this error. '
+ except Exception, e:
+ tool = None
+ valid = False
+ error_message = str( e )
+ return tool, valid, error_message
+
+ def load_tool_from_tmp_config( self, repo, repository_id, ctx, ctx_file, work_dir ):
+ tool = None
+ message = ''
+ tmp_tool_config = hg_util.get_named_tmpfile_from_ctx( ctx, ctx_file, work_dir )
+ if tmp_tool_config:
+ element_tree, error_message = xml_util.parse_xml( tmp_tool_config )
+ if element_tree is None:
+ return tool, message
+ element_tree_root = element_tree.getroot()
+ # Look for code files required by the tool config.
+ tmp_code_files = []
+ for code_elem in element_tree_root.findall( 'code' ):
+ code_file_name = code_elem.get( 'file' )
+ tmp_code_file_name = hg_util.copy_file_from_manifest( repo, ctx, code_file_name, work_dir )
+ if tmp_code_file_name:
+ tmp_code_files.append( tmp_code_file_name )
+ tool, valid, message = self.load_tool_from_config( repository_id, tmp_tool_config )
+ for tmp_code_file in tmp_code_files:
+ try:
+ os.unlink( tmp_code_file )
+ except:
+ pass
+ try:
+ os.unlink( tmp_tool_config )
+ except:
+ pass
+ return tool, message
diff -r cd5d9bf32d865657208b0b657b08c9142b357e25 -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff lib/tool_shed/util/tool_util.py
--- a/lib/tool_shed/util/tool_util.py
+++ b/lib/tool_shed/util/tool_util.py
@@ -1,14 +1,11 @@
-import filecmp
import logging
import os
import shutil
-import tempfile
import galaxy.tools
from galaxy import util
from galaxy.datatypes import checkers
from galaxy.model.orm import and_
from galaxy.tools import parameters
-from galaxy.tools.parameters import dynamic_options
from galaxy.tools.search import ToolBoxSearch
from galaxy.util.expressions import ExpressionContext
from galaxy.web.form_builder import SelectField
@@ -112,107 +109,6 @@
select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] )
return select_field
-def can_use_tool_config_disk_file( app, repository, repo, file_path, changeset_revision ):
- """
- Determine if repository's tool config file on disk can be used. This method
- is restricted to tool config files since, with the exception of tool config
- files, multiple files with the same name will likely be in various directories
- in the repository and we're comparing file names only (not relative paths).
- """
- if not file_path or not os.path.exists( file_path ):
- # The file no longer exists on disk, so it must have been deleted at some previous
- # point in the change log.
- return False
- if changeset_revision == repository.tip( app ):
- return True
- file_name = basic_util.strip_path( file_path )
- latest_version_of_file = get_latest_tool_config_revision_from_repository_manifest( repo,
- file_name,
- changeset_revision )
- can_use_disk_file = filecmp.cmp( file_path, latest_version_of_file )
- try:
- os.unlink( latest_version_of_file )
- except:
- pass
- return can_use_disk_file
-
-def check_tool_input_params( app, repo_dir, tool_config_name, tool, sample_files ):
- """
- Check all of the tool's input parameters, looking for any that are dynamically
- generated using external data files to make sure the files exist.
- """
- invalid_files_and_errors_tups = []
- correction_msg = ''
- for input_param in tool.input_params:
- if isinstance( input_param, parameters.basic.SelectToolParameter ) and input_param.is_dynamic:
- # If the tool refers to .loc files or requires an entry in the tool_data_table_conf.xml,
- # make sure all requirements exist.
- options = input_param.dynamic_options or input_param.options
- if options and isinstance( options, dynamic_options.DynamicOptions ):
- if options.tool_data_table or options.missing_tool_data_table_name:
- # Make sure the repository contains a tool_data_table_conf.xml.sample file.
- sample_tool_data_table_conf = hg_util.get_config_from_disk( 'tool_data_table_conf.xml.sample', repo_dir )
- if sample_tool_data_table_conf:
- error, correction_msg = handle_sample_tool_data_table_conf_file( app, sample_tool_data_table_conf )
- if error:
- invalid_files_and_errors_tups.append( ( 'tool_data_table_conf.xml.sample', correction_msg ) )
- else:
- options.missing_tool_data_table_name = None
- else:
- correction_msg = "This file requires an entry in the tool_data_table_conf.xml file. "
- correction_msg += "Upload a file named tool_data_table_conf.xml.sample to the repository "
- correction_msg += "that includes the required entry to correct this error.<br/>"
- invalid_tup = ( tool_config_name, correction_msg )
- if invalid_tup not in invalid_files_and_errors_tups:
- invalid_files_and_errors_tups.append( invalid_tup )
- if options.index_file or options.missing_index_file:
- # Make sure the repository contains the required xxx.loc.sample file.
- index_file = options.index_file or options.missing_index_file
- index_file_name = basic_util.strip_path( index_file )
- sample_found = False
- for sample_file in sample_files:
- sample_file_name = basic_util.strip_path( sample_file )
- if sample_file_name == '%s.sample' % index_file_name:
- options.index_file = index_file_name
- options.missing_index_file = None
- if options.tool_data_table:
- options.tool_data_table.missing_index_file = None
- sample_found = True
- break
- if not sample_found:
- correction_msg = "This file refers to a file named <b>%s</b>. " % str( index_file_name )
- correction_msg += "Upload a file named <b>%s.sample</b> to the repository to correct this error." % \
- str( index_file_name )
- invalid_files_and_errors_tups.append( ( tool_config_name, correction_msg ) )
- return invalid_files_and_errors_tups
-
-def concat_messages( msg1, msg2 ):
- if msg1:
- if msg2:
- message = '%s %s' % ( msg1, msg2 )
- else:
- message = msg1
- elif msg2:
- message = msg2
- else:
- message = ''
- return message
-
-def copy_disk_sample_files_to_dir( app, repo_files_dir, dest_path ):
- """
- Copy all files currently on disk that end with the .sample extension to the
- directory to which dest_path refers.
- """
- sample_files = []
- for root, dirs, files in os.walk( repo_files_dir ):
- if root.find( '.hg' ) < 0:
- for name in files:
- if name.endswith( '.sample' ):
- relative_path = os.path.join( root, name )
- copy_sample_file( app, relative_path, dest_path=dest_path )
- sample_files.append( name )
- return sample_files
-
def copy_sample_file( app, filename, dest_path=None ):
"""
Copy xxx.sample to dest_path/xxx.sample and dest_path/xxx. The default value for dest_path
@@ -445,35 +341,6 @@
break
return headers
-def get_latest_tool_config_revision_from_repository_manifest( repo, filename, changeset_revision ):
- """
- Get the latest revision of a tool config file named filename from the repository
- manifest up to the value of changeset_revision. This method is restricted to tool_config
- files rather than any file since it is likely that, with the exception of tool config
- files, multiple files will have the same name in various directories within the repository.
- """
- stripped_filename = basic_util.strip_path( filename )
- for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ):
- manifest_ctx = repo.changectx( changeset )
- for ctx_file in manifest_ctx.files():
- ctx_file_name = basic_util.strip_path( ctx_file )
- if ctx_file_name == stripped_filename:
- try:
- fctx = manifest_ctx[ ctx_file ]
- except LookupError:
- # The ctx_file may have been moved in the change set. For example,
- # 'ncbi_blastp_wrapper.xml' was moved to 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml',
- # so keep looking for the file until we find the new location.
- continue
- fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-gltcrfrm" )
- tmp_filename = fh.name
- fh.close()
- fh = open( tmp_filename, 'wb' )
- fh.write( fctx.data() )
- fh.close()
- return tmp_filename
- return None
-
def get_list_of_copied_sample_files( repo, ctx, dir ):
"""
Find all sample files (files in the repository with the special .sample extension)
@@ -664,45 +531,6 @@
repository_tools_tups[ index ] = ( tup_path, guid, repository_tool )
return repository_tools_tups, sample_files_copied
-def handle_sample_files_and_load_tool_from_disk( app, repo_files_dir, repository_id, tool_config_filepath, work_dir ):
- """
- Copy all sample files from disk to a temporary directory since the sample files may
- be in multiple directories.
- """
- message = ''
- sample_files = copy_disk_sample_files_to_dir( app, repo_files_dir, work_dir )
- if sample_files:
- if 'tool_data_table_conf.xml.sample' in sample_files:
- # Load entries into the tool_data_tables if the tool requires them.
- tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' )
- error, message = handle_sample_tool_data_table_conf_file( app, tool_data_table_config )
- tool, valid, message2 = load_tool_from_config( app, repository_id, tool_config_filepath )
- message = concat_messages( message, message2 )
- return tool, valid, message, sample_files
-
-def handle_sample_files_and_load_tool_from_tmp_config( app, repo, repository_id, changeset_revision,
- tool_config_filename, work_dir ):
- tool = None
- message = ''
- ctx = hg_util.get_changectx_for_changeset( repo, changeset_revision )
- # We're not currently doing anything with the returned list of deleted_sample_files here. It is
- # intended to help handle sample files that are in the manifest, but have been deleted from disk.
- sample_files, deleted_sample_files = get_list_of_copied_sample_files( repo, ctx, dir=work_dir )
- if sample_files:
- app.config.tool_data_path = work_dir
- if 'tool_data_table_conf.xml.sample' in sample_files:
- # Load entries into the tool_data_tables if the tool requires them.
- tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' )
- if tool_data_table_config:
- error, message = handle_sample_tool_data_table_conf_file( app, tool_data_table_config )
- if error:
- log.debug( message )
- manifest_ctx, ctx_file = hg_util.get_ctx_file_path_from_manifest( tool_config_filename, repo, changeset_revision )
- if manifest_ctx and ctx_file:
- tool, message2 = load_tool_from_tmp_config( app, repo, repository_id, manifest_ctx, ctx_file, work_dir )
- message = concat_messages( message, message2 )
- return tool, message, sample_files
-
def handle_sample_tool_data_table_conf_file( app, filename, persist=False ):
"""
Parse the incoming filename and add new entries to the in-memory
@@ -911,107 +739,6 @@
# Default to copying the file if none of the above are true.
return True
-def load_tool_from_changeset_revision( app, repository_id, changeset_revision, tool_config_filename ):
- """
- Return a loaded tool whose tool config file name (e.g., filtering.xml) is the value
- of tool_config_filename. The value of changeset_revision is a valid (downloadable)
- changset revision. The tool config will be located in the repository manifest between
- the received valid changeset revision and the first changeset revision in the repository,
- searching backwards.
- """
- original_tool_data_path = app.config.tool_data_path
- repository = suc.get_repository_in_tool_shed( app, repository_id )
- repo_files_dir = repository.repo_path( app )
- repo = hg_util.get_repo_for_repository( app, repository=None, repo_path=repo_files_dir, create=False )
- message = ''
- tool = None
- can_use_disk_file = False
- tool_config_filepath = suc.get_absolute_path_to_file_in_repository( repo_files_dir, tool_config_filename )
- work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-ltfcr" )
- can_use_disk_file = can_use_tool_config_disk_file( app,
- repository,
- repo,
- tool_config_filepath,
- changeset_revision )
- if can_use_disk_file:
- app.config.tool_data_path = work_dir
- tool, valid, message, sample_files = handle_sample_files_and_load_tool_from_disk( app,
- repo_files_dir,
- repository_id,
- tool_config_filepath,
- work_dir )
- if tool is not None:
- invalid_files_and_errors_tups = check_tool_input_params( app,
- repo_files_dir,
- tool_config_filename,
- tool,
- sample_files )
- if invalid_files_and_errors_tups:
- message2 = generate_message_for_invalid_tools( app,
- invalid_files_and_errors_tups,
- repository,
- metadata_dict=None,
- as_html=True,
- displaying_invalid_tool=True )
- message = concat_messages( message, message2 )
- else:
- tool, message, sample_files = handle_sample_files_and_load_tool_from_tmp_config( app,
- repo,
- repository_id,
- changeset_revision,
- tool_config_filename,
- work_dir )
- basic_util.remove_dir( work_dir )
- app.config.tool_data_path = original_tool_data_path
- # Reset the tool_data_tables by loading the empty tool_data_table_conf.xml file.
- reset_tool_data_tables( app )
- return repository, tool, message
-
-def load_tool_from_config( app, repository_id, full_path ):
- try:
- tool = app.toolbox.load_tool( full_path, repository_id=repository_id )
- valid = True
- error_message = None
- except KeyError, e:
- tool = None
- valid = False
- error_message = 'This file requires an entry for "%s" in the tool_data_table_conf.xml file. Upload a file ' % str( e )
- error_message += 'named tool_data_table_conf.xml.sample to the repository that includes the required entry to correct '
- error_message += 'this error. '
- except Exception, e:
- tool = None
- valid = False
- error_message = str( e )
- return tool, valid, error_message
-
-def load_tool_from_tmp_config( app, repo, repository_id, ctx, ctx_file, work_dir ):
- tool = None
- message = ''
- tmp_tool_config = hg_util.get_named_tmpfile_from_ctx( ctx, ctx_file, work_dir )
- if tmp_tool_config:
- element_tree, error_message = xml_util.parse_xml( tmp_tool_config )
- if element_tree is None:
- return tool, message
- element_tree_root = element_tree.getroot()
- # Look for code files required by the tool config.
- tmp_code_files = []
- for code_elem in element_tree_root.findall( 'code' ):
- code_file_name = code_elem.get( 'file' )
- tmp_code_file_name = hg_util.copy_file_from_manifest( repo, ctx, code_file_name, work_dir )
- if tmp_code_file_name:
- tmp_code_files.append( tmp_code_file_name )
- tool, valid, message = load_tool_from_config( app, repository_id, tmp_tool_config )
- for tmp_code_file in tmp_code_files:
- try:
- os.unlink( tmp_code_file )
- except:
- pass
- try:
- os.unlink( tmp_tool_config )
- except:
- pass
- return tool, message
-
def new_state( trans, tool, invalid=False ):
"""Create a new `DefaultToolState` for the received tool. Only inputs on the first page will be initialized."""
state = galaxy.tools.DefaultToolState()
diff -r cd5d9bf32d865657208b0b657b08c9142b357e25 -r 24437efed65c4db4b22b25df6b6d307ac5dcb2ff lib/tool_shed/util/workflow_util.py
--- a/lib/tool_shed/util/workflow_util.py
+++ b/lib/tool_shed/util/workflow_util.py
@@ -1,5 +1,6 @@
import logging
import os
+
import galaxy.tools
import galaxy.tools.parameters
import galaxy.webapps.galaxy.controllers.workflow
@@ -9,9 +10,12 @@
from galaxy.workflow.modules import InputDataModule
from galaxy.workflow.modules import ToolModule
from galaxy.workflow.modules import WorkflowModuleFactory
-import tool_shed.util.shed_util_common as suc
+
+from tool_shed.tools import tool_validator
+
from tool_shed.util import encoding_util
from tool_shed.util import metadata_util
+from tool_shed.util import shed_util_common as suc
from tool_shed.util import tool_util
eggs.require( "SVGFig" )
@@ -57,14 +61,14 @@
self.tool_id = tool_id
self.tool = None
self.errors = None
+ self.tv = tool_validator.ToolValidator( trans.app )
if trans.webapp.name == 'tool_shed':
# We're in the tool shed.
for tool_dict in tools_metadata:
if self.tool_id in [ tool_dict[ 'id' ], tool_dict[ 'guid' ] ]:
- repository, self.tool, message = tool_util.load_tool_from_changeset_revision( trans.app,
- repository_id,
- changeset_revision,
- tool_dict[ 'tool_config' ] )
+ repository, self.tool, message = self.tv.load_tool_from_changeset_revision( repository_id,
+ changeset_revision,
+ tool_dict[ 'tool_config' ] )
if message and self.tool is None:
self.errors = 'unavailable'
break
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.
1
0
commit/galaxy-central: greg: As much as possible, eliminate the use of trans in the tool shed's tool_util.py module.
by commits-noreply@bitbucket.org 18 Jul '14
by commits-noreply@bitbucket.org 18 Jul '14
18 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/cd5d9bf32d86/
Changeset: cd5d9bf32d86
User: greg
Date: 2014-07-18 20:41:44
Summary: As much as possible, eliminate the use of trans in the tool shed's tool_util.py module.
Affected #: 4 files
diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
--- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
+++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
@@ -244,7 +244,10 @@
if kwd.get( 'deactivate_or_uninstall_repository_button', False ):
if tool_shed_repository.includes_tools_for_display_in_tool_panel:
# Handle tool panel alterations.
- tool_util.remove_from_tool_panel( trans, tool_shed_repository, shed_tool_conf, uninstall=remove_from_disk_checked )
+ tool_util.remove_from_tool_panel( trans.app,
+ tool_shed_repository,
+ shed_tool_conf,
+ uninstall=remove_from_disk_checked )
if tool_shed_repository.includes_data_managers:
data_manager_util.remove_from_data_manager( trans.app, tool_shed_repository )
if tool_shed_repository.includes_datatypes:
@@ -1116,9 +1119,9 @@
return trans.response.send_redirect( web.url_for( controller='admin_toolshed',
action='manage_repositories',
**kwd ) )
- shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans )
+ shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans.app )
tool_path = suc.get_tool_path_by_shed_tool_conf_filename( trans.app, shed_tool_conf )
- tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans )
+ tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans.app )
if len( repo_info_dicts ) == 1:
# If we're installing or updating a single repository, see if it contains a readme or
# dependencies that we can display.
@@ -1636,7 +1639,7 @@
original_section_name = ''
else:
original_section_name = ''
- tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans )
+ tool_panel_section_select_field = tool_util.build_tool_panel_section_select_field( trans.app )
no_changes_check_box = CheckboxField( 'no_changes', checked=True )
if original_section_name:
message += "The tools contained in your <b>%s</b> repository were last loaded into the tool panel section <b>%s</b>. " \
@@ -1652,7 +1655,7 @@
no_changes_check_box = None
original_section_name = ''
tool_panel_section_select_field = None
- shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans )
+ shed_tool_conf_select_field = tool_util.build_shed_tool_conf_select_field( trans.app )
dd = dependency_display.DependencyDisplayer( trans.app )
containers_dict = \
dd.populate_containers_dict_for_new_install( tool_shed_url=tool_shed_url,
diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/galaxy/webapps/tool_shed/controllers/repository.py
--- a/lib/galaxy/webapps/tool_shed/controllers/repository.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py
@@ -1164,7 +1164,10 @@
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
render_repository_actions_for = kwd.get( 'render_repository_actions_for', 'tool_shed' )
- repository, tool, message = tool_util.load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config )
+ repository, tool, message = tool_util.load_tool_from_changeset_revision( trans.app,
+ repository_id,
+ changeset_revision,
+ tool_config )
if message:
status = 'error'
tool_state = tool_util.new_state( trans, tool, invalid=False )
@@ -2144,7 +2147,10 @@
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'error' )
render_repository_actions_for = kwd.get( 'render_repository_actions_for', 'tool_shed' )
- repository, tool, error_message = tool_util.load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config )
+ repository, tool, error_message = tool_util.load_tool_from_changeset_revision( trans.app,
+ repository_id,
+ changeset_revision,
+ tool_config )
tool_state = tool_util.new_state( trans, tool, invalid=True )
invalid_file_tups = []
if tool:
@@ -3398,7 +3404,7 @@
guid = tool_metadata_dict[ 'guid' ]
full_path_to_tool_config = os.path.abspath( relative_path_to_tool_config )
full_path_to_dir, tool_config_filename = os.path.split( full_path_to_tool_config )
- can_use_disk_file = tool_util.can_use_tool_config_disk_file( trans,
+ can_use_disk_file = tool_util.can_use_tool_config_disk_file( trans.app,
repository,
repo,
full_path_to_tool_config,
@@ -3406,7 +3412,7 @@
if can_use_disk_file:
trans.app.config.tool_data_path = work_dir
tool, valid, message, sample_files = \
- tool_util.handle_sample_files_and_load_tool_from_disk( trans,
+ tool_util.handle_sample_files_and_load_tool_from_disk( trans.app,
repo_files_dir,
repository_id,
full_path_to_tool_config,
@@ -3415,7 +3421,7 @@
status = 'error'
else:
tool, message, sample_files = \
- tool_util.handle_sample_files_and_load_tool_from_tmp_config( trans,
+ tool_util.handle_sample_files_and_load_tool_from_tmp_config( trans.app,
repo,
repository_id,
changeset_revision,
diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/tool_shed/util/tool_util.py
--- a/lib/tool_shed/util/tool_util.py
+++ b/lib/tool_shed/util/tool_util.py
@@ -65,7 +65,10 @@
if config_elem.tag == 'section':
app.toolbox.load_section_tag_set( config_elem, tool_path, load_panel_dict=True )
elif config_elem.tag == 'workflow':
- app.toolbox.load_workflow_tag_set( config_elem, app.toolbox.tool_panel, app.toolbox.integrated_tool_panel, load_panel_dict=True )
+ app.toolbox.load_workflow_tag_set( config_elem,
+ app.toolbox.tool_panel,
+ app.toolbox.integrated_tool_panel,
+ load_panel_dict=True )
elif config_elem.tag == 'tool':
guid = config_elem.get( 'guid' )
app.toolbox.load_tool_tag_set( config_elem,
@@ -82,12 +85,12 @@
app.toolbox.write_integrated_tool_panel_config_file()
app.toolbox_search = ToolBoxSearch( app.toolbox )
-def build_shed_tool_conf_select_field( trans ):
- """Build a SelectField whose options are the keys in trans.app.toolbox.shed_tool_confs."""
+def build_shed_tool_conf_select_field( app ):
+ """Build a SelectField whose options are the keys in app.toolbox.shed_tool_confs."""
options = []
- for shed_tool_conf_dict in trans.app.toolbox.shed_tool_confs:
+ for shed_tool_conf_dict in app.toolbox.shed_tool_confs:
shed_tool_conf_filename = shed_tool_conf_dict[ 'config_filename' ]
- if shed_tool_conf_filename != trans.app.config.migrated_tools_config:
+ if shed_tool_conf_filename != app.config.migrated_tools_config:
if shed_tool_conf_filename.startswith( './' ):
option_label = shed_tool_conf_filename.replace( './', '', 1 )
else:
@@ -98,10 +101,10 @@
select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] )
return select_field
-def build_tool_panel_section_select_field( trans ):
+def build_tool_panel_section_select_field( app ):
"""Build a SelectField whose options are the sections of the current in-memory toolbox."""
options = []
- for k, v in trans.app.toolbox.tool_panel.items():
+ for k, v in app.toolbox.tool_panel.items():
if isinstance( v, galaxy.tools.ToolSection ):
options.append( ( v.name, v.id ) )
select_field = SelectField( name='tool_panel_section_id', display='radio' )
@@ -109,19 +112,23 @@
select_field.add_option( option_tup[ 0 ], option_tup[ 1 ] )
return select_field
-def can_use_tool_config_disk_file( trans, repository, repo, file_path, changeset_revision ):
+def can_use_tool_config_disk_file( app, repository, repo, file_path, changeset_revision ):
"""
- Determine if repository's tool config file on disk can be used. This method is restricted to tool config files since, with the
- exception of tool config files, multiple files with the same name will likely be in various directories in the repository and we're
- comparing file names only (not relative paths).
+ Determine if repository's tool config file on disk can be used. This method
+ is restricted to tool config files since, with the exception of tool config
+ files, multiple files with the same name will likely be in various directories
+ in the repository and we're comparing file names only (not relative paths).
"""
if not file_path or not os.path.exists( file_path ):
- # The file no longer exists on disk, so it must have been deleted at some previous point in the change log.
+ # The file no longer exists on disk, so it must have been deleted at some previous
+ # point in the change log.
return False
- if changeset_revision == repository.tip( trans.app ):
+ if changeset_revision == repository.tip( app ):
return True
file_name = basic_util.strip_path( file_path )
- latest_version_of_file = get_latest_tool_config_revision_from_repository_manifest( repo, file_name, changeset_revision )
+ latest_version_of_file = get_latest_tool_config_revision_from_repository_manifest( repo,
+ file_name,
+ changeset_revision )
can_use_disk_file = filecmp.cmp( file_path, latest_version_of_file )
try:
os.unlink( latest_version_of_file )
@@ -131,14 +138,15 @@
def check_tool_input_params( app, repo_dir, tool_config_name, tool, sample_files ):
"""
- Check all of the tool's input parameters, looking for any that are dynamically generated using external data files to make
- sure the files exist.
+ Check all of the tool's input parameters, looking for any that are dynamically
+ generated using external data files to make sure the files exist.
"""
invalid_files_and_errors_tups = []
correction_msg = ''
for input_param in tool.input_params:
if isinstance( input_param, parameters.basic.SelectToolParameter ) and input_param.is_dynamic:
- # If the tool refers to .loc files or requires an entry in the tool_data_table_conf.xml, make sure all requirements exist.
+ # If the tool refers to .loc files or requires an entry in the tool_data_table_conf.xml,
+ # make sure all requirements exist.
options = input_param.dynamic_options or input_param.options
if options and isinstance( options, dynamic_options.DynamicOptions ):
if options.tool_data_table or options.missing_tool_data_table_name:
@@ -151,8 +159,9 @@
else:
options.missing_tool_data_table_name = None
else:
- correction_msg = "This file requires an entry in the tool_data_table_conf.xml file. Upload a file named tool_data_table_conf.xml.sample "
- correction_msg += "to the repository that includes the required entry to correct this error.<br/>"
+ correction_msg = "This file requires an entry in the tool_data_table_conf.xml file. "
+ correction_msg += "Upload a file named tool_data_table_conf.xml.sample to the repository "
+ correction_msg += "that includes the required entry to correct this error.<br/>"
invalid_tup = ( tool_config_name, correction_msg )
if invalid_tup not in invalid_files_and_errors_tups:
invalid_files_and_errors_tups.append( invalid_tup )
@@ -172,7 +181,8 @@
break
if not sample_found:
correction_msg = "This file refers to a file named <b>%s</b>. " % str( index_file_name )
- correction_msg += "Upload a file named <b>%s.sample</b> to the repository to correct this error." % str( index_file_name )
+ correction_msg += "Upload a file named <b>%s.sample</b> to the repository to correct this error." % \
+ str( index_file_name )
invalid_files_and_errors_tups.append( ( tool_config_name, correction_msg ) )
return invalid_files_and_errors_tups
@@ -188,15 +198,18 @@
message = ''
return message
-def copy_disk_sample_files_to_dir( trans, repo_files_dir, dest_path ):
- """Copy all files currently on disk that end with the .sample extension to the directory to which dest_path refers."""
+def copy_disk_sample_files_to_dir( app, repo_files_dir, dest_path ):
+ """
+ Copy all files currently on disk that end with the .sample extension to the
+ directory to which dest_path refers.
+ """
sample_files = []
for root, dirs, files in os.walk( repo_files_dir ):
if root.find( '.hg' ) < 0:
for name in files:
if name.endswith( '.sample' ):
relative_path = os.path.join( root, name )
- copy_sample_file( trans.app, relative_path, dest_path=dest_path )
+ copy_sample_file( app, relative_path, dest_path=dest_path )
sample_files.append( name )
return sample_files
@@ -239,7 +252,8 @@
if is_data_index_sample_file( filename ):
copy_sample_file( app, filename, dest_path=dest_path )
-def generate_message_for_invalid_tools( app, invalid_file_tups, repository, metadata_dict, as_html=True, displaying_invalid_tool=False ):
+def generate_message_for_invalid_tools( app, invalid_file_tups, repository, metadata_dict, as_html=True,
+ displaying_invalid_tool=False ):
if as_html:
new_line = '<br/>'
bold_start = '<b>'
@@ -270,8 +284,10 @@
sample_ext = '%s.sample' % missing_file
else:
sample_ext = missing_file
- correction_msg = "This file refers to a missing file %s%s%s. " % ( bold_start, str( missing_file ), bold_end )
- correction_msg += "Upload a file named %s%s%s to the repository to correct this error." % ( bold_start, sample_ext, bold_end )
+ correction_msg = "This file refers to a missing file %s%s%s. " % \
+ ( bold_start, str( missing_file ), bold_end )
+ correction_msg += "Upload a file named %s%s%s to the repository to correct this error." % \
+ ( bold_start, sample_ext, bold_end )
else:
if as_html:
correction_msg = exception_msg
@@ -282,8 +298,8 @@
def generate_tool_panel_dict_for_new_install( tool_dicts, tool_section=None ):
"""
- When installing a repository that contains tools, all tools must currently be defined within the same tool section in the tool
- panel or outside of any sections.
+ When installing a repository that contains tools, all tools must currently be defined
+ within the same tool section in the tool panel or outside of any sections.
"""
tool_panel_dict = {}
if tool_section:
@@ -307,10 +323,15 @@
def generate_tool_panel_dict_for_tool_config( guid, tool_config, tool_sections=None ):
"""
- Create a dictionary of the following type for a single tool config file name. The intent is to call this method for every tool config
- in a repository and append each of these as entries to a tool panel dictionary for the repository. This allows for each tool to be
- loaded into a different section in the tool panel.
- {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]}
+ Create a dictionary of the following type for a single tool config file name.
+ The intent is to call this method for every tool config in a repository and
+ append each of these as entries to a tool panel dictionary for the repository.
+ This allows for each tool to be loaded into a different section in the tool panel.
+ {<Tool guid> :
+ [{ tool_config : <tool_config_file>,
+ id: <ToolSection id>,
+ version : <ToolSection version>,
+ name : <TooSection name>}]}
"""
tool_panel_dict = {}
file_name = basic_util.strip_path( tool_config )
@@ -318,7 +339,8 @@
tool_panel_dict[ guid ] = tool_section_dicts
return tool_panel_dict
-def generate_tool_panel_elem_list( repository_name, repository_clone_url, changeset_revision, tool_panel_dict, repository_tools_tups, owner='' ):
+def generate_tool_panel_elem_list( repository_name, repository_clone_url, changeset_revision, tool_panel_dict,
+ repository_tools_tups, owner='' ):
"""Generate a list of ElementTree Element objects for each section or tool."""
elem_list = []
tool_elem = None
@@ -349,9 +371,21 @@
if tup_guid == guid:
break
if inside_section:
- tool_elem = suc.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, tool_section )
+ tool_elem = suc.generate_tool_elem( tool_shed,
+ repository_name,
+ changeset_revision,
+ owner,
+ tool_file_path,
+ tool,
+ tool_section )
else:
- tool_elem = suc.generate_tool_elem( tool_shed, repository_name, changeset_revision, owner, tool_file_path, tool, None )
+ tool_elem = suc.generate_tool_elem( tool_shed,
+ repository_name,
+ changeset_revision,
+ owner,
+ tool_file_path,
+ tool,
+ None )
if inside_section:
if section_in_elem_list:
elem_list[ index ] = tool_section
@@ -367,7 +401,8 @@
tool_config = ''
if tool_sections:
for tool_section in tool_sections:
- # The value of tool_section will be None if the tool is displayed outside of any sections in the tool panel.
+ # The value of tool_section will be None if the tool is displayed outside
+ # of any sections in the tool panel.
if tool_section:
section_id = tool_section.id or ''
section_version = tool_section.version or ''
@@ -376,7 +411,10 @@
section_id = ''
section_version = ''
section_name = ''
- tool_section_dicts.append( dict( tool_config=tool_config, id=section_id, version=section_version, name=section_name ) )
+ tool_section_dicts.append( dict( tool_config=tool_config,
+ id=section_id,
+ version=section_version,
+ name=section_name ) )
else:
tool_section_dicts.append( dict( tool_config=tool_config, id='', version='', name='' ) )
return tool_section_dicts
@@ -409,9 +447,10 @@
def get_latest_tool_config_revision_from_repository_manifest( repo, filename, changeset_revision ):
"""
- Get the latest revision of a tool config file named filename from the repository manifest up to the value of changeset_revision.
- This method is restricted to tool_config files rather than any file since it is likely that, with the exception of tool config files,
- multiple files will have the same name in various directories within the repository.
+ Get the latest revision of a tool config file named filename from the repository
+ manifest up to the value of changeset_revision. This method is restricted to tool_config
+ files rather than any file since it is likely that, with the exception of tool config
+ files, multiple files will have the same name in various directories within the repository.
"""
stripped_filename = basic_util.strip_path( filename )
for changeset in hg_util.reversed_upper_bounded_changelog( repo, changeset_revision ):
@@ -422,8 +461,9 @@
try:
fctx = manifest_ctx[ ctx_file ]
except LookupError:
- # The ctx_file may have been moved in the change set. For example, 'ncbi_blastp_wrapper.xml' was moved to
- # 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml', so keep looking for the file until we find the new location.
+ # The ctx_file may have been moved in the change set. For example,
+ # 'ncbi_blastp_wrapper.xml' was moved to 'tools/ncbi_blast_plus/ncbi_blastp_wrapper.xml',
+ # so keep looking for the file until we find the new location.
continue
fh = tempfile.NamedTemporaryFile( 'wb', prefix="tmp-toolshed-gltcrfrm" )
tmp_filename = fh.name
@@ -436,10 +476,12 @@
def get_list_of_copied_sample_files( repo, ctx, dir ):
"""
- Find all sample files (files in the repository with the special .sample extension) in the reversed repository manifest up to ctx. Copy
- each discovered file to dir and return the list of filenames. If a .sample file was added in a changeset and then deleted in a later
- changeset, it will be returned in the deleted_sample_files list. The caller will set the value of app.config.tool_data_path to dir in
- order to load the tools and generate metadata for them.
+ Find all sample files (files in the repository with the special .sample extension)
+ in the reversed repository manifest up to ctx. Copy each discovered file to dir and
+ return the list of filenames. If a .sample file was added in a changeset and then
+ deleted in a later changeset, it will be returned in the deleted_sample_files list.
+ The caller will set the value of app.config.tool_data_path to dir in order to load
+ the tools and generate metadata for them.
"""
deleted_sample_files = []
sample_files = []
@@ -447,16 +489,20 @@
changeset_ctx = repo.changectx( changeset )
for ctx_file in changeset_ctx.files():
ctx_file_name = basic_util.strip_path( ctx_file )
- # If we decide in the future that files deleted later in the changelog should not be used, we can use the following if statement.
- # if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files:
+ # If we decide in the future that files deleted later in the changelog should
+ # not be used, we can use the following if statement. if ctx_file_name.endswith( '.sample' )
+ # and ctx_file_name not in sample_files and ctx_file_name not in deleted_sample_files:
if ctx_file_name.endswith( '.sample' ) and ctx_file_name not in sample_files:
fctx = hg_util.get_file_context_from_ctx( changeset_ctx, ctx_file )
if fctx in [ 'DELETED' ]:
- # Since the possibly future used if statement above is commented out, the same file that was initially added will be
- # discovered in an earlier changeset in the change log and fall through to the else block below. In other words, if
- # a file named blast2go.loc.sample was added in change set 0 and then deleted in changeset 3, the deleted file in changeset
- # 3 will be handled here, but the later discovered file in changeset 0 will be handled in the else block below. In this
- # way, the file contents will always be found for future tools even though the file was deleted.
+ # Since the possibly future used if statement above is commented out, the
+ # same file that was initially added will be discovered in an earlier changeset
+ # in the change log and fall through to the else block below. In other words,
+ # if a file named blast2go.loc.sample was added in change set 0 and then deleted
+ # in changeset 3, the deleted file in changeset 3 will be handled here, but the
+ # later discovered file in changeset 0 will be handled in the else block below.
+ # In this way, the file contents will always be found for future tools even though
+ # the file was deleted.
if ctx_file_name not in deleted_sample_files:
deleted_sample_files.append( ctx_file_name )
else:
@@ -522,14 +568,14 @@
"""Return a ToolVersionAssociation if one exists that associates the two received tool_versions"""
context = app.install_model.context
return context.query( app.install_model.ToolVersionAssociation ) \
- .filter( and_( app.install_model.ToolVersionAssociation.table.c.parent_id == parent_tool_version.id,
- app.install_model.ToolVersionAssociation.table.c.tool_id == tool_version.id ) ) \
- .first()
+ .filter( and_( app.install_model.ToolVersionAssociation.table.c.parent_id == parent_tool_version.id,
+ app.install_model.ToolVersionAssociation.table.c.tool_id == tool_version.id ) ) \
+ .first()
def get_version_lineage_for_tool( app, repository_id, repository_metadata, guid ):
"""
- Return the tool version lineage chain in descendant order for the received guid contained in the received
- repsitory_metadata.tool_versions.
+ Return the tool version lineage chain in descendant order for the received
+ guid contained in the received repsitory_metadata.tool_versions.
"""
repository = suc.get_repository_by_id( app, repository_id )
repo = hg_util.get_repo_for_repository( app, repository=repository, repo_path=None, create=False )
@@ -563,9 +609,10 @@
def handle_missing_data_table_entry( app, relative_install_dir, tool_path, repository_tools_tups ):
"""
- Inspect each tool to see if any have input parameters that are dynamically generated select lists that require entries in the
- tool_data_table_conf.xml file. This method is called only from Galaxy (not the tool shed) when a repository is being installed
- or reinstalled.
+ Inspect each tool to see if any have input parameters that are dynamically
+ generated select lists that require entries in the tool_data_table_conf.xml
+ file. This method is called only from Galaxy (not the tool shed) when a
+ repository is being installed or reinstalled.
"""
missing_data_table_entry = False
for index, repository_tools_tup in enumerate( repository_tools_tups ):
@@ -574,7 +621,8 @@
missing_data_table_entry = True
break
if missing_data_table_entry:
- # The repository must contain a tool_data_table_conf.xml.sample file that includes all required entries for all tools in the repository.
+ # The repository must contain a tool_data_table_conf.xml.sample file that includes
+ # all required entries for all tools in the repository.
sample_tool_data_table_conf = hg_util.get_config_from_disk( 'tool_data_table_conf.xml.sample', relative_install_dir )
if sample_tool_data_table_conf:
# Add entries to the ToolDataTableManager's in-memory data_tables dictionary.
@@ -591,8 +639,9 @@
def handle_missing_index_file( app, tool_path, sample_files, repository_tools_tups, sample_files_copied ):
"""
- Inspect each tool to see if it has any input parameters that are dynamically generated select lists that depend on a .loc file.
- This method is not called from the tool shed, but from Galaxy when a repository is being installed.
+ Inspect each tool to see if it has any input parameters that are dynamically
+ generated select lists that depend on a .loc file. This method is not called
+ from the tool shed, but from Galaxy when a repository is being installed.
"""
for index, repository_tools_tup in enumerate( repository_tools_tups ):
tup_path, guid, repository_tool = repository_tools_tup
@@ -615,53 +664,60 @@
repository_tools_tups[ index ] = ( tup_path, guid, repository_tool )
return repository_tools_tups, sample_files_copied
-def handle_sample_files_and_load_tool_from_disk( trans, repo_files_dir, repository_id, tool_config_filepath, work_dir ):
- # Copy all sample files from disk to a temporary directory since the sample files may be in multiple directories.
+def handle_sample_files_and_load_tool_from_disk( app, repo_files_dir, repository_id, tool_config_filepath, work_dir ):
+ """
+ Copy all sample files from disk to a temporary directory since the sample files may
+ be in multiple directories.
+ """
message = ''
- sample_files = copy_disk_sample_files_to_dir( trans, repo_files_dir, work_dir )
+ sample_files = copy_disk_sample_files_to_dir( app, repo_files_dir, work_dir )
if sample_files:
if 'tool_data_table_conf.xml.sample' in sample_files:
# Load entries into the tool_data_tables if the tool requires them.
tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' )
- error, message = handle_sample_tool_data_table_conf_file( trans.app, tool_data_table_config )
- tool, valid, message2 = load_tool_from_config( trans.app, repository_id, tool_config_filepath )
+ error, message = handle_sample_tool_data_table_conf_file( app, tool_data_table_config )
+ tool, valid, message2 = load_tool_from_config( app, repository_id, tool_config_filepath )
message = concat_messages( message, message2 )
return tool, valid, message, sample_files
-def handle_sample_files_and_load_tool_from_tmp_config( trans, repo, repository_id, changeset_revision, tool_config_filename, work_dir ):
+def handle_sample_files_and_load_tool_from_tmp_config( app, repo, repository_id, changeset_revision,
+ tool_config_filename, work_dir ):
tool = None
message = ''
ctx = hg_util.get_changectx_for_changeset( repo, changeset_revision )
- # We're not currently doing anything with the returned list of deleted_sample_files here. It is intended to help handle sample files that are in
- # the manifest, but have been deleted from disk.
+ # We're not currently doing anything with the returned list of deleted_sample_files here. It is
+ # intended to help handle sample files that are in the manifest, but have been deleted from disk.
sample_files, deleted_sample_files = get_list_of_copied_sample_files( repo, ctx, dir=work_dir )
if sample_files:
- trans.app.config.tool_data_path = work_dir
+ app.config.tool_data_path = work_dir
if 'tool_data_table_conf.xml.sample' in sample_files:
# Load entries into the tool_data_tables if the tool requires them.
tool_data_table_config = os.path.join( work_dir, 'tool_data_table_conf.xml' )
if tool_data_table_config:
- error, message = handle_sample_tool_data_table_conf_file( trans.app, tool_data_table_config )
+ error, message = handle_sample_tool_data_table_conf_file( app, tool_data_table_config )
if error:
log.debug( message )
manifest_ctx, ctx_file = hg_util.get_ctx_file_path_from_manifest( tool_config_filename, repo, changeset_revision )
if manifest_ctx and ctx_file:
- tool, message2 = load_tool_from_tmp_config( trans, repo, repository_id, manifest_ctx, ctx_file, work_dir )
+ tool, message2 = load_tool_from_tmp_config( app, repo, repository_id, manifest_ctx, ctx_file, work_dir )
message = concat_messages( message, message2 )
return tool, message, sample_files
def handle_sample_tool_data_table_conf_file( app, filename, persist=False ):
"""
- Parse the incoming filename and add new entries to the in-memory app.tool_data_tables dictionary. If persist is True (should only occur
- if call is from the Galaxy side, not the tool shed), the new entries will be appended to Galaxy's shed_tool_data_table_conf.xml file on disk.
+ Parse the incoming filename and add new entries to the in-memory
+ app.tool_data_tables dictionary. If persist is True (should only occur
+ if call is from the Galaxy side, not the tool shed), the new entries will
+ be appended to Galaxy's shed_tool_data_table_conf.xml file on disk.
"""
error = False
message = ''
try:
- new_table_elems, message = app.tool_data_tables.add_new_entries_from_config_file( config_filename=filename,
- tool_data_path=app.config.tool_data_path,
- shed_tool_data_table_config=app.config.shed_tool_data_table_config,
- persist=persist )
+ new_table_elems, message = \
+ app.tool_data_tables.add_new_entries_from_config_file( config_filename=filename,
+ tool_data_path=app.config.tool_data_path,
+ shed_tool_data_table_config=app.config.shed_tool_data_table_config,
+ persist=persist )
if message:
error = True
except Exception, e:
@@ -709,9 +765,10 @@
def handle_tool_panel_section( toolbox, tool_panel_section_id=None, new_tool_panel_section_label=None ):
"""Return a ToolSection object retrieved from the current in-memory tool_panel."""
- # If tool_panel_section_id is received, the section exists in the tool panel. In this case, the value of the
- # received tool_panel_section_id must be the id retrieved from a tool panel config (e.g., tool_conf.xml, which
- # may have getext). If new_tool_panel_section_label is received, a new section will be added to the tool panel.
+ # If tool_panel_section_id is received, the section exists in the tool panel. In this
+ # case, the value of the received tool_panel_section_id must be the id retrieved from a
+ # tool panel config (e.g., tool_conf.xml, which may have getext). If new_tool_panel_section_label
+ # is received, a new section will be added to the tool panel.
if new_tool_panel_section_label:
section_id = str( new_tool_panel_section_label.lower().replace( ' ', '_' ) )
tool_panel_section_key, tool_section = \
@@ -727,8 +784,9 @@
def handle_tool_versions( app, tool_version_dicts, tool_shed_repository ):
"""
- Using the list of tool_version_dicts retrieved from the tool shed (one per changeset revison up to the currently installed changeset revision),
- create the parent / child pairs of tool versions. Each dictionary contains { tool id : parent tool id } pairs.
+ Using the list of tool_version_dicts retrieved from the tool shed (one per changeset
+ revison up to the currently installed changeset revision), create the parent / child
+ pairs of tool versions. Each dictionary contains { tool id : parent tool id } pairs.
"""
context = app.install_model.context
for tool_version_dict in tool_version_dicts:
@@ -802,9 +860,10 @@
#store repository info in the table tagset for traceability
repo_elem = suc.generate_repository_info_elem_from_repository( tool_shed_repository, parent_elem=elem )
if elems:
- os.unlink( tool_data_table_conf_filename ) #remove old data_table
- app.tool_data_tables.to_xml_file( tool_data_table_conf_filename, elems ) #persist new data_table content
-
+ # Remove old data_table
+ os.unlink( tool_data_table_conf_filename )
+ # Persist new data_table content.
+ app.tool_data_tables.to_xml_file( tool_data_table_conf_filename, elems )
return tool_data_table_conf_filename, elems
@@ -829,10 +888,11 @@
def is_data_index_sample_file( file_path ):
"""
- Attempt to determine if a .sample file is appropriate for copying to ~/tool-data when a tool shed repository is being installed
- into a Galaxy instance.
+ Attempt to determine if a .sample file is appropriate for copying to ~/tool-data when
+ a tool shed repository is being installed into a Galaxy instance.
"""
- # Currently most data index files are tabular, so check that first. We'll assume that if the file is tabular, it's ok to copy.
+ # Currently most data index files are tabular, so check that first. We'll assume that
+ # if the file is tabular, it's ok to copy.
if is_column_based( file_path ):
return True
# If the file is any of the following, don't copy it.
@@ -851,7 +911,7 @@
# Default to copying the file if none of the above are true.
return True
-def load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_config_filename ):
+def load_tool_from_changeset_revision( app, repository_id, changeset_revision, tool_config_filename ):
"""
Return a loaded tool whose tool config file name (e.g., filtering.xml) is the value
of tool_config_filename. The value of changeset_revision is a valid (downloadable)
@@ -859,31 +919,35 @@
the received valid changeset revision and the first changeset revision in the repository,
searching backwards.
"""
- original_tool_data_path = trans.app.config.tool_data_path
- repository = suc.get_repository_in_tool_shed( trans.app, repository_id )
- repo_files_dir = repository.repo_path( trans.app )
- repo = hg_util.get_repo_for_repository( trans.app, repository=None, repo_path=repo_files_dir, create=False )
+ original_tool_data_path = app.config.tool_data_path
+ repository = suc.get_repository_in_tool_shed( app, repository_id )
+ repo_files_dir = repository.repo_path( app )
+ repo = hg_util.get_repo_for_repository( app, repository=None, repo_path=repo_files_dir, create=False )
message = ''
tool = None
can_use_disk_file = False
tool_config_filepath = suc.get_absolute_path_to_file_in_repository( repo_files_dir, tool_config_filename )
work_dir = tempfile.mkdtemp( prefix="tmp-toolshed-ltfcr" )
- can_use_disk_file = can_use_tool_config_disk_file( trans, repository, repo, tool_config_filepath, changeset_revision )
+ can_use_disk_file = can_use_tool_config_disk_file( app,
+ repository,
+ repo,
+ tool_config_filepath,
+ changeset_revision )
if can_use_disk_file:
- trans.app.config.tool_data_path = work_dir
- tool, valid, message, sample_files = handle_sample_files_and_load_tool_from_disk( trans,
+ app.config.tool_data_path = work_dir
+ tool, valid, message, sample_files = handle_sample_files_and_load_tool_from_disk( app,
repo_files_dir,
repository_id,
tool_config_filepath,
work_dir )
if tool is not None:
- invalid_files_and_errors_tups = check_tool_input_params( trans.app,
+ invalid_files_and_errors_tups = check_tool_input_params( app,
repo_files_dir,
tool_config_filename,
tool,
sample_files )
if invalid_files_and_errors_tups:
- message2 = generate_message_for_invalid_tools( trans.app,
+ message2 = generate_message_for_invalid_tools( app,
invalid_files_and_errors_tups,
repository,
metadata_dict=None,
@@ -891,16 +955,16 @@
displaying_invalid_tool=True )
message = concat_messages( message, message2 )
else:
- tool, message, sample_files = handle_sample_files_and_load_tool_from_tmp_config( trans,
+ tool, message, sample_files = handle_sample_files_and_load_tool_from_tmp_config( app,
repo,
repository_id,
changeset_revision,
tool_config_filename,
work_dir )
basic_util.remove_dir( work_dir )
- trans.app.config.tool_data_path = original_tool_data_path
+ app.config.tool_data_path = original_tool_data_path
# Reset the tool_data_tables by loading the empty tool_data_table_conf.xml file.
- reset_tool_data_tables( trans.app )
+ reset_tool_data_tables( app )
return repository, tool, message
def load_tool_from_config( app, repository_id, full_path ):
@@ -920,7 +984,7 @@
error_message = str( e )
return tool, valid, error_message
-def load_tool_from_tmp_config( trans, repo, repository_id, ctx, ctx_file, work_dir ):
+def load_tool_from_tmp_config( app, repo, repository_id, ctx, ctx_file, work_dir ):
tool = None
message = ''
tmp_tool_config = hg_util.get_named_tmpfile_from_ctx( ctx, ctx_file, work_dir )
@@ -936,7 +1000,7 @@
tmp_code_file_name = hg_util.copy_file_from_manifest( repo, ctx, code_file_name, work_dir )
if tmp_code_file_name:
tmp_code_files.append( tmp_code_file_name )
- tool, valid, message = load_tool_from_config( trans.app, repository_id, tmp_tool_config )
+ tool, valid, message = load_tool_from_config( app, repository_id, tmp_tool_config )
for tmp_code_file in tmp_code_files:
try:
os.unlink( tmp_code_file )
@@ -966,7 +1030,11 @@
def panel_entry_per_tool( tool_section_dict ):
# Return True if tool_section_dict looks like this.
- # {<Tool guid> : [{ tool_config : <tool_config_file>, id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}]}
+ # {<Tool guid> :
+ # [{ tool_config : <tool_config_file>,
+ # id: <ToolSection id>,
+ # version : <ToolSection version>,
+ # name : <TooSection name>}]}
# But not like this.
# { id: <ToolSection id>, version : <ToolSection version>, name : <TooSection name>}
if not tool_section_dict:
@@ -985,10 +1053,11 @@
if isinstance( tool.tool_action, UploadToolAction ):
app.toolbox.reload_tool_by_id( tool_id )
-def remove_from_shed_tool_config( trans, shed_tool_conf_dict, guids_to_remove ):
- # A tool shed repository is being uninstalled so change the shed_tool_conf file. Parse the config file to generate the entire list
- # of config_elems instead of using the in-memory list since it will be a subset of the entire list if one or more repositories have
- # been deactivated.
+def remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove ):
+ # A tool shed repository is being uninstalled so change the shed_tool_conf file.
+ # Parse the config file to generate the entire list of config_elems instead of
+ # using the in-memory list since it will be a subset of the entire list if one
+ # or more repositories have been deactivated.
shed_tool_conf = shed_tool_conf_dict[ 'config_filename' ]
tool_path = shed_tool_conf_dict[ 'tool_path' ]
config_elems = []
@@ -1016,26 +1085,31 @@
for config_elem in config_elems_to_remove:
config_elems.remove( config_elem )
# Persist the altered in-memory version of the tool config.
- suc.config_elems_to_xml_file( trans.app, config_elems, shed_tool_conf, tool_path )
+ suc.config_elems_to_xml_file( app, config_elems, shed_tool_conf, tool_path )
-def remove_from_tool_panel( trans, repository, shed_tool_conf, uninstall ):
- """A tool shed repository is being deactivated or uninstalled, so handle tool panel alterations accordingly."""
- # Determine where the tools are currently defined in the tool panel and store this information so the tools can be displayed
- # in the same way when the repository is activated or reinstalled.
- tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( trans.app, repository )
+def remove_from_tool_panel( app, repository, shed_tool_conf, uninstall ):
+ """
+ A tool shed repository is being deactivated or uninstalled, so handle tool panel
+ alterations accordingly.
+ """
+ # Determine where the tools are currently defined in the tool panel and store this
+ # information so the tools can be displayed in the same way when the repository is
+ # activated or reinstalled.
+ tool_panel_dict = suc.generate_tool_panel_dict_from_shed_tool_conf_entries( app, repository )
repository.metadata[ 'tool_panel_section' ] = tool_panel_dict
- trans.install_model.context.add( repository )
- trans.install_model.context.flush()
- # Create a list of guids for all tools that will be removed from the in-memory tool panel and config file on disk.
+ app.install_model.context.add( repository )
+ app.install_model.context.flush()
+ # Create a list of guids for all tools that will be removed from the in-memory tool panel
+ # and config file on disk.
guids_to_remove = [ k for k in tool_panel_dict.keys() ]
# Remove the tools from the toolbox's tools_by_id dictionary.
for guid_to_remove in guids_to_remove:
- if guid_to_remove in trans.app.toolbox.tools_by_id:
- del trans.app.toolbox.tools_by_id[ guid_to_remove ]
- index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( trans.app, shed_tool_conf )
+ if guid_to_remove in app.toolbox.tools_by_id:
+ del app.toolbox.tools_by_id[ guid_to_remove ]
+ index, shed_tool_conf_dict = suc.get_shed_tool_conf_dict( app, shed_tool_conf )
if uninstall:
# Remove from the shed_tool_conf file on disk.
- remove_from_shed_tool_config( trans, shed_tool_conf_dict, guids_to_remove )
+ remove_from_shed_tool_config( app, shed_tool_conf_dict, guids_to_remove )
config_elems = shed_tool_conf_dict[ 'config_elems' ]
config_elems_to_remove = []
for config_elem in config_elems:
@@ -1052,18 +1126,19 @@
# Remove the tool sub-element from the section element.
config_elem.remove( tool_elem )
# Remove the tool from the section in the in-memory tool panel.
- if section_key in trans.app.toolbox.tool_panel:
- tool_section = trans.app.toolbox.tool_panel[ section_key ]
+ if section_key in app.toolbox.tool_panel:
+ tool_section = app.toolbox.tool_panel[ section_key ]
guid = tool_elem.get( 'guid' )
tool_key = 'tool_%s' % str( guid )
# Get the list of versions of this tool that are currently available in the toolbox.
- available_tool_versions = trans.app.toolbox.get_loaded_tools_by_lineage( guid )
+ available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid )
if tool_key in tool_section.elems:
if available_tool_versions:
available_tool_versions.reverse()
replacement_tool_key = None
replacement_tool_version = None
- # Since we are going to remove the tool from the section, replace it with the newest loaded version of the tool.
+ # Since we are going to remove the tool from the section, replace it with the
+ # newest loaded version of the tool.
for available_tool_version in available_tool_versions:
available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
if available_tool_version.id in tool_section.elems.keys() or section_key == available_tool_section_id:
@@ -1078,15 +1153,17 @@
# Remove the tool from the tool section.
del tool_section.elems[ tool_key ]
# Add the replacement tool at the same location in the tool section.
- tool_section.elems.insert( tool_section_elems_index, replacement_tool_key, replacement_tool_version )
+ tool_section.elems.insert( tool_section_elems_index,
+ replacement_tool_key,
+ replacement_tool_version )
else:
del tool_section.elems[ tool_key ]
else:
del tool_section.elems[ tool_key ]
if uninstall:
# Remove the tool from the section in the in-memory integrated tool panel.
- if section_key in trans.app.toolbox.integrated_tool_panel:
- tool_section = trans.app.toolbox.integrated_tool_panel[ section_key ]
+ if section_key in app.toolbox.integrated_tool_panel:
+ tool_section = app.toolbox.integrated_tool_panel[ section_key ]
tool_key = 'tool_%s' % str( tool_elem.get( 'guid' ) )
if tool_key in tool_section.elems:
del tool_section.elems[ tool_key ]
@@ -1098,46 +1175,47 @@
if guid in guids_to_remove:
tool_key = 'tool_%s' % str( config_elem.get( 'guid' ) )
# Get the list of versions of this tool that are currently available in the toolbox.
- available_tool_versions = trans.app.toolbox.get_loaded_tools_by_lineage( guid )
- if tool_key in trans.app.toolbox.tool_panel:
+ available_tool_versions = app.toolbox.get_loaded_tools_by_lineage( guid )
+ if tool_key in app.toolbox.tool_panel:
if available_tool_versions:
available_tool_versions.reverse()
replacement_tool_key = None
replacement_tool_version = None
- # Since we are going to remove the tool from the section, replace it with the newest loaded version of the tool.
+ # Since we are going to remove the tool from the section, replace it with
+ # the newest loaded version of the tool.
for available_tool_version in available_tool_versions:
available_tool_section_id, available_tool_section_name = available_tool_version.get_panel_section()
- if available_tool_version.id in trans.app.toolbox.tool_panel.keys() or not available_tool_section_id:
+ if available_tool_version.id in app.toolbox.tool_panel.keys() or not available_tool_section_id:
replacement_tool_key = 'tool_%s' % str( available_tool_version.id )
replacement_tool_version = available_tool_version
break
if replacement_tool_key and replacement_tool_version:
# Get the index of the tool_key in the tool_section.
- for tool_panel_index, key in enumerate( trans.app.toolbox.tool_panel.keys() ):
+ for tool_panel_index, key in enumerate( app.toolbox.tool_panel.keys() ):
if key == tool_key:
break
# Remove the tool from the tool panel.
- del trans.app.toolbox.tool_panel[ tool_key ]
+ del app.toolbox.tool_panel[ tool_key ]
# Add the replacement tool at the same location in the tool panel.
- trans.app.toolbox.tool_panel.insert( tool_panel_index, replacement_tool_key, replacement_tool_version )
+ app.toolbox.tool_panel.insert( tool_panel_index, replacement_tool_key, replacement_tool_version )
else:
- del trans.app.toolbox.tool_panel[ tool_key ]
+ del app.toolbox.tool_panel[ tool_key ]
else:
- del trans.app.toolbox.tool_panel[ tool_key ]
+ del app.toolbox.tool_panel[ tool_key ]
if uninstall:
- if tool_key in trans.app.toolbox.integrated_tool_panel:
- del trans.app.toolbox.integrated_tool_panel[ tool_key ]
+ if tool_key in app.toolbox.integrated_tool_panel:
+ del app.toolbox.integrated_tool_panel[ tool_key ]
config_elems_to_remove.append( config_elem )
for config_elem in config_elems_to_remove:
# Remove the element from the in-memory list of elements.
config_elems.remove( config_elem )
# Update the config_elems of the in-memory shed_tool_conf_dict.
shed_tool_conf_dict[ 'config_elems' ] = config_elems
- trans.app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
- trans.app.toolbox_search = ToolBoxSearch( trans.app.toolbox )
- if uninstall and trans.app.config.update_integrated_tool_panel:
+ app.toolbox.shed_tool_confs[ index ] = shed_tool_conf_dict
+ app.toolbox_search = ToolBoxSearch( app.toolbox )
+ if uninstall and app.config.update_integrated_tool_panel:
# Write the current in-memory version of the integrated_tool_panel.xml file to disk.
- trans.app.toolbox.write_integrated_tool_panel_config_file()
+ app.toolbox.write_integrated_tool_panel_config_file()
def reset_tool_data_tables( app ):
# Reset the tool_data_tables to an empty dictionary.
diff -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff -r cd5d9bf32d865657208b0b657b08c9142b357e25 lib/tool_shed/util/workflow_util.py
--- a/lib/tool_shed/util/workflow_util.py
+++ b/lib/tool_shed/util/workflow_util.py
@@ -61,7 +61,10 @@
# We're in the tool shed.
for tool_dict in tools_metadata:
if self.tool_id in [ tool_dict[ 'id' ], tool_dict[ 'guid' ] ]:
- repository, self.tool, message = tool_util.load_tool_from_changeset_revision( trans, repository_id, changeset_revision, tool_dict[ 'tool_config' ] )
+ repository, self.tool, message = tool_util.load_tool_from_changeset_revision( trans.app,
+ repository_id,
+ changeset_revision,
+ tool_dict[ 'tool_config' ] )
if message and self.tool is None:
self.errors = 'unavailable'
break
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.
1
0
commit/galaxy-central: greg: Fix for bug introduced when I eliminated the use of trans from the tool shed's review_util.py module.
by commits-noreply@bitbucket.org 18 Jul '14
by commits-noreply@bitbucket.org 18 Jul '14
18 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/5242547f33ed/
Changeset: 5242547f33ed
User: greg
Date: 2014-07-18 12:50:16
Summary: Fix for bug introduced when I eliminated the use of trans from the tool shed's review_util.py module.
Affected #: 1 file
diff -r 6609ad71320787b849d6d68522b9f346090706c5 -r 5242547f33ed801a83837de5d507cc4b4c2eb6ff lib/tool_shed/util/review_util.py
--- a/lib/tool_shed/util/review_util.py
+++ b/lib/tool_shed/util/review_util.py
@@ -41,8 +41,8 @@
def get_component_by_name( app, name ):
"""Get a component from the database via a name."""
sa_session = app.model.context.current
- return sa_session.query( app.app.model.Component ) \
- .filter( app.app.model.Component.table.c.name==name ) \
+ return sa_session.query( app.model.Component ) \
+ .filter( app.model.Component.table.c.name==name ) \
.first()
def get_component_review_by_repository_review_id_component_id( app, repository_review_id, component_id ):
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.
1
0
commit/galaxy-central: jgoecks: Update embedded visualizations to work with recent refactoring.
by commits-noreply@bitbucket.org 17 Jul '14
by commits-noreply@bitbucket.org 17 Jul '14
17 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/6609ad713207/
Changeset: 6609ad713207
User: jgoecks
Date: 2014-07-17 22:53:04
Summary: Update embedded visualizations to work with recent refactoring.
Affected #: 2 files
diff -r 6cdc306ec75b37c5dbd8f0472d73956b60186926 -r 6609ad71320787b849d6d68522b9f346090706c5 static/scripts/viz/trackster.js
--- a/static/scripts/viz/trackster.js
+++ b/static/scripts/viz/trackster.js
@@ -566,6 +566,7 @@
});
return {
+ TracksterUI: TracksterUI,
GalaxyApp : TracksterView
};
diff -r 6cdc306ec75b37c5dbd8f0472d73956b60186926 -r 6609ad71320787b849d6d68522b9f346090706c5 templates/webapps/galaxy/visualization/display.mako
--- a/templates/webapps/galaxy/visualization/display.mako
+++ b/templates/webapps/galaxy/visualization/display.mako
@@ -60,13 +60,12 @@
"libs/backbone/backbone": { exports: "Backbone" },
}
});
- require( ["base", "viz/visualization", "viz/trackster_ui", "viz/trackster/tracks"],
- function( base, visualization, trackster_ui, tracks ) {
+ require( ["viz/trackster"], function(trackster) {
// FIXME: deliberate global required for now due to requireJS integration.
view = null;
-
- var ui = new (trackster_ui.TracksterUI)( "${h.url_for('/')}" )
+
+ var ui = new (trackster.TracksterUI)( "${h.url_for('/')}" )
container_element = $("#${trans.security.encode_id( visualization.id )}");
$(function() {
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.
1
0
commit/galaxy-central: jgoecks: Remove duplicated function definition.
by commits-noreply@bitbucket.org 17 Jul '14
by commits-noreply@bitbucket.org 17 Jul '14
17 Jul '14
1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/6cdc306ec75b/
Changeset: 6cdc306ec75b
User: jgoecks
Date: 2014-07-17 22:34:20
Summary: Remove duplicated function definition.
Affected #: 1 file
diff -r 1d578ea7ba67cedd9e8ce193c4cfdb581224a3df -r 6cdc306ec75b37c5dbd8f0472d73956b60186926 static/scripts/viz/trackster.js
--- a/static/scripts/viz/trackster.js
+++ b/static/scripts/viz/trackster.js
@@ -34,24 +34,6 @@
// trackster viewer
define( ["libs/underscore", "base", "viz/trackster/tracks", "viz/visualization"],
function(_, base, tracks, visualization) {
-/**
- * Returns an IconButtonMenuView for the provided configuration.
- * Configuration is a list of dictionaries where each dictionary
- * defines an icon button. Each dictionary must have the following
- * elements: icon_class, title, and on_click.
- */
-var create_icon_buttons_menu = function(config, global_config) {
- if (!global_config) { global_config = {}; }
-
- // Create and initialize menu.
- var buttons = new IconButtonCollection(
- _.map(config, function(button_config) {
- return new IconButton(_.extend(button_config, global_config));
- })
- );
-
- return new IconButtonMenuView( {collection: buttons} );
-};
/**
* User interface controls for trackster
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.
1
0
3 new commits in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/commits/68f8568c9519/
Changeset: 68f8568c9519
User: jgoecks
Date: 2014-07-17 21:44:45
Summary: Trackster: remove unused requirements.
Affected #: 1 file
diff -r f65eb16fdf1e0b7a6f3483373c32765107c3b2b6 -r 68f8568c95195600cb38adab95cf9fcf7d617aa3 static/scripts/viz/trackster_ui.js
--- a/static/scripts/viz/trackster_ui.js
+++ b/static/scripts/viz/trackster_ui.js
@@ -1,13 +1,10 @@
-define( ["base","libs/underscore","viz/trackster/slotting", "viz/trackster/painters", "viz/trackster/tracks", "viz/visualization" ],
- function( base, _, slotting, painters, tracks, visualization ) {
+define( ["base","libs/underscore", "viz/trackster/tracks", "viz/visualization" ],
+ function( base, _, tracks, visualization ) {
/************************************************************************
* Functions used for creating and managing the Trackster user interface.
************************************************************************/
-var object_from_template = tracks.object_from_template;
-
-
/**
* Returns an IconButtonMenuView for the provided configuration.
* Configuration is a list of dictionaries where each dictionary
@@ -96,7 +93,7 @@
{ icon_class: 'plus-button', title: 'Add tracks', on_click: function() {
visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", { 'f-dbkey': view.dbkey }, function(tracks) {
_.each(tracks, function(track) {
- view.add_drawable( object_from_template(track, view, view) );
+ view.add_drawable( tracks.object_from_template(track, view, view) );
});
});
} },
@@ -263,7 +260,7 @@
drawable_type,
drawable;
for (var i = 0; i < drawables_config.length; i++) {
- view.add_drawable( object_from_template( drawables_config[i], view, view ) );
+ view.add_drawable( tracks.object_from_template( drawables_config[i], view, view ) );
}
}
@@ -367,7 +364,7 @@
});
return {
- object_from_template: object_from_template,
+ object_from_template: tracks.object_from_template,
TracksterUI: TracksterUI
};
https://bitbucket.org/galaxy/galaxy-central/commits/40d27b0ba43a/
Changeset: 40d27b0ba43a
User: jgoecks
Date: 2014-07-17 22:23:17
Summary: Trackster: merge all top-level UI code into the same file for simplicity.
Affected #: 4 files
diff -r 68f8568c95195600cb38adab95cf9fcf7d617aa3 -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 static/scripts/packed/viz/trackster_ui.js
--- a/static/scripts/packed/viz/trackster_ui.js
+++ /dev/null
@@ -1,1 +0,0 @@
-define(["base","libs/underscore","viz/trackster/slotting","viz/trackster/painters","viz/trackster/tracks","viz/visualization"],function(a,f,e,c,d,h){var j=d.object_from_template;var b=function(l,k){if(!k){k={}}var m=new IconButtonCollection(f.map(l,function(n){return new IconButton(f.extend(n,k))}));return new IconButtonMenuView({collection:m})};var g=a.Base.extend({initialize:function(k){this.baseURL=k},createButtonMenu:function(){var k=this,l=b([{icon_class:"plus-button",title:"Add tracks",on_click:function(){h.select_datasets(galaxy_config.root+"visualization/list_current_history_datasets",galaxy_config.root+"api/datasets",{"f-dbkey":view.dbkey},function(m){f.each(m,function(n){view.add_drawable(j(n,view,view))})})}},{icon_class:"block--plus",title:"Add group",on_click:function(){view.add_drawable(new d.DrawableGroup(view,view,{name:"New Group"}))}},{icon_class:"bookmarks",title:"Bookmarks",on_click:function(){force_right_panel(($("div#right").css("right")=="0px"?"hide":"show"))}},{icon_class:"globe",title:"Circster",on_click:function(){window.location=k.baseURL+"visualization/circster?id="+view.vis_id}},{icon_class:"disk--arrow",title:"Save",on_click:function(){Galaxy.modal.show({title:"Saving...",body:"progress"});var m=[];$(".bookmark").each(function(){m.push({position:$(this).children(".position").text(),annotation:$(this).children(".annotation").text()})});var n=(view.overview_drawable?view.overview_drawable.config.get_value("name"):null),o={view:view.to_dict(),viewport:{chrom:view.chrom,start:view.low,end:view.high,overview:n},bookmarks:m};$.ajax({url:galaxy_config.root+"visualization/save",type:"POST",dataType:"json",data:{id:view.vis_id,title:view.config.get_value("name"),dbkey:view.dbkey,type:"trackster",vis_json:JSON.stringify(o)}}).success(function(p){Galaxy.modal.hide();view.vis_id=p.vis_id;view.has_changes=false;window.history.pushState({},"",p.url+window.location.hash)}).error(function(){Galaxy.modal.show({title:"Could Not Save",body:"Could not save visualization. Please try again later.",buttons:{Cancel:function(){Galaxy.modal.hide()}}})})}},{icon_class:"cross-circle",title:"Close",on_click:function(){window.location=galaxy_config.root+"visualization"}}],{tooltip_config:{placement:"bottom"}});this.buttonMenu=l;return l},add_bookmarks:function(){var k=this,l=this.baseURL;Galaxy.modal.show({title:"Select dataset for new bookmarks",body:"progress"});$.ajax({url:this.baseURL+"/visualization/list_histories",data:{"f-dbkey":view.dbkey},error:function(){alert("Grid failed")},success:function(m){Galaxy.modal.show({title:"Select dataset for new bookmarks",body:m,buttons:{Cancel:function(){Galaxy.modal.hide()},Insert:function(){$("input[name=id]:checked,input[name=ldda_ids]:checked").first().each(function(){var n,o=$(this).val();if($(this).attr("name")==="id"){n={hda_id:o}}else{n={ldda_id:o}}$.ajax({url:this.baseURL+"/visualization/bookmarks_from_dataset",data:n,dataType:"json"}).then(function(p){for(i=0;i<p.data.length;i++){var q=p.data[i];k.add_bookmark(q[0],q[1])}})});Galaxy.modal.hide()}}})}})},add_bookmark:function(o,m,k){var q=$("#right .unified-panel-body"),s=$("<div/>").addClass("bookmark").appendTo(q);var t=$("<div/>").addClass("position").appendTo(s),p=$("<a href=''/>").text(o).appendTo(t).click(function(){view.go_to(o);return false}),n=$("<div/>").text(m).appendTo(s);if(k){var r=$("<div/>").addClass("delete-icon-container").prependTo(s).click(function(){s.slideUp("fast");s.remove();view.has_changes=true;return false}),l=$("<a href=''/>").addClass("icon-button delete").appendTo(r);n.make_text_editable({num_rows:3,use_textarea:true,help_text:"Edit bookmark note"}).addClass("annotation")}view.has_changes=true;return s},create_visualization:function(p,k,o,q,n){var m=this,l=new d.TracksterView(f.extend(p,{header:false}));l.editor=true;$.when(l.load_chroms_deferred).then(function(B){if(k){var z=k.chrom,r=k.start,w=k.end,t=k.overview;if(z&&(r!==undefined)&&w){l.change_chrom(z,r,w)}else{l.change_chrom(B[0].chrom)}}else{l.change_chrom(B[0].chrom)}if(o){var u,s,v;for(var x=0;x<o.length;x++){l.add_drawable(j(o[x],l,l))}}l.update_intro_div();var A;for(var x=0;x<l.drawables.length;x++){if(l.drawables[x].config.get_value("name")===t){l.set_overview(l.drawables[x]);break}}if(q){var y;for(var x=0;x<q.length;x++){y=q[x];m.add_bookmark(y.position,y.annotation,n)}}l.has_changes=false});this.set_up_router({view:l});return l},set_up_router:function(k){new h.TrackBrowserRouter(k);Backbone.history.start()},init_keyboard_nav:function(k){$(document).keyup(function(l){if($(l.srcElement).is(":input")){return}switch(l.which){case 37:k.move_fraction(0.25);break;case 38:var m=Math.round(k.viewport_container.height()/15);k.viewport_container.scrollTop(k.viewport_container.scrollTop()-20);break;case 39:k.move_fraction(-0.25);break;case 40:var m=Math.round(k.viewport_container.height()/15);k.viewport_container.scrollTop(k.viewport_container.scrollTop()+20);break}})}});return{object_from_template:j,TracksterUI:g}});
\ No newline at end of file
diff -r 68f8568c95195600cb38adab95cf9fcf7d617aa3 -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 static/scripts/viz/trackster.js
--- a/static/scripts/viz/trackster.js
+++ b/static/scripts/viz/trackster.js
@@ -1,3 +1,7 @@
+/**
+ * Top-level trackster code, used for creating/loading visualizations and user interface elements.
+ */
+
// global variables
var ui = null;
var view = null;
@@ -28,15 +32,374 @@
});
// trackster viewer
-define( ["libs/backbone/backbone", "viz/trackster_ui"], function(backbone, trackster_ui) {
+define( ["libs/underscore", "base", "viz/trackster/tracks", "viz/visualization"],
+ function(_, base, tracks, visualization) {
+/**
+ * Returns an IconButtonMenuView for the provided configuration.
+ * Configuration is a list of dictionaries where each dictionary
+ * defines an icon button. Each dictionary must have the following
+ * elements: icon_class, title, and on_click.
+ */
+var create_icon_buttons_menu = function(config, global_config) {
+ if (!global_config) { global_config = {}; }
-var TracksterView = Backbone.View.extend(
+ // Create and initialize menu.
+ var buttons = new IconButtonCollection(
+ _.map(config, function(button_config) {
+ return new IconButton(_.extend(button_config, global_config));
+ })
+ );
+
+ return new IconButtonMenuView( {collection: buttons} );
+};
+
+/**
+ * User interface controls for trackster
+ */
+var TracksterUI = base.Base.extend({
+ initialize: function( baseURL ) {
+ this.baseURL = baseURL;
+ },
+
+ /**
+ * Save visualization, returning a Deferred object for the remote call to save.
+ */
+ save_viz: function() {
+ // show dialog
+ Galaxy.modal.show({title: "Saving...", body: "progress" });
+
+ // Save bookmarks.
+ var bookmarks = [];
+ $(".bookmark").each(function() {
+ bookmarks.push({
+ position: $(this).children(".position").text(),
+ annotation: $(this).children(".annotation").text()
+ });
+ });
+
+ // FIXME: give unique IDs to Drawables and save overview as ID.
+ var overview_track_name = (view.overview_drawable ? view.overview_drawable.config.get_value('name') : null),
+ viz_config = {
+ 'view': view.to_dict(),
+ 'viewport': { 'chrom': view.chrom, 'start': view.low , 'end': view.high, 'overview': overview_track_name },
+ 'bookmarks': bookmarks
+ };
+
+ // Make call to save visualization.
+ return $.ajax({
+ url: galaxy_config.root + "visualization/save",
+ type: "POST",
+ dataType: "json",
+ data: {
+ 'id' : view.vis_id,
+ 'title' : view.config.get_value('name'),
+ 'dbkey' : view.dbkey,
+ 'type' : 'trackster',
+ 'vis_json' : JSON.stringify(viz_config)
+ }
+ }).success(function(vis_info) {
+ Galaxy.modal.hide();
+ view.vis_id = vis_info.vis_id;
+ view.has_changes = false;
+
+ // Needed to set URL when first saving a visualization.
+ window.history.pushState({}, "", vis_info.url + window.location.hash);
+ }).error(function() {
+ // show dialog
+ Galaxy.modal.show({
+ title : "Could Not Save",
+ body : "Could not save visualization. Please try again later.",
+ buttons : { "Cancel": function() { Galaxy.modal.hide(); } }
+ });
+ });
+ },
+
+ /**
+ * Create button menu
+ */
+ createButtonMenu: function() {
+ var self = this,
+ menu = create_icon_buttons_menu([
+ { icon_class: 'plus-button', title: 'Add tracks', on_click: function() {
+ visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", { 'f-dbkey': view.dbkey }, function(tracks) {
+ _.each(tracks, function(track) {
+ view.add_drawable( tracks.object_from_template(track, view, view) );
+ });
+ });
+ } },
+ { icon_class: 'block--plus', title: 'Add group', on_click: function() {
+ view.add_drawable( new tracks.DrawableGroup(view, view, { name: "New Group" }) );
+ } },
+ { icon_class: 'bookmarks', title: 'Bookmarks', on_click: function() {
+ // HACK -- use style to determine if panel is hidden and hide/show accordingly.
+ force_right_panel(($("div#right").css("right") == "0px" ? "hide" : "show"));
+ } },
+ {
+ icon_class: 'globe',
+ title: 'Circster',
+ on_click: function() {
+ window.location = self.baseURL + 'visualization/circster?id=' + view.vis_id;
+ }
+ },
+ { icon_class: 'disk--arrow', title: 'Save', on_click: function() {
+ self.save_viz();
+ } },
+ {
+ icon_class: 'cross-circle',
+ title: 'Close',
+ on_click: function() {
+ self.handle_unsaved_changes(view);
+ }
+ }
+ ],
+ {
+ tooltip_config: { placement: 'bottom' }
+ });
+ this.buttonMenu = menu;
+ return menu;
+ },
+
+ /**
+ * Use a popup to select a dataset of create bookmarks from
+ */
+ add_bookmarks: function() {
+ var self = this,
+ baseURL = this.baseURL;
+
+ // show modal while loading history
+ Galaxy.modal.show({title: "Select dataset for new bookmarks", body: "progress" });
+
+ $.ajax({
+ url: this.baseURL + "/visualization/list_histories",
+ data: { "f-dbkey": view.dbkey },
+ error: function() { alert( "Grid failed" ); },
+ success: function(table_html) {
+
+ // show modal to select bookmarks
+ Galaxy.modal.show(
+ {
+ title : "Select dataset for new bookmarks",
+ body : table_html,
+ buttons :
+ {
+ "Cancel": function()
+ {
+ Galaxy.modal.hide();
+ },
+
+ "Insert": function()
+ {
+ // Just use the first selected
+ $('input[name=id]:checked,input[name=ldda_ids]:checked').first().each(function()
+ {
+ var data, id = $(this).val();
+ if ($(this).attr("name") === "id")
+ data = { hda_id: id };
+ else
+ data = { ldda_id: id};
+
+ $.ajax({
+ url: this.baseURL + "/visualization/bookmarks_from_dataset",
+ data: data,
+ dataType: "json"
+ }).then( function(data) {
+ for( i = 0; i < data.data.length; i++ ) {
+ var row = data.data[i];
+ self.add_bookmark( row[0], row[1] );
+ }
+ });
+ });
+ Galaxy.modal.hide();
+ }
+ }
+ });
+ }
+ });
+ },
+
+ /**
+ * Add bookmark.
+ */
+ add_bookmark: function(position, annotation, editable) {
+ // Create HTML.
+ var bookmarks_container = $("#right .unified-panel-body"),
+ new_bookmark = $("<div/>").addClass("bookmark").appendTo(bookmarks_container);
+
+ var position_div = $("<div/>").addClass("position").appendTo(new_bookmark),
+ position_link = $("<a href=''/>").text(position).appendTo(position_div).click(function() {
+ view.go_to(position);
+ return false;
+ }),
+ annotation_div = $("<div/>").text(annotation).appendTo(new_bookmark);
+
+ // If editable, enable bookmark deletion and annotation editing.
+ if (editable) {
+ var delete_icon_container = $("<div/>").addClass("delete-icon-container").prependTo(new_bookmark).click(function (){
+ // Remove bookmark.
+ new_bookmark.slideUp("fast");
+ new_bookmark.remove();
+ view.has_changes = true;
+ return false;
+ }),
+ delete_icon = $("<a href=''/>").addClass("icon-button delete").appendTo(delete_icon_container);
+ annotation_div.make_text_editable({
+ num_rows: 3,
+ use_textarea: true,
+ help_text: "Edit bookmark note"
+ }).addClass("annotation");
+ }
+
+ view.has_changes = true;
+ return new_bookmark;
+ },
+
+ /**
+ * Create a complete Trackster visualization. Returns view.
+ */
+ create_visualization: function(view_config, viewport_config, drawables_config, bookmarks_config, editable) {
+
+ // Create view.
+ var self = this,
+ view = new tracks.TracksterView(_.extend(view_config, {header: false}));
+ view.editor = true;
+ $.when( view.load_chroms_deferred ).then(function(chrom_info) {
+ // Viewport config.
+ if (viewport_config) {
+ var chrom = viewport_config.chrom,
+ start = viewport_config.start,
+ end = viewport_config.end,
+ overview_drawable_name = viewport_config.overview;
+
+ if (chrom && (start !== undefined) && end) {
+ view.change_chrom(chrom, start, end);
+ }
+ else {
+ // No valid viewport, so use first chromosome.
+ view.change_chrom(chrom_info[0].chrom);
+ }
+ }
+ else {
+ // No viewport, so use first chromosome.
+ view.change_chrom(chrom_info[0].chrom);
+ }
+
+ // Add drawables to view.
+ if (drawables_config) {
+ // FIXME: can from_dict() be used to create view and add drawables?
+ var drawable_config,
+ drawable_type,
+ drawable;
+ for (var i = 0; i < drawables_config.length; i++) {
+ view.add_drawable( tracks.object_from_template( drawables_config[i], view, view ) );
+ }
+ }
+
+ // Set overview.
+ var overview_drawable;
+ for (var i = 0; i < view.drawables.length; i++) {
+ if (view.drawables[i].config.get_value('name') === overview_drawable_name) {
+ view.set_overview(view.drawables[i]);
+ break;
+ }
+ }
+
+ // Load bookmarks.
+ if (bookmarks_config) {
+ var bookmark;
+ for (var i = 0; i < bookmarks_config.length; i++) {
+ bookmark = bookmarks_config[i];
+ self.add_bookmark(bookmark['position'], bookmark['annotation'], editable);
+ }
+ }
+
+ // View has no changes as of yet.
+ view.has_changes = false;
+ });
+
+ // Final initialization.
+ this.set_up_router({view: view});
+
+ return view;
+ },
+
+ /**
+ * Set up location router to use hashes as track browser locations.
+ */
+ set_up_router : function(options)
+ {
+ new visualization.TrackBrowserRouter(options);
+ Backbone.history.start();
+ },
+
+ /**
+ * Set up keyboard navigation for a visualization.
+ */
+ init_keyboard_nav: function(view) {
+ // Keyboard navigation. Scroll ~7% of height when scrolling up/down.
+ $(document).keyup(function(e) {
+ // Do not navigate if arrow keys used in input element.
+ if ($(e.srcElement).is(':input')) {
+ return;
+ }
+
+ // Key codes: left == 37, up == 38, right == 39, down == 40
+ switch(e.which) {
+ case 37:
+ view.move_fraction(0.25);
+ break;
+ case 38:
+ var change = Math.round(view.viewport_container.height()/15.0);
+ view.viewport_container.scrollTop( view.viewport_container.scrollTop() - 20);
+ break;
+ case 39:
+ view.move_fraction(-0.25);
+ break;
+ case 40:
+ var change = Math.round(view.viewport_container.height()/15.0);
+ view.viewport_container.scrollTop( view.viewport_container.scrollTop() + 20);
+ break;
+ }
+ });
+ },
+
+ /**
+ * Handle unsaved changes in visualization.
+ */
+ handle_unsaved_changes: function(view) {
+ if (view.has_changes) {
+ var self = this;
+ Galaxy.modal.show({
+ title: "Close visualization",
+ body: "There are unsaved changes to your visualization which will be lost if you do not save them.",
+ buttons: {
+ "Cancel": function() { Galaxy.modal.hide(); },
+ "Leave without Saving" : function() {
+ window.onbeforeunload = undefined;
+ window.location = galaxy_config.root + 'visualization';
+ },
+ "Save" : function() {
+ $.when(self.save_viz()).then(function() {
+ window.location = galaxy_config.root + 'visualization';
+ });
+ }
+ }
+ });
+
+ }
+ else {
+ window.location = galaxy_config.root + 'visualization';
+ }
+ }
+
+});
+
+var TracksterView = base.Backbone.View.extend(
{
// initalize trackster
initialize : function ()
{
// load ui
- ui = new trackster_ui.TracksterUI(galaxy_config.root);
+ ui = new TracksterUI(galaxy_config.root);
// create button menu
ui.createButtonMenu();
@@ -197,7 +560,7 @@
url: galaxy_config.root + "api/datasets/" + galaxy_config.app.add_dataset,
data: { hda_ldda: 'hda', data_type: 'track_config' },
dataType: "json",
- success: function(track_data) { view.add_drawable( trackster_ui.object_from_template(track_data, view, view) ); }
+ success: function(track_data) { view.add_drawable( tracks.object_from_template(track_data, view, view) ); }
});
// initialize icons
@@ -220,10 +583,8 @@
}
});
-// return
return {
GalaxyApp : TracksterView
};
-// done
});
\ No newline at end of file
diff -r 68f8568c95195600cb38adab95cf9fcf7d617aa3 -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 static/scripts/viz/trackster/tracks.js
--- a/static/scripts/viz/trackster/tracks.js
+++ b/static/scripts/viz/trackster/tracks.js
@@ -877,7 +877,7 @@
this.content_div = this.viewport_container;
is_container(this.viewport_container, view);
// Introduction div shown when there are no tracks.
- this.intro_div = $("<div/>").addClass("intro").appendTo(this.viewport_container).hide();
+ this.intro_div = $("<div/>").addClass("intro").appendTo(this.viewport_container);
var add_tracks_button = $("<div/>").text("Add Datasets to Visualization").addClass("action-button").appendTo(this.intro_div).click(function () {
visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", { 'f-dbkey': view.dbkey }, function(tracks) {
_.each(tracks, function(track) {
diff -r 68f8568c95195600cb38adab95cf9fcf7d617aa3 -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 static/scripts/viz/trackster_ui.js
--- a/static/scripts/viz/trackster_ui.js
+++ /dev/null
@@ -1,371 +0,0 @@
-define( ["base","libs/underscore", "viz/trackster/tracks", "viz/visualization" ],
- function( base, _, tracks, visualization ) {
-
-/************************************************************************
- * Functions used for creating and managing the Trackster user interface.
- ************************************************************************/
-
-/**
- * Returns an IconButtonMenuView for the provided configuration.
- * Configuration is a list of dictionaries where each dictionary
- * defines an icon button. Each dictionary must have the following
- * elements: icon_class, title, and on_click.
- */
-var create_icon_buttons_menu = function(config, global_config) {
- if (!global_config) { global_config = {}; }
-
- // Create and initialize menu.
- var buttons = new IconButtonCollection(
- _.map(config, function(button_config) {
- return new IconButton(_.extend(button_config, global_config));
- })
- );
-
- return new IconButtonMenuView( {collection: buttons} );
-};
-
-
-var TracksterUI = base.Base.extend({
-
- initialize: function( baseURL ) {
- this.baseURL = baseURL;
- },
-
- /**
- * Save visualization, returning a Deferred object for the remote call to save.
- */
- save_viz: function() {
- // show dialog
- Galaxy.modal.show({title: "Saving...", body: "progress" });
-
- // Save bookmarks.
- var bookmarks = [];
- $(".bookmark").each(function() {
- bookmarks.push({
- position: $(this).children(".position").text(),
- annotation: $(this).children(".annotation").text()
- });
- });
-
- // FIXME: give unique IDs to Drawables and save overview as ID.
- var overview_track_name = (view.overview_drawable ? view.overview_drawable.config.get_value('name') : null),
- viz_config = {
- 'view': view.to_dict(),
- 'viewport': { 'chrom': view.chrom, 'start': view.low , 'end': view.high, 'overview': overview_track_name },
- 'bookmarks': bookmarks
- };
-
- // Make call to save visualization.
- return $.ajax({
- url: galaxy_config.root + "visualization/save",
- type: "POST",
- dataType: "json",
- data: {
- 'id' : view.vis_id,
- 'title' : view.config.get_value('name'),
- 'dbkey' : view.dbkey,
- 'type' : 'trackster',
- 'vis_json' : JSON.stringify(viz_config)
- }
- }).success(function(vis_info) {
- Galaxy.modal.hide();
- view.vis_id = vis_info.vis_id;
- view.has_changes = false;
-
- // Needed to set URL when first saving a visualization.
- window.history.pushState({}, "", vis_info.url + window.location.hash);
- }).error(function() {
- // show dialog
- Galaxy.modal.show({
- title : "Could Not Save",
- body : "Could not save visualization. Please try again later.",
- buttons : { "Cancel": function() { Galaxy.modal.hide(); } }
- });
- });
- },
-
- /**
- * Create button menu
- */
- createButtonMenu: function() {
- var self = this,
- menu = create_icon_buttons_menu([
- { icon_class: 'plus-button', title: 'Add tracks', on_click: function() {
- visualization.select_datasets(galaxy_config.root + "visualization/list_current_history_datasets", galaxy_config.root + "api/datasets", { 'f-dbkey': view.dbkey }, function(tracks) {
- _.each(tracks, function(track) {
- view.add_drawable( tracks.object_from_template(track, view, view) );
- });
- });
- } },
- { icon_class: 'block--plus', title: 'Add group', on_click: function() {
- view.add_drawable( new tracks.DrawableGroup(view, view, { name: "New Group" }) );
- } },
- { icon_class: 'bookmarks', title: 'Bookmarks', on_click: function() {
- // HACK -- use style to determine if panel is hidden and hide/show accordingly.
- force_right_panel(($("div#right").css("right") == "0px" ? "hide" : "show"));
- } },
- {
- icon_class: 'globe',
- title: 'Circster',
- on_click: function() {
- window.location = self.baseURL + 'visualization/circster?id=' + view.vis_id;
- }
- },
- { icon_class: 'disk--arrow', title: 'Save', on_click: function() {
- self.save_viz();
- } },
- {
- icon_class: 'cross-circle',
- title: 'Close',
- on_click: function() {
- self.handle_unsaved_changes(view);
- }
- }
- ],
- {
- tooltip_config: { placement: 'bottom' }
- });
- this.buttonMenu = menu;
- return menu;
- },
-
- /**
- * Use a popup to select a dataset of create bookmarks from
- */
- add_bookmarks: function() {
- var self = this,
- baseURL = this.baseURL;
-
- // show modal while loading history
- Galaxy.modal.show({title: "Select dataset for new bookmarks", body: "progress" });
-
- $.ajax({
- url: this.baseURL + "/visualization/list_histories",
- data: { "f-dbkey": view.dbkey },
- error: function() { alert( "Grid failed" ); },
- success: function(table_html) {
-
- // show modal to select bookmarks
- Galaxy.modal.show(
- {
- title : "Select dataset for new bookmarks",
- body : table_html,
- buttons :
- {
- "Cancel": function()
- {
- Galaxy.modal.hide();
- },
-
- "Insert": function()
- {
- // Just use the first selected
- $('input[name=id]:checked,input[name=ldda_ids]:checked').first().each(function()
- {
- var data, id = $(this).val();
- if ($(this).attr("name") === "id")
- data = { hda_id: id };
- else
- data = { ldda_id: id};
-
- $.ajax({
- url: this.baseURL + "/visualization/bookmarks_from_dataset",
- data: data,
- dataType: "json"
- }).then( function(data) {
- for( i = 0; i < data.data.length; i++ ) {
- var row = data.data[i];
- self.add_bookmark( row[0], row[1] );
- }
- });
- });
- Galaxy.modal.hide();
- }
- }
- });
- }
- });
- },
-
- /**
- * Add bookmark.
- */
- add_bookmark: function(position, annotation, editable) {
- // Create HTML.
- var bookmarks_container = $("#right .unified-panel-body"),
- new_bookmark = $("<div/>").addClass("bookmark").appendTo(bookmarks_container);
-
- var position_div = $("<div/>").addClass("position").appendTo(new_bookmark),
- position_link = $("<a href=''/>").text(position).appendTo(position_div).click(function() {
- view.go_to(position);
- return false;
- }),
- annotation_div = $("<div/>").text(annotation).appendTo(new_bookmark);
-
- // If editable, enable bookmark deletion and annotation editing.
- if (editable) {
- var delete_icon_container = $("<div/>").addClass("delete-icon-container").prependTo(new_bookmark).click(function (){
- // Remove bookmark.
- new_bookmark.slideUp("fast");
- new_bookmark.remove();
- view.has_changes = true;
- return false;
- }),
- delete_icon = $("<a href=''/>").addClass("icon-button delete").appendTo(delete_icon_container);
- annotation_div.make_text_editable({
- num_rows: 3,
- use_textarea: true,
- help_text: "Edit bookmark note"
- }).addClass("annotation");
- }
-
- view.has_changes = true;
- return new_bookmark;
- },
-
- /**
- * Create a complete Trackster visualization. Returns view.
- */
- create_visualization: function(view_config, viewport_config, drawables_config, bookmarks_config, editable) {
-
- // Create view.
- var self = this,
- view = new tracks.TracksterView(_.extend(view_config, {header: false}));
- view.editor = true;
- $.when( view.load_chroms_deferred ).then(function(chrom_info) {
- // Viewport config.
- if (viewport_config) {
- var chrom = viewport_config.chrom,
- start = viewport_config.start,
- end = viewport_config.end,
- overview_drawable_name = viewport_config.overview;
-
- if (chrom && (start !== undefined) && end) {
- view.change_chrom(chrom, start, end);
- }
- else {
- // No valid viewport, so use first chromosome.
- view.change_chrom(chrom_info[0].chrom);
- }
- }
- else {
- // No viewport, so use first chromosome.
- view.change_chrom(chrom_info[0].chrom);
- }
-
- // Add drawables to view.
- if (drawables_config) {
- // FIXME: can from_dict() be used to create view and add drawables?
- var drawable_config,
- drawable_type,
- drawable;
- for (var i = 0; i < drawables_config.length; i++) {
- view.add_drawable( tracks.object_from_template( drawables_config[i], view, view ) );
- }
- }
-
- // Set overview.
- var overview_drawable;
- for (var i = 0; i < view.drawables.length; i++) {
- if (view.drawables[i].config.get_value('name') === overview_drawable_name) {
- view.set_overview(view.drawables[i]);
- break;
- }
- }
-
- // Load bookmarks.
- if (bookmarks_config) {
- var bookmark;
- for (var i = 0; i < bookmarks_config.length; i++) {
- bookmark = bookmarks_config[i];
- self.add_bookmark(bookmark['position'], bookmark['annotation'], editable);
- }
- }
-
- // View has no changes as of yet.
- view.has_changes = false;
- });
-
- // Final initialization.
- this.set_up_router({view: view});
-
- return view;
- },
-
- /**
- * Set up location router to use hashes as track browser locations.
- */
- set_up_router : function(options)
- {
- new visualization.TrackBrowserRouter(options);
- Backbone.history.start();
- },
-
- /**
- * Set up keyboard navigation for a visualization.
- */
- init_keyboard_nav: function(view) {
- // Keyboard navigation. Scroll ~7% of height when scrolling up/down.
- $(document).keyup(function(e) {
- // Do not navigate if arrow keys used in input element.
- if ($(e.srcElement).is(':input')) {
- return;
- }
-
- // Key codes: left == 37, up == 38, right == 39, down == 40
- switch(e.which) {
- case 37:
- view.move_fraction(0.25);
- break;
- case 38:
- var change = Math.round(view.viewport_container.height()/15.0);
- view.viewport_container.scrollTop( view.viewport_container.scrollTop() - 20);
- break;
- case 39:
- view.move_fraction(-0.25);
- break;
- case 40:
- var change = Math.round(view.viewport_container.height()/15.0);
- view.viewport_container.scrollTop( view.viewport_container.scrollTop() + 20);
- break;
- }
- });
- },
-
- /**
- * Handle unsaved changes in visualization.
- */
- handle_unsaved_changes: function(view) {
- if (view.has_changes) {
- var self = this;
- Galaxy.modal.show({
- title: "Close visualization",
- body: "There are unsaved changes to your visualization which will be lost if you do not save them.",
- buttons: {
- "Cancel": function() { Galaxy.modal.hide(); },
- "Leave without Saving" : function() {
- window.onbeforeunload = undefined;
- window.location = galaxy_config.root + 'visualization';
- },
- "Save" : function() {
- $.when(self.save_viz()).then(function() {
- window.location = galaxy_config.root + 'visualization';
- });
- }
- }
- });
-
- }
- else {
- window.location = galaxy_config.root + 'visualization';
- }
- }
-
-});
-
-return {
- object_from_template: tracks.object_from_template,
- TracksterUI: TracksterUI
-};
-
-});
https://bitbucket.org/galaxy/galaxy-central/commits/1d578ea7ba67/
Changeset: 1d578ea7ba67
User: jgoecks
Date: 2014-07-17 22:23:33
Summary: Automated merge.
Affected #: 4 files
diff -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 -r 1d578ea7ba67cedd9e8ce193c4cfdb581224a3df lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
--- a/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
+++ b/lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
@@ -169,7 +169,7 @@
message = kwd.get( 'message', '' )
status = kwd.get( 'status', 'done' )
tool_dependency_ids = tool_dependency_util.get_tool_dependency_ids( as_string=False, **kwd )
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_ids[ 0 ] )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_ids[ 0 ] )
if tool_dependency.in_error_state:
message = "This tool dependency is not installed correctly (see the <b>Tool dependency installation error</b> below). "
message += "Choose <b>Uninstall this tool dependency</b> from the <b>Repository Actions</b> menu, correct problems "
@@ -806,7 +806,7 @@
tool_dependency_ids = tool_dependency_util.get_tool_dependency_ids( as_string=False, **kwd )
if tool_dependency_ids:
# We need a tool_shed_repository, so get it from one of the tool_dependencies.
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_ids[ 0 ] )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_ids[ 0 ] )
tool_shed_repository = tool_dependency.tool_shed_repository
else:
# The user must be on the manage_repository_tool_dependencies page and clicked the button to either install or uninstall a
@@ -830,7 +830,7 @@
elif operation == 'uninstall':
tool_dependencies_for_uninstallation = []
for tool_dependency_id in tool_dependency_ids:
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_id )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_id )
if tool_dependency.status in [ trans.install_model.ToolDependency.installation_status.INSTALLED,
trans.install_model.ToolDependency.installation_status.ERROR ]:
tool_dependencies_for_uninstallation.append( tool_dependency )
@@ -845,7 +845,7 @@
if trans.app.config.tool_dependency_dir:
tool_dependencies_for_installation = []
for tool_dependency_id in tool_dependency_ids:
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_id )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_id )
if tool_dependency.status in [ trans.install_model.ToolDependency.installation_status.NEVER_INSTALLED,
trans.install_model.ToolDependency.installation_status.UNINSTALLED ]:
tool_dependencies_for_installation.append( tool_dependency )
@@ -889,7 +889,7 @@
repository_id = kwd.get( 'repository_id', None )
if tool_dependency_ids:
# We need a tool_shed_repository, so get it from one of the tool_dependencies.
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_ids[ 0 ] )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_ids[ 0 ] )
tool_shed_repository = tool_dependency.tool_shed_repository
else:
# The user must be on the manage_repository_tool_dependencies page and clicked the button to either install or uninstall a
@@ -914,7 +914,7 @@
if trans.app.config.tool_dependency_dir:
tool_dependencies_for_installation = []
for tool_dependency_id in tool_dependency_ids:
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_id )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_id )
if tool_dependency.status in [ trans.install_model.ToolDependency.installation_status.NEVER_INSTALLED,
trans.install_model.ToolDependency.installation_status.UNINSTALLED ]:
tool_dependencies_for_installation.append( tool_dependency )
@@ -1849,7 +1849,7 @@
tool_dependency_ids = util.listify( kwd.get( 'id', None ) )
tool_dependencies = []
for tool_dependency_id in tool_dependency_ids:
- tool_dependency = tool_dependency_util.get_tool_dependency( trans, tool_dependency_id )
+ tool_dependency = tool_dependency_util.get_tool_dependency( trans.app, tool_dependency_id )
tool_dependencies.append( tool_dependency )
tool_shed_repository = tool_dependencies[ 0 ].tool_shed_repository
if kwd.get( 'uninstall_tool_dependencies_button', False ):
diff -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 -r 1d578ea7ba67cedd9e8ce193c4cfdb581224a3df lib/galaxy/webapps/tool_shed/controllers/repository.py
--- a/lib/galaxy/webapps/tool_shed/controllers/repository.py
+++ b/lib/galaxy/webapps/tool_shed/controllers/repository.py
@@ -1347,7 +1347,7 @@
match_tuples = []
ok = True
if tool_ids or tool_names or tool_versions:
- ok, match_tuples = search_util.search_repository_metadata( trans,
+ ok, match_tuples = search_util.search_repository_metadata( trans.app,
exact_matches_checked,
tool_ids=tool_ids,
tool_names=tool_names,
@@ -1437,9 +1437,14 @@
match_tuples = []
ok = True
if workflow_names:
- ok, match_tuples = search_util.search_repository_metadata( trans, exact_matches_checked, workflow_names=workflow_names )
+ ok, match_tuples = search_util.search_repository_metadata( trans.app,
+ exact_matches_checked,
+ workflow_names=workflow_names )
else:
- ok, match_tuples = search_util.search_repository_metadata( trans, exact_matches_checked, workflow_names=[], all_workflows=True )
+ ok, match_tuples = search_util.search_repository_metadata( trans.app,
+ exact_matches_checked,
+ workflow_names=[],
+ all_workflows=True )
if ok:
kwd[ 'match_tuples' ] = match_tuples
if trans.webapp.name == 'galaxy':
diff -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 -r 1d578ea7ba67cedd9e8ce193c4cfdb581224a3df lib/tool_shed/util/search_util.py
--- a/lib/tool_shed/util/search_util.py
+++ b/lib/tool_shed/util/search_util.py
@@ -81,15 +81,17 @@
match_tuples.append( ( repository_metadata.repository_id, repository_metadata.changeset_revision ) )
return match_tuples
-def search_repository_metadata( trans, exact_matches_checked, tool_ids='', tool_names='', tool_versions='', workflow_names='', all_workflows=False ):
+def search_repository_metadata( app, exact_matches_checked, tool_ids='', tool_names='', tool_versions='',
+ workflow_names='', all_workflows=False ):
+ sa_session=app.model.context.current
match_tuples = []
ok = True
if tool_ids or tool_names or tool_versions:
- for repository_metadata in trans.sa_session.query( trans.model.RepositoryMetadata ) \
- .filter( trans.model.RepositoryMetadata.table.c.includes_tools == True ) \
- .join( trans.model.Repository ) \
- .filter( and_( trans.model.Repository.table.c.deleted == False,
- trans.model.Repository.table.c.deprecated == False ) ):
+ for repository_metadata in sa_session.query( app.model.RepositoryMetadata ) \
+ .filter( app.model.RepositoryMetadata.table.c.includes_tools == True ) \
+ .join( app.model.Repository ) \
+ .filter( and_( app.model.Repository.table.c.deleted == False,
+ app.model.Repository.table.c.deprecated == False ) ):
metadata = repository_metadata.metadata
if metadata:
tools = metadata.get( 'tools', [] )
@@ -140,11 +142,11 @@
else:
ok = False
elif workflow_names or all_workflows:
- for repository_metadata in trans.sa_session.query( trans.model.RepositoryMetadata ) \
- .filter( trans.model.RepositoryMetadata.table.c.includes_workflows == True ) \
- .join( trans.model.Repository ) \
- .filter( and_( trans.model.Repository.table.c.deleted == False,
- trans.model.Repository.table.c.deprecated == False ) ):
+ for repository_metadata in sa_session.query( app.model.RepositoryMetadata ) \
+ .filter( app.model.RepositoryMetadata.table.c.includes_workflows == True ) \
+ .join( app.model.Repository ) \
+ .filter( and_( app.model.Repository.table.c.deleted == False,
+ app.model.Repository.table.c.deprecated == False ) ):
metadata = repository_metadata.metadata
if metadata:
# metadata[ 'workflows' ] is a list of tuples where each contained tuple is
diff -r 40d27b0ba43a746aeecd8e78891c270bcb513ca8 -r 1d578ea7ba67cedd9e8ce193c4cfdb581224a3df lib/tool_shed/util/tool_dependency_util.py
--- a/lib/tool_shed/util/tool_dependency_util.py
+++ b/lib/tool_shed/util/tool_dependency_util.py
@@ -128,9 +128,9 @@
platform_dict[ 'architecture' ] = machine.lower()
return platform_dict
-def get_tool_dependency( trans, id ):
+def get_tool_dependency( app, id ):
"""Get a tool_dependency from the database via id"""
- return trans.install_model.context.query( trans.install_model.ToolDependency ).get( trans.security.decode_id( id ) )
+ return app.install_model.context.query( app.install_model.ToolDependency ).get( app.security.decode_id( id ) )
def get_tool_dependency_by_name_type_repository( app, repository, name, type ):
context = app.install_model.context
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.
1
0