Repository: ESMCI/cime

Issue:
Allow passing batch arguments through case.submit command line options
Suggested by @erichlf over on ACME.

If one wants to add arguments to the batch submit command, they have to edit env_batch.xml.  For experimenting and trying something once, it would be easier to pass additional commands as an argument to case.submit like this:
case.submit --batchargs '--mail-user=user@server.com --mail-type=END'




Discussion:
The original PR can be seen [here](https://github.com/ACME-Climate/ACME/pull/1180#issuecomment-267092914).
This seems like a good idea.

Resolving patch:
diff --git a/utils/python/CIME/XML/env_batch.py b/utils/python/CIME/XML/env_batch.py
--- a/utils/python/CIME/XML/env_batch.py
+++ b/utils/python/CIME/XML/env_batch.py
@@ -286,7 +286,7 @@ def get_submit_args(self, case, job):
 
         return submitargs
 
-    def submit_jobs(self, case, no_batch=False, job=None):
+    def submit_jobs(self, case, no_batch=False, job=None, batch_args=None):
         alljobs = self.get_jobs()
         startindex = 0
         jobs = []
@@ -311,6 +311,7 @@ def submit_jobs(self, case, no_batch=False, job=None):
                 jobs.append((job,self.get_value('dependency', subgroup=job)))
             if self.batchtype == "cobalt":
                 break
+
         depid = {}
         for job, dependency in jobs:
             if dependency is not None:
@@ -335,12 +336,13 @@ def submit_jobs(self, case, no_batch=False, job=None):
                 jobid = None
 
             logger.warn("job is %s"%job)
-            depid[job] = self.submit_single_job(case, job, jobid, no_batch=no_batch)
+            depid[job] = self.submit_single_job(case, job, jobid, no_batch=no_batch, batch_args=batch_args)
             if self.batchtype == "cobalt":
                 break
+
         return sorted(list(depid.values()))
 
-    def submit_single_job(self, case, job, depid=None, no_batch=False):
+    def submit_single_job(self, case, job, depid=None, no_batch=False, batch_args=None):
         logger.warn("Submit job %s"%job)
         caseroot = case.get_value("CASEROOT")
         batch_system = self.get_value("BATCH_SYSTEM", subgroup=None)
@@ -374,6 +376,9 @@ def submit_single_job(self, case, job, depid=None, no_batch=False):
             dep_string = dep_string.replace("jobid",depid.strip()) # pylint: disable=maybe-no-member
             submitargs += " " + dep_string
 
+        if batch_args is not None:
+            submitargs += " " + batch_args
+
         batchsubmit = self.get_value("batch_submit", subgroup=None)
         expect(batchsubmit is not None,
                "Unable to determine the correct command for batch submission.")
diff --git a/utils/python/CIME/case.py b/utils/python/CIME/case.py
--- a/utils/python/CIME/case.py
+++ b/utils/python/CIME/case.py
@@ -1052,9 +1052,9 @@ def create_clone(self, newcase, keepexe=False, mach_dir=None, project=None, cime
 
         return newcase
 
-    def submit_jobs(self, no_batch=False, job=None):
+    def submit_jobs(self, no_batch=False, job=None, batch_args=None):
         env_batch = self.get_env('batch')
-        return env_batch.submit_jobs(self, no_batch=no_batch, job=job)
+        return env_batch.submit_jobs(self, no_batch=no_batch, job=job, batch_args=batch_args)
 
     def get_mpirun_cmd(self, job="case.run"):
         env_mach_specific = self.get_env('mach_specific')
diff --git a/utils/python/CIME/case_submit.py b/utils/python/CIME/case_submit.py
--- a/utils/python/CIME/case_submit.py
+++ b/utils/python/CIME/case_submit.py
@@ -15,7 +15,7 @@
 
 logger = logging.getLogger(__name__)
 
-def submit(case, job=None, resubmit=False, no_batch=False):
+def submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):
     caseroot = case.get_value("CASEROOT")
 
     if job is None:
@@ -62,7 +62,7 @@ def submit(case, job=None, resubmit=False, no_batch=False):
     case.flush()
 
     logger.warn("submit_jobs %s"%job)
-    job_ids = case.submit_jobs(no_batch=no_batch, job=job)
+    job_ids = case.submit_jobs(no_batch=no_batch, job=job, batch_args=batch_args)
     msg = "Submitted jobs %s"%job_ids
     append_status(msg, caseroot=caseroot, sfile="CaseStatus")
 


Test patch: