commit/galaxy-central: greg: Fixes for rendering certain tool shed repository content.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/20a25a4f989d/ changeset: 20a25a4f989d user: greg date: 2012-12-01 01:37:37 summary: Fixes for rendering certain tool shed repository content. affected #: 2 files diff -r 03ec137ca8a3148aa771769e80963b65194b7895 -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 lib/galaxy/util/shed_util.py --- a/lib/galaxy/util/shed_util.py +++ b/lib/galaxy/util/shed_util.py @@ -1064,19 +1064,6 @@ return removed, error_message def tool_shed_from_repository_clone_url( repository_clone_url ): return clean_repository_clone_url( repository_clone_url ).split( 'repos' )[ 0 ].rstrip( '/' ) -def translate_string( raw_text, to_html=True ): - if raw_text: - if to_html: - if len( raw_text ) <= MAX_CONTENT_SIZE: - translated_string = to_html_str( raw_text ) - else: - large_str = '\nFile contents truncated because file size is larger than maximum viewing size of %s\n' % util.nice_size( MAX_CONTENT_SIZE ) - translated_string = to_html_str( '%s%s' % ( raw_text[ 0:MAX_CONTENT_SIZE ], large_str ) ) - else: - raise Exception( "String translation currently only supports text to HTML." ) - else: - translated_string = '' - return translated_string def update_in_shed_tool_config( app, repository ): # A tool shed repository is being updated 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. diff -r 03ec137ca8a3148aa771769e80963b65194b7895 -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 lib/galaxy/util/shed_util_common.py --- a/lib/galaxy/util/shed_util_common.py +++ b/lib/galaxy/util/shed_util_common.py @@ -62,7 +62,7 @@ f = open( full_path_to_readme_file, 'r' ) text = f.read() f.close() - readme_files_dict[ readme_file_name ] = str( text ) + readme_files_dict[ readme_file_name ] = translate_string( text, to_html=False ) except Exception, e: log.debug( "Error reading README file '%s' defined in metadata for repository '%s', revision '%s': %s" % \ ( str( relative_path_to_readme_file ), str( repository_name ), str( changeset_revision ), str( e ) ) ) @@ -1155,22 +1155,22 @@ return all_repository_dependencies def get_repository_file_contents( file_path ): if is_gzip( file_path ): - to_html = to_html_str( '\ngzip compressed file\n' ) + safe_str = to_safe_str( '\ngzip compressed file\n' ) elif is_bz2( file_path ): - to_html = to_html_str( '\nbz2 compressed file\n' ) + safe_str = to_safe_str( '\nbz2 compressed file\n' ) elif check_zip( file_path ): - to_html = to_html_str( '\nzip compressed file\n' ) + safe_str = to_safe_str( '\nzip compressed file\n' ) elif check_binary( file_path ): - to_html = to_html_str( '\nBinary file\n' ) + safe_str = to_safe_str( '\nBinary file\n' ) else: - to_html = '' + safe_str = '' for i, line in enumerate( open( file_path ) ): - to_html = '%s%s' % ( to_html, to_html_str( line ) ) - if len( to_html ) > MAX_CONTENT_SIZE: + safe_str = '%s%s' % ( safe_str, to_safe_str( line ) ) + if len( safe_str ) > MAX_CONTENT_SIZE: large_str = '\nFile contents truncated because file size is larger than maximum viewing size of %s\n' % util.nice_size( MAX_CONTENT_SIZE ) - to_html = '%s%s' % ( to_html, to_html_str( large_str ) ) + safe_str = '%s%s' % ( safe_str, to_safe_str( large_str ) ) break - return to_html + return safe_str def get_repository_files( trans, folder_path ): contents = [] for item in os.listdir( folder_path ): @@ -1631,7 +1631,7 @@ except: file_name = fpath return file_name -def to_html_str( text ): +def to_safe_str( text, to_html=True ): """Translates the characters in text to an html string""" translated = [] for c in text: @@ -1639,17 +1639,28 @@ translated.append( c ) elif c in MAPPED_CHARS: translated.append( MAPPED_CHARS[ c ] ) - elif c == ' ': - translated.append( ' ' ) - elif c == '\t': - translated.append( ' ' ) - elif c == '\n': - translated.append( '<br/>' ) - elif c not in [ '\r' ]: + elif c in [ '\n', '\r' ]: + if to_html: + translated.append( '<br/>' ) + else: + translated.append( c ) + elif c in [ ' ', ' ' ]: + translated.append( c ) + else: translated.append( '' ) return ''.join( translated ) def tool_shed_is_this_tool_shed( toolshed_base_url ): return toolshed_base_url.rstrip( '/' ) == str( url_for( '/', qualified=True ) ).rstrip( '/' ) +def translate_string( raw_text, to_html=True ): + if raw_text: + if len( raw_text ) <= MAX_CONTENT_SIZE: + translated_string = to_safe_str( raw_text, to_html=to_html ) + else: + large_str = '\nFile contents truncated because file size is larger than maximum viewing size of %s\n' % util.nice_size( MAX_CONTENT_SIZE ) + translated_string = to_safe_str( '%s%s' % ( raw_text[ 0:MAX_CONTENT_SIZE ], large_str ), to_html=to_html ) + else: + translated_string = '' + return translated_string def update_existing_tool_dependency( app, repository, original_dependency_dict, new_dependencies_dict ): """ Update an exsiting tool dependency whose definition was updated in a change set pulled by a Galaxy administrator when getting updates 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)
-
Bitbucket