From d58b60e1969dadd3910a41c39f259a1e6c5ad9e0 Mon Sep 17 00:00:00 2001
From: John Chilton <jmchilton@gmail.com>
Date: Tue, 10 Sep 2013 07:18:54 -0500
Subject: [PATCH] Parse destination_params for submit_params.

This feels some what wrong because a destination is describing both which LWR server and manager to use as well as the parameters to be used. This is a Galaxyism though - same holds true for all destinations the LWR justs feels heavier because we are constructing a client object per request.
---
 lwr/lwr_client/client.py      |  9 ++++++++-
 lwr/lwr_client/destination.py | 15 +++++++++++++++
 test/check.py                 |  9 ++++-----
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/lwr/lwr_client/client.py b/lwr/lwr_client/client.py
index f6f8a02e..a4ee845b 100644
--- a/lwr/lwr_client/client.py
+++ b/lwr/lwr_client/client.py
@@ -6,6 +6,7 @@ from simplejson import dumps
 from time import sleep
 
 from .destination import url_to_destination_params
+from .destination import submit_params
 
 CACHE_WAIT_SECONDS = 3
 MAX_RETRY_COUNT = 5
@@ -69,11 +70,16 @@ class Client(object):
         self.remote_host = destination_params.get("url")
         self.default_file_action = destination_params.get("default_file_action", "transfer")
         self.action_config_path = destination_params.get("file_action_config", None)
+        self.destination_params = destination_params
         assert self.remote_host != None, "Failed to determine url for LWR client."
         self.private_key = destination_params.get("private_token", None)
         self.job_id = job_id
         self.client_manager = client_manager
 
+    @property
+    def _submit_params(self):
+        return submit_params(self.destination_params)
+
     def __build_url(self, command, args):
         if self.private_key:
             args["private_key"] = self.private_key
@@ -197,7 +203,7 @@ class Client(object):
                             "output_type": output_type},
                            output_path=output_path)
 
-    def launch(self, command_line, submit_params=None):
+    def launch(self, command_line):
         """
         Run or queue up the execution of the supplied
         `command_line` on the remote server.
@@ -208,6 +214,7 @@ class Client(object):
             Command to execute.
         """
         launch_params = dict(command_line=command_line, job_id=self.job_id)
+        submit_params = self._submit_params
         if submit_params:
             launch_params['params'] = dumps(submit_params)
         return self._raw_execute("launch", launch_params)
diff --git a/lwr/lwr_client/destination.py b/lwr/lwr_client/destination.py
index 110227d8..5c44ce76 100644
--- a/lwr/lwr_client/destination.py
+++ b/lwr/lwr_client/destination.py
@@ -1,6 +1,8 @@
 
 from re import match
 
+SUBMIT_PREFIX = "submit_"
+
 
 def url_to_destination_params(url):
     """Convert a legacy runner URL to a job destination
@@ -42,3 +44,16 @@ def url_to_destination_params(url):
                         "private_token": private_token}
 
     return destination_args
+
+
+def submit_params(destination_params):
+    """
+
+    >>> destination_params = {"private_token": "12345", "submit_native_specification": "-q batch"}
+    >>> result = submit_params(destination_params)
+    >>> result.items()
+    [('native_specification', '-q batch')]
+    """
+    return dict([(key[len(SUBMIT_PREFIX):], value)
+                  for key, value in (destination_params or {}).iteritems()
+                  if key.startswith(SUBMIT_PREFIX)])
diff --git a/test/check.py b/test/check.py
index 37791839..f51dbd52 100644
--- a/test/check.py
+++ b/test/check.py
@@ -66,14 +66,13 @@ finally:
         client_options = {"url": options.url, "private_token": options.private_token}
         if hasattr(options, "default_file_action"):
             client_options["default_file_action"] = getattr(options, "default_file_action")
+        user = getattr(options, 'user', None)
+        if user:
+            client_options["submit_user"] = user
         client = ClientManager(**manager_args).get_client(client_options, "123456")
         stager = FileStager(client, MockTool(temp_tool_dir), command_line, config_files, input_files, output_files, temp_work_dir)
         new_command = stager.get_rewritten_command_line()
-        submit_params = {}
-        user = getattr(options, 'user', None)
-        if user:
-            submit_params['user'] = user
-        client.launch(new_command, submit_params)
+        client.launch(new_command)
         response = client.wait()
 
         finish_args = dict(client=client,
-- 
GitLab