diff --git a/lib/galaxy/datatypes/coverage.py b/lib/galaxy/datatypes/coverage.py index f224188df5e..1d35c92ce4a 100644 --- a/lib/galaxy/datatypes/coverage.py +++ b/lib/galaxy/datatypes/coverage.py @@ -5,7 +5,7 @@ Coverage datatypes import pkg_resources pkg_resources.require( "bx-python" ) -import logging, os, sys, time, sets, tempfile, shutil +import logging, os, sys, time, tempfile, shutil import data from galaxy import util from galaxy.datatypes.sniff import * diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index 266774e1165..6a15e8731b8 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -1,4 +1,4 @@ -import logging, os, sys, time, sets, tempfile +import logging, os, sys, time, tempfile from galaxy import util from galaxy.util.odict import odict from galaxy.util.bunch import Bunch diff --git a/lib/galaxy/datatypes/genetics.py b/lib/galaxy/datatypes/genetics.py index 55f37b32d75..f199baf3d94 100644 --- a/lib/galaxy/datatypes/genetics.py +++ b/lib/galaxy/datatypes/genetics.py @@ -12,7 +12,7 @@ ross lazarus for rgenetics august 20 2007 """ -import logging, os, sys, time, sets, tempfile, shutil +import logging, os, sys, time, tempfile, shutil import data from galaxy import util from cgi import escape diff --git a/lib/galaxy/datatypes/interval.py b/lib/galaxy/datatypes/interval.py index 934c189f588..daa29575165 100644 --- a/lib/galaxy/datatypes/interval.py +++ b/lib/galaxy/datatypes/interval.py @@ -5,7 +5,7 @@ Interval datatypes import pkg_resources pkg_resources.require( "bx-python" ) -import logging, os, sys, time, sets, tempfile, shutil +import logging, os, sys, time, tempfile, shutil import data from galaxy import util from galaxy.datatypes.sniff import * diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index d1297fac4bb..fe3bddc71b1 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -5,8 +5,7 @@ Naming: try to use class names that have a distinct plural form so that the relationship cardinalities are obvious (e.g. prefer Dataset to Data) """ -import os.path, os, errno -import sha +import os.path, os, errno, sys import galaxy.datatypes from galaxy.util.bunch import Bunch from galaxy import util @@ -14,8 +13,11 @@ import tempfile import galaxy.datatypes.registry from galaxy.datatypes.metadata import MetadataCollection from galaxy.security import RBACAgent, get_permitted_actions - - +using_24 = sys.version_info[:2] < ( 2, 5 ) +if using_24: + import sha +else: + import hashlib import logging log = logging.getLogger( __name__ ) @@ -40,10 +42,16 @@ class User( object ): def set_password_cleartext( self, cleartext ): """Set 'self.password' to the digest of 'cleartext'.""" - self.password = sha.new( cleartext ).hexdigest() + if using_24: + self.password = sha.new( cleartext ).hexdigest() + else: + self.password = hashlib.sha1( cleartext ).hexdigest() def check_password( self, cleartext ): """Check if 'cleartext' matches 'self.password' when hashed.""" - return self.password == sha.new( cleartext ).hexdigest() + if using_24: + return self.password == sha.new( cleartext ).hexdigest() + else: + return self.password == hashlib.sha1( cleartext ).hexdigest() def all_roles( self ): roles = [ ura.role for ura in self.roles ] for group in [ uga.group for uga in self.groups ]: diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index d7d5f9cbe35..49f9d39deaa 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -1,15 +1,13 @@ """ Classes encapsulating galaxy tools and tool configuration. """ - import pkg_resources; pkg_resources.require( "simplejson" ) import logging, os, string, sys, tempfile, glob, shutil import simplejson -import sha, hmac, binascii - +import hmac, binascii from UserDict import DictMixin from galaxy.util.odict import odict from galaxy.util.bunch import Bunch @@ -27,6 +25,12 @@ from galaxy.util.none_like import NoneDataset from galaxy.datatypes import sniff from cgi import FieldStorage +using_24 = sys.version_info[:2] < ( 2, 5 ) +if using_24: + import sha +else: + import hashlib + log = logging.getLogger( __name__ ) class ToolNotFoundException( Exception ): @@ -211,7 +215,10 @@ class DefaultToolState( object ): value["__page__"] = self.page value = simplejson.dumps( value ) # Make it secure - a = hmac.new( app.config.tool_secret, value, sha ).hexdigest() + if using_24: + a = hmac.new( app.config.tool_secret, value, sha ).hexdigest() + else: + a = hmac.new( app.config.tool_secret, value, hashlib.sha1 ).hexdigest() b = binascii.hexlify( value ) return "%s:%s" % ( a, b ) def decode( self, value, tool, app ): @@ -221,7 +228,10 @@ class DefaultToolState( object ): # Extract and verify hash a, b = value.split( ":" ) value = binascii.unhexlify( b ) - test = hmac.new( app.config.tool_secret, value, sha ).hexdigest() + if using_24: + test = hmac.new( app.config.tool_secret, value, sha ).hexdigest() + else: + test = hmac.new( app.config.tool_secret, value, hashlib.sha1 ).hexdigest() assert a == test # Restore from string values = json_fix( simplejson.loads( value ) ) @@ -453,7 +463,6 @@ class Tool: self.tests = None # Determine if this tool can be used in workflows self.is_workflow_compatible = self.check_workflow_compatible() - def parse_inputs( self, root ): """ diff --git a/lib/galaxy/web/controllers/admin.py b/lib/galaxy/web/controllers/admin.py index 82d4d088912..2cb4366a3f3 100644 --- a/lib/galaxy/web/controllers/admin.py +++ b/lib/galaxy/web/controllers/admin.py @@ -1,9 +1,14 @@ -import shutil, StringIO, operator, urllib, gzip, tempfile, sets, string, sys +import shutil, StringIO, operator, urllib, gzip, tempfile, string, sys from datetime import datetime, timedelta from galaxy import util, datatypes from galaxy.web.base.controller import * from galaxy.model.orm import * from galaxy.web.controllers.forms import get_all_forms, get_form_widgets +# Older py compatibility +try: + set() +except: + from sets import Set as set import logging log = logging.getLogger( __name__ ) @@ -1236,16 +1241,16 @@ class Admin( BaseController ): if v == trans.app.security_agent.permitted_actions.DATASET_ACCESS: if len( in_roles ) > 1: # Get the set of all users that are being associated with the dataset - in_roles_set = sets.Set() + in_roles_set = set() for role in in_roles: in_roles_set.add( role ) - users_set = sets.Set() + users_set = set() for role in in_roles: for ura in role.users: users_set.add( ura.user ) # Make sure that at least 1 user has every role being associated with the dataset for user in users_set: - user_roles_set = sets.Set() + user_roles_set = set() for ura in user.roles: user_roles_set.add( ura.role ) if in_roles_set.issubset( user_roles_set ): @@ -1421,16 +1426,16 @@ class Admin( BaseController ): if v == trans.app.security_agent.permitted_actions.DATASET_ACCESS: if len( in_roles ) > 1: # Get the set of all users that are being associated with the dataset - in_roles_set = sets.Set() + in_roles_set = set() for role in in_roles: in_roles_set.add( role ) - users_set = sets.Set() + users_set = set() for role in in_roles: for ura in role.users: users_set.add( ura.user ) # Make sure that at least 1 user has every role being associated with the dataset for user in users_set: - user_roles_set = sets.Set() + user_roles_set = set() for ura in user.roles: user_roles_set.add( ura.role ) if in_roles_set.issubset( user_roles_set ): diff --git a/lib/galaxy/web/controllers/async.py b/lib/galaxy/web/controllers/async.py index c3709d2f913..032e472586d 100644 --- a/lib/galaxy/web/controllers/async.py +++ b/lib/galaxy/web/controllers/async.py @@ -6,8 +6,13 @@ from galaxy.web.base.controller import * from galaxy import jobs, util, datatypes, web -import logging, urllib -import sha, hmac +import logging, urllib, hmac, sys + +using_24 = sys.version_info[:2] < ( 2, 5 ) +if using_24: + import sha +else: + import hashlib log = logging.getLogger( __name__ ) @@ -58,7 +63,10 @@ class ASync( BaseController ): return "Data %s does not exist or has already been deleted" % data_id if STATUS == 'OK': - key = hmac.new( trans.app.config.tool_secret, "%d:%d" % ( data.id, data.history_id), sha ).hexdigest() + if using_24: + key = hmac.new( trans.app.config.tool_secret, "%d:%d" % ( data.id, data.history_id), sha ).hexdigest() + else: + key = hmac.new( trans.app.config.tool_secret, "%d:%d" % ( data.id, data.history_id), hashlib.sha1 ).hexdigest() if key != data_secret: return "You do not have permission to alter data %s." % data_id # push the job into the queue @@ -116,7 +124,10 @@ class ASync( BaseController ): trans.log_event( "Added dataset %d to history %d" %(data.id, trans.history.id ), tool_id=tool_id ) try: - key = hmac.new( trans.app.config.tool_secret, "%d:%d" % ( data.id, data.history_id), sha ).hexdigest() + if using_24: + key = hmac.new( trans.app.config.tool_secret, "%d:%d" % ( data.id, data.history_id), sha ).hexdigest() + else: + key = hmac.new( trans.app.config.tool_secret, "%d:%d" % ( data.id, data.history_id), hashlib.sha1 ).hexdigest() galaxy_url = trans.request.base + '/async/%s/%s/%s' % ( tool_id, data.id, key ) params.update( { 'GALAXY_URL' :galaxy_url } ) params.update( { 'data_id' :data.id } ) diff --git a/lib/galaxy/web/controllers/dataset.py b/lib/galaxy/web/controllers/dataset.py index ec299dde3a1..2f094de32f4 100644 --- a/lib/galaxy/web/controllers/dataset.py +++ b/lib/galaxy/web/controllers/dataset.py @@ -1,4 +1,4 @@ -import logging, os, sets, string, shutil, re, socket, mimetypes, smtplib, urllib +import logging, os, string, shutil, re, socket, mimetypes, smtplib, urllib from galaxy.web.base.controller import * from galaxy import util, datatypes, jobs, web, model diff --git a/lib/galaxy/web/controllers/genetrack.py b/lib/galaxy/web/controllers/genetrack.py index b964d844237..f2a97b04faa 100644 --- a/lib/galaxy/web/controllers/genetrack.py +++ b/lib/galaxy/web/controllers/genetrack.py @@ -1,12 +1,16 @@ -import time, glob, os +import time, glob, os, sys from itertools import cycle -import sha - from mako import exceptions from mako.template import Template from mako.lookup import TemplateLookup from galaxy.web.base.controller import * +using_24 = sys.version_info[:2] < ( 2, 5 ) +if using_24: + import sha +else: + import hashlib + try: import pkg_resources pkg_resources.require("GeneTrack") @@ -265,7 +269,10 @@ class WebRoot(BaseController): tmpl_name, track_maker = conf.PLOT_MAPPER[param.plot] # check against a hash, display an image that already exists if it was previously created. - hash = sha.new() + if using_24: + hash = sha.new() + else: + hash = hashlib.sha1() hash.update(str(dataset_id)) for key in sorted(kwds.keys()): hash.update(str(kwds[key])) diff --git a/lib/galaxy/web/controllers/root.py b/lib/galaxy/web/controllers/root.py index cd9a52316cd..dba83fa63d2 100644 --- a/lib/galaxy/web/controllers/root.py +++ b/lib/galaxy/web/controllers/root.py @@ -1,7 +1,7 @@ """ Contains the main interface in the Universe class """ -import logging, os, sets, string, shutil, urllib, re, socket +import logging, os, string, shutil, urllib, re, socket from cgi import escape, FieldStorage from galaxy import util, datatypes, jobs, web, util from galaxy.web.base.controller import * @@ -60,7 +60,6 @@ class RootController( BaseController ): trans.response.set_content_type('text/xml') return trans.fill_template_mako( "root/history_as_xml.mako", history=history, show_deleted=util.string_as_bool( show_deleted ) ) else: - template = "root/history.mako" show_deleted = util.string_as_bool( show_deleted ) query = trans.sa_session.query( model.HistoryDatasetAssociation ) \ .filter( model.HistoryDatasetAssociation.history == history ) \ diff --git a/lib/galaxy/web/controllers/tool_runner.py b/lib/galaxy/web/controllers/tool_runner.py index 42cfae6c1ed..e1179bd4b43 100644 --- a/lib/galaxy/web/controllers/tool_runner.py +++ b/lib/galaxy/web/controllers/tool_runner.py @@ -117,7 +117,6 @@ class ToolRunner( BaseController ): tool_state_string = util.object_to_string(state.encode(tool, trans.app)) # Setup context for template history = trans.get_history() - template = "tool_form.mako" vars = dict( tool_state=state, errors = {} ) # Is the "add frame" stuff neccesary here? add_frame = AddFrameData() @@ -125,17 +124,13 @@ class ToolRunner( BaseController ): if from_noframe is not None: add_frame.wiki_url = trans.app.config.wiki_url add_frame.from_noframe = True - return trans.fill_template( template, history=history, toolbox=toolbox, tool=tool, util=util, add_frame=add_frame, **vars ) - - + return trans.fill_template( "tool_form.mako", history=history, toolbox=toolbox, tool=tool, util=util, add_frame=add_frame, **vars ) @web.expose def redirect( self, trans, redirect_url=None, **kwd ): if not redirect_url: return trans.show_error_message( "Required URL for redirection missing" ) trans.log_event( "Redirecting to: %s" % redirect_url ) return trans.fill_template( 'root/redirect.mako', redirect_url=redirect_url ) - - @web.json def upload_async_create( self, trans, tool_id=None, **kwd ): """ diff --git a/lib/galaxy/web/framework/__init__.py b/lib/galaxy/web/framework/__init__.py index 78c5106aa9b..c67dd365cdb 100644 --- a/lib/galaxy/web/framework/__init__.py +++ b/lib/galaxy/web/framework/__init__.py @@ -93,8 +93,8 @@ class MessageException( Exception ): """ Exception to make throwing errors from deep in controllers easier """ - def __init__( self, message, type="info" ): - self.message = message + def __init__( self, err_msg, type="info" ): + self.err_msg = err_msg self.type = type def error( message ): @@ -117,7 +117,7 @@ class WebApplication( base.WebApplication ): self.security = galaxy_app.security def handle_controller_exception( self, e, trans, **kwargs ): if isinstance( e, MessageException ): - return trans.show_message( e.message, e.type ) + return trans.show_message( e.err_msg, e.type ) def make_body_iterable( self, trans, body ): if isinstance( body, FormBuilder ): body = trans.show_form( body ) diff --git a/lib/galaxy/webapps/reports/controllers/root.py b/lib/galaxy/webapps/reports/controllers/root.py index c7e54ce7dfe..7af4abda225 100644 --- a/lib/galaxy/webapps/reports/controllers/root.py +++ b/lib/galaxy/webapps/reports/controllers/root.py @@ -1,8 +1,8 @@ -import sys, os, operator, sets, string, shutil, re, socket, urllib +import sys, os, operator, string, shutil, re, socket, urllib, time from galaxy import web from cgi import escape, FieldStorage from galaxy.webapps.reports.base.controller import * -import logging, sets, time +import logging log = logging.getLogger( __name__ ) class Report( BaseController ): diff --git a/tools/data_source/genbank.py b/tools/data_source/genbank.py index 5b39bd270d9..cf857fc0b6c 100644 --- a/tools/data_source/genbank.py +++ b/tools/data_source/genbank.py @@ -1,6 +1,6 @@ #!/usr/bin/env python from Bio import GenBank -import sys, os, sets, textwrap +import sys, os, textwrap assert sys.version_info[:2] >= ( 2, 4 ) diff --git a/tools/data_source/ucsc_proxy.py b/tools/data_source/ucsc_proxy.py index 6105453d805..d8111799062 100644 --- a/tools/data_source/ucsc_proxy.py +++ b/tools/data_source/ucsc_proxy.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import urllib -import sys, os, sets +import sys, os assert sys.version_info[:2] >= ( 2, 4 ) diff --git a/tools/new_operations/get_flanks.py b/tools/new_operations/get_flanks.py index 90ea6261f61..502082ab0ba 100644 --- a/tools/new_operations/get_flanks.py +++ b/tools/new_operations/get_flanks.py @@ -9,7 +9,7 @@ usage: %prog input out_file size direction region -o, --off=N: Offset """ -import sys, sets, re, os +import sys, re, os from galaxy import eggs import pkg_resources; pkg_resources.require( "bx-python" ) from bx.cookbook import doc_optparse diff --git a/tools/new_operations/operation_filter.py b/tools/new_operations/operation_filter.py index e3d27a8ec99..63e0eb6a541 100644 --- a/tools/new_operations/operation_filter.py +++ b/tools/new_operations/operation_filter.py @@ -1,8 +1,13 @@ # runs after the job (and after the default post-filter) -import sets, os +import os from galaxy import eggs from galaxy import jobs from galaxy.tools.parameters import DataToolParameter +# Older py compatibility +try: + set() +except: + from sets import Set as set #def exec_before_process(app, inp_data, out_data, param_dict, tool=None): # """Sets the name of the data""" @@ -11,8 +16,8 @@ from galaxy.tools.parameters import DataToolParameter # raise Exception, '

Both Queries must be from the same genome build

' def validate_input( trans, error_map, param_values, page_param_map ): - dbkeys = sets.Set() - data_param_names = sets.Set() + dbkeys = set() + data_param_names = set() data_params = 0 for name, param in page_param_map.iteritems(): if isinstance( param, DataToolParameter ): diff --git a/tools/new_operations/subtract_query.py b/tools/new_operations/subtract_query.py index a628464e13b..de0ca1c86ee 100644 --- a/tools/new_operations/subtract_query.py +++ b/tools/new_operations/subtract_query.py @@ -5,13 +5,17 @@ Subtract an entire query from another query usage: %prog in_file_1 in_file_2 begin_col end_col output """ - -import sys, sets, re - +import sys, re from galaxy import eggs import pkg_resources; pkg_resources.require( "bx-python" ) from bx.cookbook import doc_optparse +# Older py compatibility +try: + set() +except: + from sets import Set as set + assert sys.version_info[:2] >= ( 2, 4 ) def get_lines(fname, begin_col='', end_col=''): diff --git a/tools/regVariation/windowSplitter.py b/tools/regVariation/windowSplitter.py index c5102aef578..3a322607449 100644 --- a/tools/regVariation/windowSplitter.py +++ b/tools/regVariation/windowSplitter.py @@ -7,7 +7,7 @@ usage: %prog input size out_file -l, --cols=N,N,N,N: Columns for chrom, start, end, strand in file """ -import sys, sets, re, os +import sys, re, os from galaxy import eggs import pkg_resources; pkg_resources.require( "bx-python" ) diff --git a/tools/stats/column_maker.py b/tools/stats/column_maker.py index bddce007802..d8ffa380960 100644 --- a/tools/stats/column_maker.py +++ b/tools/stats/column_maker.py @@ -2,7 +2,7 @@ # This tool takes a tab-delimited textfile as input and creates another column in the file which is the result of # a computation performed on every row in the original file. The tool will skip over invalid lines within the file, # informing the user about the number of lines skipped. -import sys, sets, re, os.path +import sys, re, os.path from galaxy import eggs from galaxy.tools import validation from galaxy.datatypes import metadata diff --git a/tools/stats/filtering.py b/tools/stats/filtering.py index 502f22d2381..63cd3fdc594 100644 --- a/tools/stats/filtering.py +++ b/tools/stats/filtering.py @@ -2,8 +2,13 @@ # This tool takes a tab-delimited text file as input and creates filters on columns based on certain properties. # The tool will skip over invalid lines within the file, informing the user about the number of lines skipped. -import sys, sets, re, os.path +import sys, re, os.path from galaxy import eggs +# Older py compatibility +try: + set() +except: + from sets import Set as set assert sys.version_info[:2] >= ( 2, 4 ) @@ -13,7 +18,7 @@ def get_operands( filter_condition ): for item in items_to_strip: if filter_condition.find( item ) >= 0: filter_condition = filter_condition.replace( item, ' ' ) - operands = sets.Set( filter_condition.split( ' ' ) ) + operands = set( filter_condition.split( ' ' ) ) return operands def stop_err( msg ): diff --git a/tools/stats/grouping.py b/tools/stats/grouping.py index b9178f064ee..7c0e35d83e4 100644 --- a/tools/stats/grouping.py +++ b/tools/stats/grouping.py @@ -3,7 +3,7 @@ """ This tool provides the SQL "group by" functionality. """ -import sys, string, re, commands, tempfile, random, sets +import sys, string, re, commands, tempfile, random from rpy import * def stop_err(msg): diff --git a/tools/stats/gsummary.py b/tools/stats/gsummary.py index ffe1ca6446b..00f3bbf25c5 100755 --- a/tools/stats/gsummary.py +++ b/tools/stats/gsummary.py @@ -1,7 +1,12 @@ #!/usr/bin/python -import sys, sets, re, tempfile +import sys, re, tempfile from rpy import * +# Older py compatibility +try: + set() +except: + from sets import Set as set assert sys.version_info[:2] >= ( 2, 4 ) @@ -33,7 +38,7 @@ def main(): for word in re.compile( '[a-zA-Z]+' ).findall( expression ): if word and not word in math_allowed: stop_err( "Invalid expression '%s': term '%s' is not recognized or allowed" %( expression, word ) ) - symbols = sets.Set() + symbols = set() for symbol in re.compile( '[^a-z0-9\s]+' ).findall( expression ): if symbol and not symbol in ops_allowed: stop_err( "Invalid expression '%s': operator '%s' is not recognized or allowed" % ( expression, symbol ) ) diff --git a/tools/visualization/build_ucsc_custom_track_code.py b/tools/visualization/build_ucsc_custom_track_code.py index 3a94f22be99..40e5f1377a2 100644 --- a/tools/visualization/build_ucsc_custom_track_code.py +++ b/tools/visualization/build_ucsc_custom_track_code.py @@ -1,6 +1,10 @@ # runs after the job (and after the default post-filter) -from sets import Set as set +# Older py compatibility +try: + set() +except: + from sets import Set as set def validate_input( trans, error_map, param_values, page_param_map ): dbkeys = set() diff --git a/tools/visualization/genetrack_code.py b/tools/visualization/genetrack_code.py index b79f77b13ce..e93a2819fd8 100644 --- a/tools/visualization/genetrack_code.py +++ b/tools/visualization/genetrack_code.py @@ -1,4 +1,4 @@ -import sets, os +import os from galaxy import eggs from galaxy import jobs from galaxy.tools.parameters import DataToolParameter