From 354d0447df4ca884b63a1666c3953be2bdcdf76b Mon Sep 17 00:00:00 2001 From: Greg Von Kuster Date: Fri, 20 Mar 2009 02:49:30 -0400 Subject: [PATCH] Fixes for i18n support - all charsets set to utf-8, now able to paste multi-byte chars in upload form, templates use utf-8 as output_charset, other miscellaneous fixes. --- lib/galaxy/datatypes/sniff.py | 3 +- lib/galaxy/tools/actions/upload.py | 30 +++++++-------- lib/galaxy/util/__init__.py | 4 +- lib/galaxy/web/controllers/ucsc_proxy.py | 2 +- lib/galaxy/web/framework/__init__.py | 13 +++++-- lib/galaxy/web/framework/base.py | 38 +++++++++---------- .../reports/templates/base_panels.mako | 2 +- .../webapps/reports/templates/masthead.mako | 2 +- scripts/paster.py | 1 - templates/base.mako | 2 +- templates/base_panels.mako | 2 +- templates/dataset/errors.tmpl | 2 +- templates/dataset/validation.tmpl | 2 +- templates/root/history.mako | 2 +- templates/root/masthead.mako | 2 +- templates/root/tool_menu.mako | 2 +- templates/tool_executed.mako | 2 +- templates/tool_form.mako | 2 +- .../workflow/build_from_current_history.mako | 2 +- tools/data_source/wormbase.xml | 2 +- tools/data_source/wormbase_test.xml | 2 +- 21 files changed, 60 insertions(+), 59 deletions(-) diff --git a/lib/galaxy/datatypes/sniff.py b/lib/galaxy/datatypes/sniff.py index da913abf86f..efc8a9d3a9b 100644 --- a/lib/galaxy/datatypes/sniff.py +++ b/lib/galaxy/datatypes/sniff.py @@ -21,7 +21,8 @@ def stream_to_file( stream, suffix='', prefix='', dir=None, text=False ): chunk = stream.read(1048576) if not chunk: break - os.write(fd, chunk) + # TODO: does this work on binary files? + os.write( fd, chunk.encode( "utf-8" ) ) os.close(fd) return temp_name diff --git a/lib/galaxy/tools/actions/upload.py b/lib/galaxy/tools/actions/upload.py index c093fa25794..9817c4da8d2 100644 --- a/lib/galaxy/tools/actions/upload.py +++ b/lib/galaxy/tools/actions/upload.py @@ -105,7 +105,7 @@ class UploadToolAction( object ): try: data_list.append( self.add_file( trans, temp_name, 'Pasted Entry', file_type, dbkey, info="pasted entry", space_to_tab=space_to_tab ) ) except Exception, e: - log.excception( 'exception in add_file using StringIO.StringIO( url_paste ) temp_name %s: %s' % ( str( temp_name ), str( e ) ) ) + log.exception( 'exception in add_file using StringIO.StringIO( url_paste ) temp_name %s: %s' % ( str( temp_name ), str( e ) ) ) self.remove_tempfile( temp_name ) return self.upload_empty( trans, job, "Error:", str( e ) ) else: @@ -146,12 +146,11 @@ class UploadToolAction( object ): def add_file( self, trans, temp_name, file_name, file_type, dbkey, info=None, space_to_tab=False ): data_type = None - # See if we have an empty file if not os.path.getsize( temp_name ) > 0: raise BadFileException( "you attempted to upload an empty file." ) - - # See if we have a gzipped file, which, if it passes our restrictions, we'll decompress on the fly. + # See if we have a gzipped file, which, if it passes our restrictions, + # we'll decompress on the fly. is_gzipped, is_valid = self.check_gzip( temp_name ) if is_gzipped and not is_valid: raise BadFileException( "you attempted to upload an inappropriate file." ) @@ -176,7 +175,7 @@ class UploadToolAction( object ): shutil.move( uncompressed, temp_name ) file_name = file_name.rstrip( '.gz' ) data_type = 'gzip' - + ext = '' if not data_type: # See if we have a zip archive is_zipped, is_valid, test_ext = self.check_zip( temp_name ) @@ -193,30 +192,28 @@ class UploadToolAction( object ): raise BadFileException( "you must manually set the 'File Format' to either 'Binseq.zip' or 'Txtseq.zip' when uploading zip files." ) data_type = 'zip' ext = file_type - if not data_type: if self.check_binary( temp_name ): - ext = file_name.split( "." )[1].strip().lower() - if not( ext == 'ab1' or ext == 'scf' ): - raise BadFileException( "you attempted to upload an inappropriate file." ) - if ext == 'ab1' and file_type != 'ab1': - raise BadFileException( "you must manually set the 'File Format' to 'Ab1' when uploading ab1 files." ) - elif ext == 'scf' and file_type != 'scf': - raise BadFileException( "you must manually set the 'File Format' to 'Scf' when uploading scf files." ) + parts = file_name.split( "." ) + if len( parts ) > 1: + ext = parts[1].strip().lower() + if not( ext == 'ab1' or ext == 'scf' ): + raise BadFileException( "you attempted to upload an inappropriate file." ) + if ext == 'ab1' and file_type != 'ab1': + raise BadFileException( "you must manually set the 'File Format' to 'Ab1' when uploading ab1 files." ) + elif ext == 'scf' and file_type != 'scf': + raise BadFileException( "you must manually set the 'File Format' to 'Scf' when uploading scf files." ) data_type = 'binary' - if not data_type: # We must have a text file if self.check_html( temp_name ): raise BadFileException( "you attempted to upload an inappropriate file." ) - if data_type != 'binary' and data_type != 'zip': if space_to_tab: self.line_count = sniff.convert_newlines_sep2tabs( temp_name ) else: self.line_count = sniff.convert_newlines( temp_name ) if file_type == 'auto': - log.debug("In upload, in if file_type == 'auto':") ext = sniff.guess_ext( temp_name, sniff_order=trans.app.datatypes_registry.sniff_order ) else: ext = file_type @@ -312,7 +309,6 @@ class UploadToolAction( object ): if chunk is None: temp.close() return False - def check_binary( self, temp_name, chunk=None ): if chunk is None: temp = open( temp_name, "U" ) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index cd0d1483270..13e121e7d62 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -107,9 +107,9 @@ def sanitize_text(text): def sanitize_param(value): """Clean incoming parameters (strings or lists)""" - if type(value) == type('x'): + if isinstance( value, basestring ): return sanitize_text(value) - elif type(value) == type([]): + elif isinstance( value, list ): return map(sanitize_text, value) else: raise Exception, 'Unknown parameter type' diff --git a/lib/galaxy/web/controllers/ucsc_proxy.py b/lib/galaxy/web/controllers/ucsc_proxy.py index 9ad6225fcfb..c95f67fdfc6 100644 --- a/lib/galaxy/web/controllers/ucsc_proxy.py +++ b/lib/galaxy/web/controllers/ucsc_proxy.py @@ -121,7 +121,7 @@ beginning = ''' Galaxy - + diff --git a/templates/root/history.mako b/templates/root/history.mako index 1f05b39cbb4..0f4cf21430b 100644 --- a/templates/root/history.mako +++ b/templates/root/history.mako @@ -11,7 +11,7 @@ %endif - + diff --git a/templates/root/masthead.mako b/templates/root/masthead.mako index c9a26e24b79..c2d66dc080c 100644 --- a/templates/root/masthead.mako +++ b/templates/root/masthead.mako @@ -5,7 +5,7 @@ Galaxy - + diff --git a/templates/root/tool_menu.mako b/templates/root/tool_menu.mako index d4385de800d..9e1fc8db854 100644 --- a/templates/root/tool_menu.mako +++ b/templates/root/tool_menu.mako @@ -49,7 +49,7 @@ ${_('Galaxy Tools')} - + diff --git a/templates/tool_executed.mako b/templates/tool_executed.mako index 9fd7ed1bc08..a241ce9d7c4 100644 --- a/templates/tool_executed.mako +++ b/templates/tool_executed.mako @@ -3,7 +3,7 @@ Galaxy - +