commit/galaxy-central: greg: Add a new ~/tool_shed/util/metadata_util.py component to contain all tool shed related repository metadata utility methods.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/4827bed265e7/ changeset: 4827bed265e7 user: greg date: 2013-03-13 20:37:29 summary: Add a new ~/tool_shed/util/metadata_util.py component to contain all tool shed related repository metadata utility methods. affected #: 11 files diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 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 @@ -7,6 +7,7 @@ from galaxy.model.orm import or_ import tool_shed.util.shed_util as shed_util import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util from tool_shed.util import encoding_util from galaxy.webapps.tool_shed.util import workflow_util import tool_shed.galaxy_install.grids.admin_toolshed_grids as admin_toolshed_grids @@ -380,16 +381,16 @@ when an admin is installing a new repository or reinstalling an uninstalled repository. """ shed_config_dict = trans.app.toolbox.get_shed_config_dict_by_filename( shed_tool_conf ) - metadata_dict, invalid_file_tups = suc.generate_metadata_for_changeset_revision( app=trans.app, - repository=tool_shed_repository, - changeset_revision=tool_shed_repository.changeset_revision, - repository_clone_url=repository_clone_url, - shed_config_dict=shed_config_dict, - relative_install_dir=relative_install_dir, - repository_files_dir=None, - resetting_all_metadata_on_repository=False, - updating_installed_repository=False, - persist=True ) + metadata_dict, invalid_file_tups = metadata_util.generate_metadata_for_changeset_revision( app=trans.app, + repository=tool_shed_repository, + changeset_revision=tool_shed_repository.changeset_revision, + repository_clone_url=repository_clone_url, + shed_config_dict=shed_config_dict, + relative_install_dir=relative_install_dir, + repository_files_dir=None, + resetting_all_metadata_on_repository=False, + updating_installed_repository=False, + persist=True ) tool_shed_repository.metadata = metadata_dict trans.sa_session.add( tool_shed_repository ) trans.sa_session.flush() @@ -1462,7 +1463,7 @@ @web.require_admin def reset_metadata_on_selected_installed_repositories( self, trans, **kwd ): if 'reset_metadata_on_selected_repositories_button' in kwd: - message, status = suc.reset_metadata_on_selected_repositories( trans, **kwd ) + message, status = metadata_util.reset_metadata_on_selected_repositories( trans, **kwd ) else: message = util.restore_text( kwd.get( 'message', '' ) ) status = kwd.get( 'status', 'done' ) @@ -1482,16 +1483,16 @@ tool_path, relative_install_dir = repository.get_tool_relative_path( trans.app ) if relative_install_dir: original_metadata_dict = repository.metadata - metadata_dict, invalid_file_tups = suc.generate_metadata_for_changeset_revision( app=trans.app, - repository=repository, - changeset_revision=repository.changeset_revision, - repository_clone_url=repository_clone_url, - shed_config_dict = repository.get_shed_config_dict( trans.app ), - relative_install_dir=relative_install_dir, - repository_files_dir=None, - resetting_all_metadata_on_repository=False, - updating_installed_repository=False, - persist=False ) + metadata_dict, invalid_file_tups = metadata_util.generate_metadata_for_changeset_revision( app=trans.app, + repository=repository, + changeset_revision=repository.changeset_revision, + repository_clone_url=repository_clone_url, + shed_config_dict = repository.get_shed_config_dict( trans.app ), + relative_install_dir=relative_install_dir, + repository_files_dir=None, + resetting_all_metadata_on_repository=False, + updating_installed_repository=False, + persist=False ) repository.metadata = metadata_dict if metadata_dict != original_metadata_dict: suc.update_in_shed_tool_config( trans.app, repository ) @@ -1687,16 +1688,16 @@ if repository.includes_data_managers: shed_util.remove_from_data_manager( trans.app, repository ) # Update the repository metadata. - metadata_dict, invalid_file_tups = suc.generate_metadata_for_changeset_revision( app=trans.app, - repository=repository, - changeset_revision=latest_changeset_revision, - repository_clone_url=repository_clone_url, - shed_config_dict = repository.get_shed_config_dict( trans.app ), - relative_install_dir=relative_install_dir, - repository_files_dir=None, - resetting_all_metadata_on_repository=False, - updating_installed_repository=True, - persist=True ) + metadata_dict, invalid_file_tups = metadata_util.generate_metadata_for_changeset_revision( app=trans.app, + repository=repository, + changeset_revision=latest_changeset_revision, + repository_clone_url=repository_clone_url, + shed_config_dict = repository.get_shed_config_dict( trans.app ), + relative_install_dir=relative_install_dir, + repository_files_dir=None, + resetting_all_metadata_on_repository=False, + updating_installed_repository=True, + persist=True ) repository.metadata = metadata_dict # Update the repository changeset_revision in the database. repository.changeset_revision = latest_changeset_revision diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 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 @@ -3,6 +3,7 @@ from galaxy.web.base.controllers.admin import Admin from galaxy.util import inflector import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util import tool_shed.grids.admin_grids as admin_grids from galaxy import eggs @@ -301,7 +302,7 @@ @web.require_admin def reset_metadata_on_selected_repositories_in_tool_shed( self, trans, **kwd ): if 'reset_metadata_on_selected_repositories_button' in kwd: - message, status = suc.reset_metadata_on_selected_repositories( trans, **kwd ) + message, status = metadata_util.reset_metadata_on_selected_repositories( trans, **kwd ) else: message = util.restore_text( kwd.get( 'message', '' ) ) status = kwd.get( 'status', 'done' ) diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 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 @@ -1,7 +1,8 @@ import os, logging from galaxy import web from galaxy.web.base.controller import BaseUIController -from tool_shed.util.shed_util_common import get_repository_by_name_and_owner, set_repository_metadata +from tool_shed.util.shed_util_common import get_repository_by_name_and_owner +from tool_shed.util.metadata_util import set_repository_metadata from galaxy import eggs eggs.require('mercurial') diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 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 @@ -11,6 +11,7 @@ from galaxy.util import json from galaxy.model.orm import and_, or_ import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util from tool_shed.util import encoding_util from galaxy.webapps.tool_shed.util import workflow_util from galaxy.webapps.tool_shed.util import common_util @@ -365,7 +366,7 @@ operation = kwd[ 'operation' ].lower() if operation == "preview_tools_in_changeset": repository = suc.get_repository_in_tool_shed( trans, repository_id ) - repository_metadata = suc.get_latest_repository_metadata( trans, repository.id ) + repository_metadata = metadata_util.get_latest_repository_metadata( trans, repository.id ) latest_installable_changeset_revision = repository_metadata.changeset_revision return trans.response.send_redirect( web.url_for( controller='repository', action='preview_tools_in_changeset', @@ -1914,7 +1915,7 @@ def reset_all_metadata( self, trans, id, **kwd ): # This method is called only from the ~/templates/webapps/tool_shed/repository/manage_repository.mako template. # It resets all metadata on the complete changelog for a single repository in the tool shed. - invalid_file_tups, metadata_dict = suc.reset_all_metadata_on_repository_in_tool_shed( trans, id, **kwd ) + invalid_file_tups, metadata_dict = metadata_util.reset_all_metadata_on_repository_in_tool_shed( trans, id, **kwd ) if invalid_file_tups: repository = suc.get_repository_in_tool_shed( trans, id ) message = suc.generate_message_for_invalid_tools( trans, invalid_file_tups, repository, metadata_dict ) @@ -2082,7 +2083,7 @@ else: message += 'The selected files were deleted from the repository. ' kwd[ 'message' ] = message - suc.set_repository_metadata_due_to_new_tip( trans, repository, **kwd ) + metadata_util.set_repository_metadata_due_to_new_tip( trans, repository, **kwd ) else: message = "Select at least 1 file to delete from the repository before clicking <b>Delete selected files</b>." status = "error" diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 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 @@ -3,6 +3,7 @@ from galaxy import web, util from galaxy.datatypes import checkers import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util from galaxy import eggs eggs.require('mercurial') @@ -15,6 +16,26 @@ CHUNK_SIZE = 2**20 # 1Mb class UploadController( BaseUIController ): + def check_file_contents_for_email_alerts( self, trans ): + """ + See if any admin users have chosen to receive email alerts when a repository is updated. If so, the file contents of the update must be + checked for inappropriate content. + """ + admin_users = trans.app.config.get( "admin_users", "" ).split( "," ) + for repository in trans.sa_session.query( trans.model.Repository ) \ + .filter( trans.model.Repository.table.c.email_alerts != None ): + email_alerts = json.from_json_string( repository.email_alerts ) + for user_email in email_alerts: + if user_email in admin_users: + return True + return False + def check_file_content_for_html_and_images( self, file_path ): + message = '' + if checkers.check_html( file_path ): + message = 'The file "%s" contains HTML content.\n' % str( file_path ) + elif checkers.check_image( file_path ): + message = 'The file "%s" contains image content.\n' % str( file_path ) + return message @web.expose @web.require_login( 'upload', use_panels=True ) def upload( self, trans, **kwd ): @@ -120,9 +141,9 @@ shutil.move( uploaded_file_name, full_path ) # See if any admin users have chosen to receive email alerts when a repository is # updated. If so, check every uploaded file to ensure content is appropriate. - check_contents = suc.check_file_contents( trans ) + check_contents = self.check_file_contents_for_email_alerts( trans ) if check_contents and os.path.isfile( full_path ): - content_alert_str = self.__check_file_content( full_path ) + content_alert_str = self.check_file_content_for_html_and_images( full_path ) else: content_alert_str = '' commands.add( repo.ui, repo, full_path ) @@ -166,7 +187,7 @@ else: message += " %d files were removed from the repository root. " % len( files_to_remove ) kwd[ 'message' ] = message - suc.set_repository_metadata_due_to_new_tip( trans, repository, content_alert_str=content_alert_str, **kwd ) + metadata_util.set_repository_metadata_due_to_new_tip( trans, repository, content_alert_str=content_alert_str, **kwd ) if repository.metadata_revisions: # A repository's metadata revisions are order descending by update_time, so the zeroth revision will be the tip just after an upload. metadata_dict = repository.metadata_revisions[0].metadata @@ -330,11 +351,11 @@ pass # See if any admin users have chosen to receive email alerts when a repository is # updated. If so, check every uploaded file to ensure content is appropriate. - check_contents = suc.check_file_contents( trans ) + check_contents = self.check_file_contents_for_email_alerts( trans ) for filename_in_archive in filenames_in_archive: # Check file content to ensure it is appropriate. if check_contents and os.path.isfile( filename_in_archive ): - content_alert_str += self.__check_file_content( filename_in_archive ) + content_alert_str += self.check_file_content_for_html_and_images( filename_in_archive ) commands.add( repo.ui, repo, filename_in_archive ) if filename_in_archive.endswith( 'tool_data_table_conf.xml.sample' ): # Handle the special case where a tool_data_table_conf.xml.sample file is being uploaded by parsing the file and adding new entries @@ -421,10 +442,3 @@ message = "Uploaded archives cannot contain hgrc files." return False, message return True, '' - def __check_file_content( self, file_path ): - message = '' - if checkers.check_html( file_path ): - message = 'The file "%s" contains HTML content.\n' % str( file_path ) - elif checkers.check_image( file_path ): - message = 'The file "%s" contains image content.\n' % str( file_path ) - return message diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 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 @@ -8,6 +8,7 @@ from galaxy.util.json import from_json_string, to_json_string import tool_shed.util.shed_util as shed_util import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util from galaxy.util.odict import odict from tool_shed.util import common_util @@ -179,16 +180,16 @@ else: print 'The tool "%s" (%s) has not been enabled because it is not defined in a proprietary tool config (%s).' \ % ( guid, tool_config, ", ".join( self.proprietary_tool_confs or [] ) ) - metadata_dict, invalid_file_tups = suc.generate_metadata_for_changeset_revision( app=self.app, - repository=tool_shed_repository, - changeset_revision=tool_shed_repository.changeset_revision, - repository_clone_url=repository_clone_url, - shed_config_dict = self.shed_config_dict, - relative_install_dir=relative_install_dir, - repository_files_dir=None, - resetting_all_metadata_on_repository=False, - updating_installed_repository=False, - persist=True ) + metadata_dict, invalid_file_tups = metadata_util.generate_metadata_for_changeset_revision( app=self.app, + repository=tool_shed_repository, + changeset_revision=tool_shed_repository.changeset_revision, + repository_clone_url=repository_clone_url, + shed_config_dict = self.shed_config_dict, + relative_install_dir=relative_install_dir, + repository_files_dir=None, + resetting_all_metadata_on_repository=False, + updating_installed_repository=False, + persist=True ) tool_shed_repository.metadata = metadata_dict self.app.sa_session.add( tool_shed_repository ) self.app.sa_session.flush() diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 lib/tool_shed/galaxy_install/repository_util.py --- a/lib/tool_shed/galaxy_install/repository_util.py +++ b/lib/tool_shed/galaxy_install/repository_util.py @@ -1,5 +1,6 @@ import tool_shed.util.shed_util as shed_util import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util def handle_repository_contents( app, tool_shed_repository, tool_path, repository_clone_url, relative_install_dir, tool_shed=None, tool_section=None, shed_tool_conf=None, reinstalling=False ): @@ -9,16 +10,16 @@ """ sa_session = app.model.context.current shed_config_dict = app.toolbox.get_shed_config_dict_by_filename( shed_tool_conf ) - metadata_dict, invalid_file_tups = suc.generate_metadata_for_changeset_revision( app=app, - repository=tool_shed_repository, - changeset_revision=tool_shed_repository.changeset_revision, - repository_clone_url=repository_clone_url, - shed_config_dict=shed_config_dict, - relative_install_dir=relative_install_dir, - repository_files_dir=None, - resetting_all_metadata_on_repository=False, - updating_installed_repository=False, - persist=True ) + metadata_dict, invalid_file_tups = metadata_util.generate_metadata_for_changeset_revision( app=app, + repository=tool_shed_repository, + changeset_revision=tool_shed_repository.changeset_revision, + repository_clone_url=repository_clone_url, + shed_config_dict=shed_config_dict, + relative_install_dir=relative_install_dir, + repository_files_dir=None, + resetting_all_metadata_on_repository=False, + updating_installed_repository=False, + persist=True ) tool_shed_repository.metadata = metadata_dict sa_session.add( tool_shed_repository ) sa_session.flush() diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 lib/tool_shed/grids/repository_review_grids.py --- a/lib/tool_shed/grids/repository_review_grids.py +++ b/lib/tool_shed/grids/repository_review_grids.py @@ -4,6 +4,7 @@ from galaxy.model.orm import and_, or_ from tool_shed.grids.repository_grids import RepositoryGrid import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util from galaxy import eggs eggs.require('mercurial') @@ -76,9 +77,9 @@ if repository_metadata_revisions: rval = '' for repository_metadata in repository_metadata_revisions: - rev, label, changeset_revision = suc.get_rev_label_changeset_revision_from_repository_metadata( trans, - repository_metadata, - repository=repository ) + rev, label, changeset_revision = metadata_util.get_rev_label_changeset_revision_from_repository_metadata( trans, + repository_metadata, + repository=repository ) rval += '<a href="manage_repository_reviews_of_revision?id=%s&changeset_revision=%s">%s</a><br/>' % \ ( trans.security.encode_id( repository.id ), changeset_revision, label ) return rval diff -r 185a0ed00d8f245aa4ec161ba134df38edf19f70 -r 4827bed265e7563c58346654f5a668f5de6d9d68 lib/tool_shed/grids/util.py --- a/lib/tool_shed/grids/util.py +++ b/lib/tool_shed/grids/util.py @@ -1,5 +1,6 @@ import os, logging import tool_shed.util.shed_util_common as suc +import tool_shed.util.metadata_util as metadata_util from galaxy.web.form_builder import SelectField def build_approved_select_field( trans, name, selected_value=None, for_component=True ): @@ -43,7 +44,7 @@ # Restrict the options to all revisions that have associated metadata. repository_metadata_revisions = repository.metadata_revisions for repository_metadata in repository_metadata_revisions: - rev, label, changeset_revision = suc.get_rev_label_changeset_revision_from_repository_metadata( trans, repository_metadata, repository=repository ) + rev, label, changeset_revision = metadata_util.get_rev_label_changeset_revision_from_repository_metadata( trans, repository_metadata, repository=repository ) changeset_tups.append( ( rev, label, changeset_revision ) ) refresh_on_change_values.append( changeset_revision ) # Sort options by the revision label. Even though the downloadable_revisions query sorts by update_time, This diff is so big that we needed to truncate the remainder. Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org