From 0e60332f449609a43a49b7d33ec64bf53663befd Mon Sep 17 00:00:00 2001 From: Eric Rasche Date: Thu, 29 Oct 2015 22:02:34 -0500 Subject: [PATCH] Replace remaining print statements with log.* --- lib/galaxy/app.py | 2 +- lib/galaxy/config.py | 2 +- lib/galaxy/model/__init__.py | 2 +- lib/galaxy/util/__init__.py | 4 ++-- .../webapps/galaxy/api/library_contents.py | 2 +- .../galaxy/controllers/requests_common.py | 8 +++---- lib/galaxy/webapps/reports/app.py | 4 +++- lib/galaxy/webapps/tool_shed/app.py | 7 ++++-- .../tool_shed/framework/middleware/hg.py | 2 +- .../repository_dependency_manager.py | 2 +- .../tool_dependencies/recipe/tag_handler.py | 6 ++--- .../galaxy_install/tool_migration_manager.py | 24 ++++++++++--------- lib/tool_shed/util/common_util.py | 4 ++-- lib/tool_shed/util/hg_util.py | 2 +- 14 files changed, 39 insertions(+), 32 deletions(-) diff --git a/lib/galaxy/app.py b/lib/galaxy/app.py index 70309deecd3e..f721f1cb007b 100644 --- a/lib/galaxy/app.py +++ b/lib/galaxy/app.py @@ -30,7 +30,7 @@ class UniverseApplication( object, config.ConfiguresGalaxyMixin ): """Encapsulates the state of a Universe application""" def __init__( self, **kwargs ): - print >> sys.stderr, "python path is: " + ", ".join( sys.path ) + log.debug( "python path is: %s", ", ".join( sys.path ) ) self.name = 'galaxy' self.new_installation = False # Read config file and check for errors diff --git a/lib/galaxy/config.py b/lib/galaxy/config.py index 2955d7fa0ad4..95457d21b255 100644 --- a/lib/galaxy/config.py +++ b/lib/galaxy/config.py @@ -201,7 +201,7 @@ def __init__( self, **kwargs ): with open( self.blacklist_file ) as blacklist: self.blacklist_content = [ line.rstrip() for line in blacklist.readlines() ] except IOError: - print ( "CONFIGURATION ERROR: Can't open supplied blacklist file from path: " + str( self.blacklist_file ) ) + log.error( "CONFIGURATION ERROR: Can't open supplied blacklist file from path: " + str( self.blacklist_file ) ) self.smtp_server = kwargs.get( 'smtp_server', None ) self.smtp_username = kwargs.get( 'smtp_username', None ) self.smtp_password = kwargs.get( 'smtp_password', None ) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 7a48740c9adc..f18661364a83 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2927,7 +2927,7 @@ def clear( self, purge=False, delete_dataset=True ): try: os.unlink( self.file_name ) except Exception, e: - print "Failed to purge associated file (%s) from disk: %s" % ( self.file_name, e ) + log.error( "Failed to purge associated file (%s) from disk: %s" % ( self.file_name, e ) ) DEFAULT_COLLECTION_NAME = "Unnamed Collection" diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index e04c973f07c5..da458dfa0461 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -950,7 +950,7 @@ class DBNames( list ): man_builds = [(build, name) for name, build in man_builds] db_names = DBNames( db_names + man_builds ) except Exception, e: - print "ERROR: Unable to read builds file:", e + log.error( "ERROR: Unable to read builds file: %s", str( e ) ) if len(db_names) < 1: db_names = DBNames( [( db_names.default_value, db_names.default_name )] ) return db_names @@ -976,7 +976,7 @@ def read_build_sites( filename, check_builds=True ): except: continue except: - print "ERROR: Unable to read builds for site file %s" % filename + log.error( "ERROR: Unable to read builds for site file %s", filename ) return build_sites diff --git a/lib/galaxy/webapps/galaxy/api/library_contents.py b/lib/galaxy/webapps/galaxy/api/library_contents.py index d0e05dd8c155..f7c5f84ef498 100644 --- a/lib/galaxy/webapps/galaxy/api/library_contents.py +++ b/lib/galaxy/webapps/galaxy/api/library_contents.py @@ -400,7 +400,7 @@ def delete( self, trans, library_id, id, **kwd ): ld = self.get_library_dataset( trans, id, check_ownership=False, check_accessible=True ) user_is_admin = trans.user_is_admin() can_modify = trans.app.security_agent.can_modify_library_item( trans.user.all_roles(), ld ) - print 'is_admin: %s, can_modify: %s' % ( user_is_admin, can_modify ) + log.debug( 'is_admin: %s, can_modify: %s', user_is_admin, can_modify ) if not ( user_is_admin or can_modify ): trans.response.status = 403 rval.update({ 'error': 'Unauthorized to delete or purge this library dataset' }) diff --git a/lib/galaxy/webapps/galaxy/controllers/requests_common.py b/lib/galaxy/webapps/galaxy/controllers/requests_common.py index 875dd07d1322..9848a070df1a 100644 --- a/lib/galaxy/webapps/galaxy/controllers/requests_common.py +++ b/lib/galaxy/webapps/galaxy/controllers/requests_common.py @@ -1212,8 +1212,8 @@ def __save_samples( self, trans, cntrller, request, sample_widgets, saving_new_s redirect_action = 'edit_samples' # Check for duplicate sample names within the request self.__validate_sample_names( trans, cntrller, request, sample_widgets, **kwd ) - print "SAVING SAMPLES!" - print "saving_new_samples is %s" % saving_new_samples + log.debug( "SAVING SAMPLES!" ) + log.debug( "saving_new_samples is %s" % saving_new_samples ) if not saving_new_samples: library = None folder = None @@ -1874,8 +1874,8 @@ def __validate_request( self, trans, cntrller, request ): empty_sample_fields = [] for s in request.samples: for field in request.type.sample_form.fields: - print "field:", field - print "svc:", s.values.content + log.debug("field: %s", field) + log.debug("svc: %s", s.values.content) if field['required'] == 'required' and s.values.content[field['name']] in ['', None]: empty_sample_fields.append((s.name, field['label'])) if empty_fields or empty_sample_fields: diff --git a/lib/galaxy/webapps/reports/app.py b/lib/galaxy/webapps/reports/app.py index 59352640cb86..747614465883 100644 --- a/lib/galaxy/webapps/reports/app.py +++ b/lib/galaxy/webapps/reports/app.py @@ -4,12 +4,14 @@ import galaxy.model from galaxy.web import security +import logging +log = logging.getLogger( __name__ ) class UniverseApplication( object ): """Encapsulates the state of a Universe application""" def __init__( self, **kwargs ): - print >> sys.stderr, "python path is: " + ", ".join( sys.path ) + log.debug( "python path is: %s", ", ".join( sys.path ) ) self.name = "reports" # Read config file and check for errors self.config = config.Configuration( **kwargs ) diff --git a/lib/galaxy/webapps/tool_shed/app.py b/lib/galaxy/webapps/tool_shed/app.py index 0c2abbf37314..2261e22875b7 100644 --- a/lib/galaxy/webapps/tool_shed/app.py +++ b/lib/galaxy/webapps/tool_shed/app.py @@ -13,13 +13,16 @@ import tool_shed.repository_registry import tool_shed.repository_types.registry from tool_shed.grids.repository_grid_filter_manager import RepositoryGridFilterManager +import logging +log = logging.getLogger( __name__ ) + class UniverseApplication( object ): """Encapsulates the state of a Universe application""" def __init__( self, **kwd ): - print >> sys.stderr, "python path is: " + ", ".join( sys.path ) + log.debug( "python path is: %s", ", ".join( sys.path ) ) self.name = "tool_shed" # Read the tool_shed.ini configuration file and check for errors. self.config = config.Configuration( **kwd ) @@ -75,7 +78,7 @@ def __init__( self, **kwd ): self.repository_registry = tool_shed.repository_registry.Registry( self ) # used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base. self.server_starttime = int(time.time()) - print >> sys.stderr, "Tool shed hgweb.config file is: ", self.hgweb_config_manager.hgweb_config + log.debug( "Tool shed hgweb.config file is: %s", self.hgweb_config_manager.hgweb_config ) def shutdown( self ): pass diff --git a/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py b/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py index 08f204c37e2e..cdc1aa56cb20 100644 --- a/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py +++ b/lib/galaxy/webapps/tool_shed/framework/middleware/hg.py @@ -25,7 +25,7 @@ class Hg( object ): def __init__( self, app, config ): - print "mercurial version is:", mercurial.__version__.version + log.debug( "mercurial version is: %s", mercurial.__version__.version ) self.app = app self.config = config # Authenticate this mercurial request using basic authentication diff --git a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py index 6aa8abe73428..04345cad9a43 100644 --- a/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py +++ b/lib/tool_shed/galaxy_install/repository_dependencies/repository_dependency_manager.py @@ -293,7 +293,7 @@ def get_repository_dependencies_for_installed_tool_shed_repository( self, app, r try: raw_text = common_util.tool_shed_get( app, tool_shed_url, pathspec=pathspec, params=params ) except Exception, e: - print "The URL\n%s\nraised the exception:\n%s\n" % ( common_util.url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) ) + log.error("The URL\n%s\nraised the exception:\n%s\n", common_util.url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) ) return '' if len( raw_text ) > 2: encoded_text = json.loads( raw_text ) diff --git a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py index cb0b0cc9438b..21f33e04b172 100644 --- a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py @@ -96,7 +96,7 @@ def sync_database_with_file_system( self, app, tool_shed_repository, tool_depend str( basic_util.INSTALLATION_LOG ) ) error_message += ' is missing. This indicates an installation error so the tool dependency is being' error_message += ' prepared for re-installation.' - print error_message + log.error( error_message ) tool_dependency.status = app.install_model.ToolDependency.installation_status.NEVER_INSTALLED basic_util.remove_dir( tool_dependency_install_dir ) can_install_tool_dependency = True @@ -464,7 +464,7 @@ def handle_complex_repository_dependency_for_package( self, elem, package_name, # required_repository. if required_repository.is_deactivated_or_installed: if not os.path.exists( required_repository_package_install_dir ): - print 'Missing required tool dependency directory %s' % str( required_repository_package_install_dir ) + log.error( 'Missing required tool dependency directory %s' % str( required_repository_package_install_dir ) ) repo_files_dir = required_repository.repo_files_directory( self.app ) tool_dependencies_config = suc.get_absolute_path_to_file_in_repository( repo_files_dir, 'tool_dependencies.xml' ) if tool_dependencies_config: @@ -518,7 +518,7 @@ def process_tag_set( self, tool_shed_repository, tool_dependency, package_elem, for rd_tool_dependency in rd_tool_dependencies: if rd_tool_dependency.status == self.app.install_model.ToolDependency.installation_status.ERROR: # We'll log the error here, but continue installing packages since some may not require this dependency. - print "Error installing tool dependency for required repository: %s" % str( rd_tool_dependency.error_message ) + log.error( "Error installing tool dependency for required repository: %s" % str( rd_tool_dependency.error_message ) ) return tool_dependency, proceed_with_install, action_elem_tuples def remove_file( self, file_name ): diff --git a/lib/tool_shed/galaxy_install/tool_migration_manager.py b/lib/tool_shed/galaxy_install/tool_migration_manager.py index 1b1c985ad578..c936f06b7d82 100644 --- a/lib/tool_shed/galaxy_install/tool_migration_manager.py +++ b/lib/tool_shed/galaxy_install/tool_migration_manager.py @@ -62,16 +62,16 @@ def __init__( self, app, latest_migration_script_number, tool_shed_install_confi # setting from migrated_tools_config. tree, error_message = xml_util.parse_xml( migrated_tools_config ) if tree is None: - print error_message + log.error( error_message ) else: root = tree.getroot() self.tool_path = root.get( 'tool_path' ) - print "Repositories will be installed into configured tool_path location ", str( self.tool_path ) + log.debug( "Repositories will be installed into configured tool_path location ", str( self.tool_path ) ) # Parse tool_shed_install_config to check each of the tools. self.tool_shed_install_config = tool_shed_install_config tree, error_message = xml_util.parse_xml( tool_shed_install_config ) if tree is None: - print error_message + log.error( error_message ) else: root = tree.getroot() defined_tool_shed_url = root.get( 'name' ) @@ -157,12 +157,12 @@ def __init__( self, app, latest_migration_script_number, tool_shed_install_confi str( latest_migration_script_number ) message += "file%s named %s,\nso no repositories will be installed on disk.\n" % \ ( plural, file_names ) - print message + log.info( message ) else: 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 + log.error( message ) def create_or_update_tool_shed_repository_record( self, name, owner, changeset_revision, description=None ): @@ -403,8 +403,8 @@ def handle_repository_contents( self, tool_shed_repository, repository_clone_url if tool_config not in tool_configs_to_filter: tool_configs_to_filter.append( tool_config ) 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 [] ) ) + log.error( '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 [] ) ) ) if tool_configs_to_filter: lock = threading.Lock() lock.acquire( True ) @@ -489,8 +489,9 @@ def handle_repository_contents( self, tool_shed_repository, repository_clone_url from_tool_migration_manager=True ) for installed_tool_dependency in installed_tool_dependencies: if installed_tool_dependency.status == self.app.install_model.ToolDependency.installation_status.ERROR: - print '\nThe ToolMigrationManager returned the following error while installing tool dependency ', installed_tool_dependency.name, ':' - print installed_tool_dependency.error_message, '\n\n' + log.error( + 'The ToolMigrationManager returned the following error while installing tool dependency %s: %s', + installed_tool_dependency.name, installed_tool_dependency.error_message ) if 'datatypes' in irmm_metadata_dict: cdl = custom_datatype_manager.CustomDatatypeLoader( self.app ) tool_shed_repository.status = self.app.install_model.ToolShedRepository.installation_status.LOADING_PROPRIETARY_DATATYPES @@ -544,7 +545,8 @@ def install_repository( self, repository_elem, tool_shed_repository, install_dep self.app.install_model.ToolShedRepository.installation_status.DEACTIVATED ]: is_installed = True if cloned_ok and is_installed: - print "Skipping automatic install of repository '", tool_shed_repository.name, "' because it has already been installed in location ", clone_dir + log.info( "Skipping automatic install of repository '%s' because it has already been installed in location %s", + tool_shed_repository.name, clone_dir ) else: irm = install_manager.InstallRepositoryManager( self.app, self.tpm ) repository_clone_url = os.path.join( self.tool_shed_url, 'repos', tool_shed_repository.owner, tool_shed_repository.name ) @@ -614,7 +616,7 @@ def install_repository( self, repository_elem, tool_shed_repository, install_dep irm.update_tool_shed_repository_status( tool_shed_repository, self.app.install_model.ToolShedRepository.installation_status.INSTALLED ) else: - print 'Error attempting to clone repository %s: %s' % ( str( tool_shed_repository.name ), str( error_message ) ) + log.error('Error attempting to clone repository %s: %s', str( tool_shed_repository.name ), str( error_message ) ) irm.update_tool_shed_repository_status( tool_shed_repository, self.app.install_model.ToolShedRepository.installation_status.ERROR, error_message=error_message ) diff --git a/lib/tool_shed/util/common_util.py b/lib/tool_shed/util/common_util.py index 63a778891c19..273311e7d3a2 100644 --- a/lib/tool_shed/util/common_util.py +++ b/lib/tool_shed/util/common_util.py @@ -163,7 +163,7 @@ def get_repository_dependencies( app, tool_shed_url, repository_name, repository tool_shed_accessible = True except Exception, e: tool_shed_accessible = False - print "The URL\n%s\nraised the exception:\n%s\n" % ( url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) ) + log.warn( "The URL\n%s\nraised the exception:\n%s\n" % ( url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) ) ) if tool_shed_accessible: if len( raw_text ) > 2: encoded_text = json.loads( raw_text ) @@ -195,7 +195,7 @@ def get_tool_dependencies( app, tool_shed_url, repository_name, repository_owner tool_shed_accessible = True except Exception, e: tool_shed_accessible = False - print "The URL\n%s\nraised the exception:\n%s\n" % ( url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) ) + log.warn( "The URL\n%s\nraised the exception:\n%s\n" % ( url_join( tool_shed_url, pathspec=pathspec, params=params ), str( e ) ) ) if tool_shed_accessible: if text: tool_dependencies_dict = encoding_util.tool_shed_decode( text ) diff --git a/lib/tool_shed/util/hg_util.py b/lib/tool_shed/util/hg_util.py index 64ca1cfb1e61..ac01ca7c2477 100644 --- a/lib/tool_shed/util/hg_util.py +++ b/lib/tool_shed/util/hg_util.py @@ -436,7 +436,7 @@ def unpack_patches( hg_unbundle10_obj, remaining ): 'blocklen': blocklen, 'block': block.encode( 'string_escape' ) } if remaining > 0: - print remaining + log.error("Unexpected end of patch stream, %s remaining", remaining) raise Exception( "unexpected end of patch stream" )