commit/galaxy-central: inithello: Clean up maintenance scripts for the EC2 environment.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/c4c6e8ea9837/ Changeset: c4c6e8ea9837 User: inithello Date: 2013-12-18 18:07:49 Summary: Clean up maintenance scripts for the EC2 environment. Affected #: 2 files diff -r 356e0b061fb4c0500db7faf11de8bf5edb2f9c41 -r c4c6e8ea9837d4aa4fbbf08a681fd0c72b34f5b6 lib/tool_shed/scripts/clean_up_tool_dependency_directory.py --- a/lib/tool_shed/scripts/clean_up_tool_dependency_directory.py +++ b/lib/tool_shed/scripts/clean_up_tool_dependency_directory.py @@ -4,55 +4,23 @@ import shutil def main( args ): - if not os.path.exists( args.basepath ): - print 'Tool dependency path %s does not exist.' % str( args.basepath ) - return 1 - if args.delete: - print 'Deleting contents of tool dependency path %s.' % args.basepath - for node in os.listdir( args.basepath ): - path = os.path.join( args.basepath, node ) - if os.path.isdir( path ): - try: - shutil.rmtree( path ) - print 'Deleted directory %s and all its contents.' % path - except Exception, e: - print 'Error deleting directory %s: %s' % ( path, str( e ) ) - pass - elif os.path.isfile( path ): - try: - os.remove( path ) - print 'Deleted file %s.' % path - except Exception, e: - print 'Error deleting file %s: %s' % ( path, str( e ) ) - pass - elif os.path.islink( path ): - print 'Deleting symlink %s with target %s.' % ( path, os.path.realpath( path ) ) - try: - os.remove( path ) - except Exception, e: - print 'Error deleting symlink %s: %s' % ( path, str( e ) ) - pass + if not os.path.exists( args.tool_dependency_dir ): + print 'Tool dependency base path %s does not exist, creating.' % str( args.tool_dependency_dir ) + os.mkdir( args.tool_dependency_dir ) + return 0 else: - print 'Tool dependency path %s contains the following files and directories:' % args.basepath - for element in os.listdir( args.basepath ): - print element - return 0 + for subdirectory in os.listdir( args.tool_dependency_dir ): + print 'Deleting directory %s from %s.' % ( subdirectory, args.tool_dependency_dir ) + shutil.rmtree( os.path.join( args.tool_dependency_dir, subdirectory ) ) if __name__ == '__main__': - description = 'Clean out or list the contents of the provided tool dependency path. Remove if ' - description += 'the --delete command line argument is provided.' + description = 'Clean out the configured tool dependency path, creating it if it does not exist.' parser = argparse.ArgumentParser( description=description ) - parser.add_argument( '--delete', - dest='delete', - required=False, - action='store_true', - default=False, - help='Whether to delete all folders and files or list them on exit.' ) - parser.add_argument( '--basepath', - dest='basepath', + parser.add_argument( '--tool_dependency_dir', + dest='tool_dependency_dir', required=True, action='store', metavar='name', - help='The base path where tool dependencies are installed.' ) + help='The base path where tool dependencies will be installed.' ) args = parser.parse_args() sys.exit( main( args ) ) diff -r 356e0b061fb4c0500db7faf11de8bf5edb2f9c41 -r c4c6e8ea9837d4aa4fbbf08a681fd0c72b34f5b6 lib/tool_shed/scripts/show_tool_dependency_installation_dir_contents.py --- /dev/null +++ b/lib/tool_shed/scripts/show_tool_dependency_installation_dir_contents.py @@ -0,0 +1,75 @@ +import argparse +import os +import sys + +new_path = [ os.path.join( os.getcwd(), "lib" ) ] +new_path.extend( sys.path[ 1: ] ) +sys.path = new_path + +from galaxy import eggs +eggs.require( "SQLAlchemy >= 0.4" ) + +import galaxy.model +import galaxy.model.tool_shed_install.mapping as install_mapper +import galaxy.config as galaxy_config + + +class CleanUpDependencyApplication( object ): + """Application that enables querying the database using the tool_shed_install model.""" + + def __init__( self, config ): + self.config = config + # Setup the database engine and ORM + self.model = install_mapper.init( self.config.database_connection, engine_options={}, create_tables=False ) + + @property + def sa_session( self ): + """Returns a SQLAlchemy session.""" + return self.model.context.current + + def shutdown( self ): + pass + +def main( args, app ): + if not os.path.exists( args.basepath ): + print 'Tool dependency base path %s does not exist.' % str( args.basepath ) + return + print 'Checking tool dependency path %s' % args.basepath + tool_dependency_dirs = get_tool_dependency_dirs( app ) + for tool_dependency_dir in tool_dependency_dirs: + path = os.path.join( args.basepath, tool_dependency_dir ) + if os.path.exists( path ): + path_contents = os.listdir( path ) + if len( path_contents ) > 0: + print 'Found non-empty tool dependency installation directory %s.' % path + print 'Directory has the following contents: \n %s' % '\n '.join( path_contents ) + +def get_tool_dependency_dirs( app ): + dependency_paths = [] + for tool_dependency in app.sa_session.query( galaxy.model.tool_shed_install.ToolDependency ).all(): + dependency_paths.append( tool_dependency.installation_directory( app ) ) + return dependency_paths + +if __name__ == '__main__': + description = 'Clean out or list the contents any tool dependency directory under the provided' + description += 'tool dependency path. Remove any non-empty directories found if the ' + description += '--delete command line argument is provided.' + parser = argparse.ArgumentParser( description=description ) + parser.add_argument( '--basepath', + dest='basepath', + required=True, + action='store', + metavar='name', + help='The base path where tool dependencies are installed.' ) + parser.add_argument( '--dburi', + dest='dburi', + required=True, + action='store', + metavar='dburi', + help='The database URI to connect to.' ) + args = parser.parse_args() + database_connection = args.dburi + config_dict = dict( database_connection=database_connection, tool_dependency_dir=args.basepath ) + config = galaxy_config.Configuration( **config_dict ) + app = CleanUpDependencyApplication( config ) + sys.exit( main( args, app ) ) 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