source: flex_extract.git/documentation/Sphinx/build/html/_modules/submit.html @ 2625ca8

dev
Last change on this file since 2625ca8 was 2625ca8, checked in by Anne Philipp <anne.philipp@…>, 6 months ago

new build of sphinx for updated api

  • Property mode set to 100644
File size: 32.9 KB
Line 
1
2
3<!DOCTYPE html>
4<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
5<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
6<head>
7  <meta charset="utf-8">
8 
9  <meta name="viewport" content="width=device-width, initial-scale=1.0">
10 
11  <title>submit &mdash; flex_extract 7.1 alpha documentation</title>
12 
13
14 
15 
16 
17 
18
19 
20
21 
22 
23   
24
25 
26
27  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
28  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
29    <link rel="index" title="Index" href="../genindex.html" />
30    <link rel="search" title="Search" href="../search.html" /> 
31
32 
33  <script src="../_static/js/modernizr.min.js"></script>
34
35</head>
36
37<body class="wy-body-for-nav">
38
39   
40  <div class="wy-grid-for-nav">
41
42   
43    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
44      <div class="wy-side-scroll">
45        <div class="wy-side-nav-search">
46         
47
48         
49            <a href="../index.html" class="icon icon-home"> flex_extract
50         
51
52         
53          </a>
54
55         
56           
57           
58              <div class="version">
59                7.1
60              </div>
61           
62         
63
64         
65<div role="search">
66  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
67    <input type="text" name="q" placeholder="Search docs" />
68    <input type="hidden" name="check_keywords" value="yes" />
69    <input type="hidden" name="area" value="default" />
70  </form>
71</div>
72
73         
74        </div>
75
76        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
77         
78           
79           
80             
81           
82           
83              <p class="caption"><span class="caption-text">Table of Contents:</span></p>
84<ul>
85<li class="toctree-l1"><a class="reference internal" href="../downloads.html">Downloads</a></li>
86<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
87<li class="toctree-l1"><a class="reference internal" href="../program_structure.html">Program Structure</a></li>
88<li class="toctree-l1"><a class="reference internal" href="../user_guide.html">User Guide</a></li>
89<li class="toctree-l1"><a class="reference internal" href="../api.html">Auto Generated Documentation</a></li>
90<li class="toctree-l1"><a class="reference internal" href="../support.html">Support</a></li>
91</ul>
92
93           
94         
95        </div>
96      </div>
97    </nav>
98
99    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
100
101     
102      <nav class="wy-nav-top" aria-label="top navigation">
103       
104          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
105          <a href="../index.html">flex_extract</a>
106       
107      </nav>
108
109
110      <div class="wy-nav-content">
111       
112        <div class="rst-content">
113       
114         
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130<div role="navigation" aria-label="breadcrumbs navigation">
131
132  <ul class="wy-breadcrumbs">
133   
134      <li><a href="../index.html">Docs</a> &raquo;</li>
135       
136          <li><a href="index.html">Module code</a> &raquo;</li>
137       
138      <li>submit</li>
139   
140   
141      <li class="wy-breadcrumbs-aside">
142       
143      </li>
144   
145  </ul>
146
147 
148  <hr/>
149</div>
150          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
151           <div itemprop="articleBody">
152           
153  <h1>Source code for submit</h1><div class="highlight"><pre>
154<span></span><span class="ch">#!/usr/bin/env python</span>
155<span class="c1"># -*- coding: utf-8 -*-</span>
156<span class="c1">#*******************************************************************************</span>
157<span class="c1"># @Author: Anne Fouilloux (University of Oslo)</span>
158<span class="c1">#</span>
159<span class="c1"># @Date: October 2014</span>
160<span class="c1">#</span>
161<span class="c1"># @Change History:</span>
162<span class="c1">#</span>
163<span class="c1">#    November 2015 - Leopold Haimberger (University of Vienna):</span>
164<span class="c1">#        - job submission on ecgate and cca</span>
165<span class="c1">#        - job templates suitable for twice daily operational dissemination</span>
166<span class="c1">#</span>
167<span class="c1">#    February 2018 - Anne Philipp (University of Vienna):</span>
168<span class="c1">#        - applied PEP8 style guide</span>
169<span class="c1">#        - added documentation</span>
170<span class="c1">#        - minor changes in programming style (for consistence)</span>
171<span class="c1">#        - changed path names to variables from config file</span>
172<span class="c1">#        - added option for writing mars requests to extra file</span>
173<span class="c1">#          additionally, as option without submitting the mars jobs</span>
174<span class="c1">#        - splitted submit function to use genshi templates for the</span>
175<span class="c1">#          job script and avoid code duplication</span>
176<span class="c1">#</span>
177<span class="c1"># @License:</span>
178<span class="c1">#    (C) Copyright 2014-2019.</span>
179<span class="c1">#    Anne Philipp, Leopold Haimberger</span>
180<span class="c1">#</span>
181<span class="c1">#    This work is licensed under the Creative Commons Attribution 4.0</span>
182<span class="c1">#    International License. To view a copy of this license, visit</span>
183<span class="c1">#    http://creativecommons.org/licenses/by/4.0/ or send a letter to</span>
184<span class="c1">#    Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.</span>
185<span class="c1">#*******************************************************************************</span>
186<span class="sd">&#39;&#39;&#39;This script allows the user to extract meteorological fields from the ECMWF.</span>
187
188<span class="sd">It prepares the settings for retrieving the data from ECMWF servers and</span>
189<span class="sd">process the resulting files to prepare them for the use with FLEXPART or</span>
190<span class="sd">FLEXTRA.</span>
191
192<span class="sd">If it is supposed to work locally then it works through the necessary</span>
193<span class="sd">functions get_mars_data and prepare_flexpart. Otherwise it prepares</span>
194<span class="sd">a job script (korn shell) which will do the necessary work on the</span>
195<span class="sd">ECMWF server. This script will de submitted via the ecaccess command</span>
196<span class="sd">ecaccess-job-submit.</span>
197
198<span class="sd">This file can also be imported as a module which then contains the following</span>
199<span class="sd">functions:</span>
200
201<span class="sd">    * main - the main function of the script</span>
202<span class="sd">    * submit - calls mk_jobscript depending on operation mode and submits its</span>
203<span class="sd">    * mk_jobscript - creates the job script from a template</span>
204
205<span class="sd">Type: submit.py --help</span>
206<span class="sd">to get information about command line parameters.</span>
207<span class="sd">Read the documentation for usage instructions.</span>
208<span class="sd">&#39;&#39;&#39;</span>
209
210<span class="c1"># ------------------------------------------------------------------------------</span>
211<span class="c1"># MODULES</span>
212<span class="c1"># ------------------------------------------------------------------------------</span>
213<span class="kn">import</span> <span class="nn">os</span>
214<span class="kn">import</span> <span class="nn">sys</span>
215<span class="kn">import</span> <span class="nn">subprocess</span>
216<span class="kn">import</span> <span class="nn">inspect</span>
217<span class="kn">import</span> <span class="nn">collections</span>
218<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
219
220<span class="c1"># software specific classes and modules from flex_extract</span>
221<span class="kn">import</span> <span class="nn">_config</span>
222<span class="kn">from</span> <span class="nn">mods.tools</span> <span class="k">import</span> <span class="p">(</span><span class="n">normal_exit</span><span class="p">,</span> <span class="n">get_cmdline_args</span><span class="p">,</span>
223                        <span class="n">submit_job_to_ecserver</span><span class="p">,</span> <span class="n">read_ecenv</span><span class="p">)</span>
224<span class="kn">from</span> <span class="nn">mods.get_mars_data</span> <span class="k">import</span> <span class="n">get_mars_data</span>
225<span class="kn">from</span> <span class="nn">mods.prepare_flexpart</span> <span class="k">import</span> <span class="n">prepare_flexpart</span>
226<span class="kn">from</span> <span class="nn">classes.ControlFile</span> <span class="k">import</span> <span class="n">ControlFile</span>
227
228<span class="c1"># ------------------------------------------------------------------------------</span>
229<span class="c1"># METHODS</span>
230<span class="c1"># ------------------------------------------------------------------------------</span>
231
232<div class="viewcode-block" id="main"><a class="viewcode-back" href="../api.html#submit.main">[docs]</a><span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
233    <span class="sd">&#39;&#39;&#39;Get the arguments from script call and from CONTROL file.</span>
234<span class="sd">    Decides from the argument &quot;queue&quot; if the local version</span>
235<span class="sd">    is done &quot;queue=None&quot; or the gateway version with &quot;queue=ecgate&quot;</span>
236<span class="sd">    or &quot;queue=cca&quot;.</span>
237
238<span class="sd">    Parameters</span>
239<span class="sd">    ----------</span>
240
241<span class="sd">    Return</span>
242<span class="sd">    ------</span>
243
244<span class="sd">    &#39;&#39;&#39;</span>
245
246    <span class="n">args</span> <span class="o">=</span> <span class="n">get_cmdline_args</span><span class="p">()</span>
247    <span class="n">c</span> <span class="o">=</span> <span class="n">ControlFile</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">controlfile</span><span class="p">)</span>
248
249    <span class="n">env_parameter</span> <span class="o">=</span> <span class="n">read_ecenv</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_ECMWF_ENV</span><span class="p">)</span>
250    <span class="n">c</span><span class="o">.</span><span class="n">assign_args_to_control</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
251    <span class="n">c</span><span class="o">.</span><span class="n">assign_envs_to_control</span><span class="p">(</span><span class="n">env_parameter</span><span class="p">)</span>
252    <span class="n">c</span><span class="o">.</span><span class="n">check_conditions</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">queue</span><span class="p">)</span>
253
254    <span class="c1"># on local side</span>
255    <span class="c1"># on ECMWF server this would also be the local side</span>
256    <span class="n">called_from_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
257    <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">queue</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
258        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">&#39;/&#39;</span><span class="p">:</span>
259            <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">called_from_dir</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">)</span>
260        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">&#39;/&#39;</span><span class="p">:</span>
261            <span class="n">c</span><span class="o">.</span><span class="n">outputdir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">called_from_dir</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">)</span>
262        <span class="n">get_mars_data</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
263        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">request</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
264            <span class="n">prepare_flexpart</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">ppid</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
265            <span class="n">exit_message</span> <span class="o">=</span> <span class="s1">&#39;FLEX_EXTRACT IS DONE!&#39;</span>
266        <span class="k">else</span><span class="p">:</span>
267            <span class="n">exit_message</span> <span class="o">=</span> <span class="s1">&#39;PRINTING MARS_REQUESTS DONE!&#39;</span>
268    <span class="c1"># send files to ECMWF server</span>
269    <span class="k">else</span><span class="p">:</span>
270        <span class="n">submit</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">job_template</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">args</span><span class="o">.</span><span class="n">queue</span><span class="p">)</span>
271        <span class="n">exit_message</span> <span class="o">=</span> <span class="s1">&#39;FLEX_EXTRACT JOB SCRIPT IS SUBMITED!&#39;</span>
272
273    <span class="n">normal_exit</span><span class="p">(</span><span class="n">exit_message</span><span class="p">)</span>
274
275    <span class="k">return</span></div>
276
277<div class="viewcode-block" id="submit"><a class="viewcode-back" href="../api.html#submit.submit">[docs]</a><span class="k">def</span> <span class="nf">submit</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">queue</span><span class="p">):</span>
278    <span class="sd">&#39;&#39;&#39;Prepares the job script and submits it to the specified queue.</span>
279
280<span class="sd">    Parameters</span>
281<span class="sd">    ----------</span>
282<span class="sd">    jtemplate : str</span>
283<span class="sd">        Job template file from sub-directory &quot;_templates&quot; for</span>
284<span class="sd">        submission to ECMWF. It contains all necessary</span>
285<span class="sd">        module and variable settings for the ECMWF environment as well as</span>
286<span class="sd">        the job call and mail report instructions.</span>
287<span class="sd">        Default is &quot;job.temp&quot;.</span>
288
289<span class="sd">    c : ControlFile</span>
290<span class="sd">        Contains all the parameters of CONTROL file and</span>
291<span class="sd">        command line.</span>
292
293<span class="sd">    queue : str</span>
294<span class="sd">        Name of queue for submission to ECMWF (e.g. ecgate or cca )</span>
295
296<span class="sd">    Return</span>
297<span class="sd">    ------</span>
298
299<span class="sd">    &#39;&#39;&#39;</span>
300
301    <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">:</span>
302    <span class="c1"># --------- create on demand job script ------------------------------------</span>
303        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
304            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;---- Pure forecast mode! ----&#39;</span><span class="p">)</span>
305        <span class="k">else</span><span class="p">:</span>
306            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;---- On-demand mode! ----&#39;</span><span class="p">)</span>
307
308        <span class="n">job_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_JOBSCRIPTS</span><span class="p">,</span>
309                                <span class="n">jtemplate</span><span class="p">[:</span><span class="o">-</span><span class="mi">5</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;.ksh&#39;</span><span class="p">)</span>
310
311        <span class="c1"># divide time periode into specified number of job chunks</span>
312        <span class="c1"># to have multiple job scripts</span>
313        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">job_chunk</span><span class="p">:</span>
314            <span class="n">start</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">start_date</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
315            <span class="n">end</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">end_date</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
316            <span class="n">chunk</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">job_chunk</span><span class="p">)</span>
317
318            <span class="k">while</span> <span class="n">start</span> <span class="o">&lt;=</span> <span class="n">end</span><span class="p">:</span>
319                <span class="k">if</span> <span class="p">(</span><span class="n">start</span> <span class="o">+</span> <span class="n">chunk</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">end</span><span class="p">:</span>
320                    <span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">=</span> <span class="p">(</span><span class="n">start</span> <span class="o">+</span> <span class="n">chunk</span><span class="p">)</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span>
321                <span class="k">else</span><span class="p">:</span>
322                    <span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span>
323
324                <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
325
326                <span class="n">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">)</span>
327
328                <span class="n">job_id</span> <span class="o">=</span> <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
329                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The job id is: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job_id</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
330
331                <span class="n">start</span> <span class="o">=</span> <span class="n">start</span> <span class="o">+</span> <span class="n">chunk</span>
332                <span class="n">c</span><span class="o">.</span><span class="n">start_date</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span>
333        <span class="c1"># submit a single job script</span>
334        <span class="k">else</span><span class="p">:</span>
335            <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
336
337            <span class="n">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">)</span>
338
339            <span class="n">job_id</span> <span class="o">=</span> <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
340            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The job id is: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job_id</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
341
342    <span class="k">else</span><span class="p">:</span>
343    <span class="c1"># --------- create operational job script ----------------------------------</span>
344        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;---- Operational mode! ----&#39;</span><span class="p">)</span>
345
346        <span class="n">job_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_JOBSCRIPTS</span><span class="p">,</span>
347                                <span class="n">jtemplate</span><span class="p">[:</span><span class="o">-</span><span class="mi">5</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;oper.ksh&#39;</span><span class="p">)</span>
348
349        <span class="n">c</span><span class="o">.</span><span class="n">start_date</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_YEAR}</span><span class="s1">$</span><span class="si">{MSJ_MONTH}</span><span class="s1">$</span><span class="si">{MSJ_DAY}</span><span class="s1">&#39;</span>
350        <span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_YEAR}</span><span class="s1">$</span><span class="si">{MSJ_MONTH}</span><span class="s1">$</span><span class="si">{MSJ_DAY}</span><span class="s1">&#39;</span>
351        <span class="n">c</span><span class="o">.</span><span class="n">base_time</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_BASETIME}</span><span class="s1">&#39;</span>
352        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">24</span><span class="p">:</span>
353            <span class="n">c</span><span class="o">.</span><span class="n">time</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_BASETIME}</span><span class="s1"> </span><span class="si">{MSJ_BASETIME}</span><span class="s1">&#39;</span>
354
355        <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
356
357        <span class="n">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">)</span>
358
359        <span class="n">job_id</span> <span class="o">=</span> <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
360        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The job id is: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job_id</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
361
362    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;You should get an email per job with subject flex.hostname.pid&#39;</span><span class="p">)</span>
363
364    <span class="k">return</span></div>
365
366<div class="viewcode-block" id="mk_jobscript"><a class="viewcode-back" href="../api.html#submit.mk_jobscript">[docs]</a><span class="k">def</span> <span class="nf">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">):</span>
367    <span class="sd">&#39;&#39;&#39;Creates the job script from template.</span>
368
369<span class="sd">    Parameters</span>
370<span class="sd">    ----------</span>
371<span class="sd">    jtemplate : str</span>
372<span class="sd">        Job template file from sub-directory &quot;_templates&quot; for</span>
373<span class="sd">        submission to ECMWF. It contains all necessary</span>
374<span class="sd">        module and variable settings for the ECMWF environment as well as</span>
375<span class="sd">        the job call and mail report instructions.</span>
376<span class="sd">        Default is &quot;job.temp&quot;.</span>
377
378<span class="sd">    job_file : str</span>
379<span class="sd">        Path to the job script file.</span>
380
381<span class="sd">    clist : list of str</span>
382<span class="sd">        Contains all necessary parameters for ECMWF CONTROL file.</span>
383
384<span class="sd">    Return</span>
385<span class="sd">    ------</span>
386
387<span class="sd">    &#39;&#39;&#39;</span>
388    <span class="kn">from</span> <span class="nn">genshi.template.text</span> <span class="k">import</span> <span class="n">NewTextTemplate</span>
389    <span class="kn">from</span> <span class="nn">genshi.template</span> <span class="k">import</span>  <span class="n">TemplateLoader</span>
390    <span class="kn">from</span> <span class="nn">genshi.template.eval</span> <span class="k">import</span> <span class="n">UndefinedError</span>
391
392    <span class="c1"># load template and insert control content as list</span>
393    <span class="k">try</span><span class="p">:</span>
394        <span class="n">loader</span> <span class="o">=</span> <span class="n">TemplateLoader</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_TEMPLATES</span><span class="p">,</span> <span class="n">auto_reload</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
395        <span class="n">control_template</span> <span class="o">=</span> <span class="n">loader</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span>
396                                       <span class="bp">cls</span><span class="o">=</span><span class="n">NewTextTemplate</span><span class="p">)</span>
397
398        <span class="n">stream</span> <span class="o">=</span> <span class="n">control_template</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">control_content</span><span class="o">=</span><span class="n">clist</span><span class="p">)</span>
399    <span class="k">except</span> <span class="n">UndefinedError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
400        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
401
402        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to generate jobscript&#39;</span><span class="p">)</span>
403    <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
404        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR CODE: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="p">))</span>
405        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR MESSAGE:</span><span class="se">\n</span><span class="s1"> </span><span class="se">\t</span><span class="s1"> &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">))</span>
406
407        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to generate jobscript&#39;</span><span class="p">)</span>
408
409    <span class="c1"># create jobscript file</span>
410    <span class="k">try</span><span class="p">:</span>
411        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">job_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
412            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">stream</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s1">&#39;text&#39;</span><span class="p">))</span>
413    <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
414        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR CODE: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="p">))</span>
415        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR MESSAGE:</span><span class="se">\n</span><span class="s1"> </span><span class="se">\t</span><span class="s1"> &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">))</span>
416
417        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to write &#39;</span> <span class="o">+</span> <span class="n">job_file</span><span class="p">)</span>
418
419    <span class="k">return</span></div>
420
421
422<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
423    <span class="n">main</span><span class="p">()</span>
424</pre></div>
425
426           </div>
427           
428          </div>
429          <footer>
430 
431
432  <hr/>
433
434  <div role="contentinfo">
435    <p>
436        &copy; Copyright 2018, Anne Philipp and Leopold Haimberger
437
438    </p>
439  </div>
440  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
441
442</footer>
443
444        </div>
445      </div>
446
447    </section>
448
449  </div>
450 
451
452
453 
454
455   
456   
457      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
458        <script type="text/javascript" src="../_static/jquery.js"></script>
459        <script type="text/javascript" src="../_static/underscore.js"></script>
460        <script type="text/javascript" src="../_static/doctools.js"></script>
461   
462
463 
464
465  <script type="text/javascript" src="../_static/js/theme.js"></script>
466
467  <script type="text/javascript">
468      jQuery(function () {
469          SphinxRtdTheme.Navigation.enable(true);
470      });
471  </script> 
472
473</body>
474</html>
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG