Skip to content

Commit

Permalink
Merge pull request #741 from natefoo/drop-pexpect
Browse files Browse the repository at this point in the history
Do not explicitly require pexpect
  • Loading branch information
dannon committed Sep 17, 2015
2 parents d717ec8 + 150c17b commit 63e3596
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
12 changes: 10 additions & 2 deletions lib/galaxy/model/__init__.py
Expand Up @@ -19,13 +19,16 @@
from uuid import UUID, uuid4

from galaxy import eggs
eggs.require("pexpect")
import pexpect
eggs.require('SQLAlchemy')
from sqlalchemy import and_, func, not_, or_, true, join, select
from sqlalchemy.orm import joinedload, object_session, aliased
from sqlalchemy.ext import hybrid

try:
import pexpect
except ImportError:
pexpect = None

import galaxy.datatypes
import galaxy.datatypes.registry
import galaxy.model.orm.now
Expand Down Expand Up @@ -57,6 +60,9 @@
# this be unlimited - filter in Python if over this limit.
MAX_IN_FILTER_LENGTH = 100

PEXPECT_IMPORT_MESSAGE = ('The Python pexpect package is required to use this '
'feature, please install it')


class NoConverterException(Exception):
def __init__(self, value):
Expand Down Expand Up @@ -4245,6 +4251,8 @@ def untransferred_dataset_files( self ):
def get_untransferred_dataset_size( self, filepath, scp_configs ):
def print_ticks( d ):
pass
if pexpect is None:
return PEXPECT_IMPORT_MESSAGE
error_msg = 'Error encountered in determining the file size of %s on the external_service.' % filepath
if not scp_configs['host'] or not scp_configs['user_name'] or not scp_configs['password']:
return error_msg
Expand Down
1 change: 0 additions & 1 deletion lib/galaxy/web/framework/__init__.py
Expand Up @@ -3,7 +3,6 @@
"""

from galaxy import eggs
eggs.require( "pexpect" )
eggs.require( "amqp" )

import base
Expand Down
33 changes: 23 additions & 10 deletions lib/galaxy/webapps/galaxy/controllers/requests_admin.py
Expand Up @@ -10,7 +10,13 @@
from galaxy import eggs
eggs.require("amqp")
import amqp
import pexpect
try:
import pexpect
except ImportError:
pexpect = None

PEXPECT_IMPORT_MESSAGE = ('The Python pexpect package is required to use this '
'feature, please install it')

log = logging.getLogger( __name__ )

Expand Down Expand Up @@ -440,6 +446,8 @@ def print_ticks( d ):
# Avoid caching
trans.response.headers['Pragma'] = 'no-cache'
trans.response.headers['Expires'] = '0'
if pexpect is None:
return PEXPECT_IMPORT_MESSAGE
external_service = trans.sa_session.query( trans.model.ExternalService ).get( trans.security.decode_id( external_service_id ) )
external_service.load_data_transfer_settings( trans )
scp_configs = external_service.data_transfer[ trans.model.ExternalService.data_transfer_protocol.SCP ]
Expand Down Expand Up @@ -498,15 +506,20 @@ def print_ticks( d ):
cmd = 'ssh %s@%s "ls -p \'%s\'"' % ( scp_configs[ 'user_name' ], scp_configs[ 'host' ], folder_path )
# Handle the authentication message if keys are not set - the message is
# something like: "Are you sure you want to continue connecting (yes/no)."
output = pexpect.run( cmd,
events={ '\(yes\/no\)\.*' : 'yes\r\n',
'.ssword:*' : scp_configs[ 'password' ] + '\r\n',
pexpect.TIMEOUT : print_ticks },
timeout=10 )
if 'No such file or directory' in output:
status = 'error'
message = "No folder named (%s) exists on the external service." % folder_path
ok = False
if pexpect is not None:
output = pexpect.run( cmd,
events={ '\(yes\/no\)\.*' : 'yes\r\n',
'.ssword:*' : scp_configs[ 'password' ] + '\r\n',
pexpect.TIMEOUT : print_ticks },
timeout=10 )
if 'No such file or directory' in output:
status = 'error'
message = "No folder named (%s) exists on the external service." % folder_path
ok = False
else:
status = 'error'
message = PEXPECT_IMPORT_MESSAGE
ok = False
if ok:
if 'assword:' in output:
# Eliminate the output created using ssh from the tree
Expand Down
12 changes: 9 additions & 3 deletions scripts/transfer.py
Expand Up @@ -11,9 +11,10 @@

from galaxy import eggs

import pkg_resources
pkg_resources.require( "pexpect" )
import pexpect
try:
import pexpect
except ImportError:
pexpect = None

eggs.require( "SQLAlchemy >= 0.4" )

Expand All @@ -27,6 +28,9 @@
eggs.require( 'python_daemon' )
from daemon import DaemonContext

PEXPECT_IMPORT_MESSAGE = ('The Python pexpect package is required to use this '
'feature, please install it')

log = logging.getLogger( __name__ )
log.setLevel( logging.DEBUG )
handler = logging.StreamHandler( sys.stdout )
Expand Down Expand Up @@ -247,6 +251,8 @@ def print_ticks( d ):
user_name = transfer_job.params[ 'user_name' ]
password = transfer_job.params[ 'password' ]
file_path = transfer_job.params[ 'file_path' ]
if pexpect is None:
return dict( state = transfer_job.states.ERROR, info = PEXPECT_IMPORT_MESSAGE )
try:
fh, fn = tempfile.mkstemp()
except Exception, e:
Expand Down

0 comments on commit 63e3596

Please sign in to comment.