Skip to content

Commit

Permalink
Support external server use in CLI
Browse files Browse the repository at this point in the history
- Addresses issue #87
- TODO: when server status starts in unknown state, CLI should ask user if running
  externally.
  • Loading branch information
Jay B. Martin committed Apr 22, 2014
1 parent 058c139 commit ee7c3da
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions psiturk/psiturk_shell.py
Expand Up @@ -107,6 +107,7 @@ def __init__(self, config, server):
self.helpPath = os.path.join(os.path.dirname(__file__), "shell_help/")
self.psiTurk_header = 'psiTurk command help:'
self.super_header = 'basic CMD command help:'
self.server.is_external = False

self.color_prompt()
self.intro = self.get_intro_prompt()
Expand Down Expand Up @@ -146,6 +147,8 @@ def color_prompt(self):
serverString = colorize('on', 'green')
elif server_status == 'no':
serverString = colorize('off', 'red')
elif self.server.is_external is True:
serverString = colorize('external', 'green')
elif server_status == 'maybe':
serverString = colorize('unknown', 'yellow')
prompt += ' server:' + serverString
Expand Down Expand Up @@ -219,11 +222,16 @@ def do_debug(self, arg):
-p, --print-only just provides the URL, doesn't attempt to launch browser
"""
if self.server.is_server_running() == 'no' or self.server.is_server_running()=='maybe':
if self.server.is_server_running() == 'no' or self.server.is_server_running()=='maybe' and self.server.is_external is not True:
print "Error: Sorry, you need to have the server running to debug your experiment. Try 'server on' first."
return

base_url = "http://" + self.config.get('Server Parameters', 'host') + ":" + self.config.get('Server Parameters', 'port') + "/ad"
if self.server.is_external is True:
server_name = '[external address]'
else:
server_name = self.config.get('Server Parameters', 'host')

base_url = "http://" + server_name + ":" + self.config.get('Server Parameters', 'port') + "/ad"
launchurl = base_url + "?assignmentId=debug" + str(self.random_id_generator()) \
+ "&hitId=debug" + str(self.random_id_generator()) \
+ "&workerId=debug" + str(self.random_id_generator())
Expand Down Expand Up @@ -268,6 +276,8 @@ def do_status(self, arg):
print 'Server: ' + colorize('currently online', 'green')
elif server_status == 'no':
print 'Server: ' + colorize('currently offline', 'red')
elif self.server.is_external is True:
serverString = colorize('external', 'green')
elif server_status == 'maybe':
print 'Server: ' + colorize('status unknown', 'yellow')

Expand Down Expand Up @@ -455,6 +465,8 @@ def color_prompt(self): # overloads prompt with network info
serverString = colorize('on', 'green')
elif server_status == 'no':
serverString = colorize('off', 'red')
elif self.server.is_external is True:
serverString = colorize('external', 'green')
elif server_status == 'maybe':
serverString = colorize('unknown', 'yellow')
prompt += ' server:' + serverString
Expand Down Expand Up @@ -713,8 +725,10 @@ def hit_create(self, numWorkers, reward, duration):
''])
r = raw_input('\n'.join([' If you are using an external server process, press `y` to continue.',
' Otherwise, press `n` to cancel:']))
if r!='y':
if r != 'y':
return
else:
self.server.is_external = True

interactive = False
if numWorkers is None:
Expand Down Expand Up @@ -1259,7 +1273,7 @@ def do_mode(self, arg):
mode <which>
"""
restartServer = False
if self.server.is_server_running() == 'yes' or self.server.is_server_running() == 'maybe':
if self.server.is_server_running() == 'yes' or self.server.is_server_running() == 'maybe' and self.server.is_external is not True:
r = raw_input("Switching modes requires the server to restart. Really switch modes? y or n: ")
if r != 'y':
return
Expand Down

1 comment on commit ee7c3da

@gureckis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one suggestion is that we add a hidden config option for external_server rather than giving the prompt on create_hit when the server isn't running. the reason is that if most people aren't going to be using the external server thing, then why even present that to them when creating hits? @alexanderrich tells me that it is possible to have a default config setting like external_server = False which is set by default and you would just add external_server=True to your local config.txt if you wanted to enable that logic.

i could imagine down the line other aspects of the psiTurk process needing access to the server (e.g., worker bonus?) or knowing that the server is external, thus it might make sense to turn the external_server option into a broader configuration setting.

Please sign in to comment.