Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flex Extract
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Flexpart
Flex Extract
Commits
bf48c8a5
Commit
bf48c8a5
authored
6 years ago
by
Anne Philipp
Browse files
Options
Downloads
Patches
Plain Diff
introduced a function for subprocess check_call to do error handling once
parent
524ac32c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
source/python/classes/EcFlexpart.py
+29
-18
29 additions, 18 deletions
source/python/classes/EcFlexpart.py
source/python/install.py
+4
-4
4 additions, 4 deletions
source/python/install.py
source/python/mods/tools.py
+36
-0
36 additions, 0 deletions
source/python/mods/tools.py
with
69 additions
and
22 deletions
source/python/classes/EcFlexpart.py
+
29
−
18
View file @
bf48c8a5
...
...
@@ -91,7 +91,8 @@ sys.path.append('../')
import
_config
from
GribUtil
import
GribUtil
from
mods.tools
import
(
init128
,
to_param_id
,
silent_remove
,
product
,
my_error
,
make_dir
,
get_informations
,
get_dimensions
)
my_error
,
make_dir
,
get_informations
,
get_dimensions
,
execute_subprocess
)
from
MarsRetrieval
import
MarsRetrieval
import
mods.disaggregation
as
disaggregation
...
...
@@ -1426,8 +1427,10 @@ class EcFlexpart(object):
sys
.
stdout
.
flush
()
# Fortran program creates file fort.15 (with u,v,etadot,t,sp,q)
p
=
subprocess
.
check_call
([
os
.
path
.
join
(
c
.
exedir
,
_config
.
FORTRAN_EXECUTABLE
)],
shell
=
True
)
execute_subprocess
([
os
.
path
.
join
(
c
.
exedir
,
_config
.
FORTRAN_EXECUTABLE
)],
error_msg
=
'
FORTRAN PROGRAM FAILED!
'
)
#shell=True)
os
.
chdir
(
pwd
)
#============================================================================================
# create name of final output file, e.g. EN13040500 (ENYYMMDDHH)
...
...
@@ -1506,24 +1509,32 @@ class EcFlexpart(object):
ofile
=
os
.
path
.
join
(
self
.
inputdir
,
ofile
)
if
c
.
format
.
lower
()
==
'
grib2
'
:
p
=
subprocess
.
check_call
([
'
grib_set
'
,
'
-s
'
,
'
edition=2,
'
,
execute_
subprocess
([
'
grib_set
'
,
'
-s
'
,
'
edition=2,
'
+
'
productDefinitionTemplateNumber=8
'
,
ofile
,
ofile
+
'
_2
'
])
p
=
subprocess
.
check_call
([
'
mv
'
,
ofile
+
'
_2
'
,
ofile
])
ofile
,
ofile
+
'
_2
'
],
error_msg
=
'
GRIB2 CONVERSION FAILED!
'
)
execute_subprocess
([
'
mv
'
,
ofile
+
'
_2
'
,
ofile
],
error_msg
=
'
RENAMING FOR NEW GRIB2 FORMAT
'
'
FILES FAILED!
'
)
if
c
.
ectrans
and
not
c
.
ecapi
:
p
=
subprocess
.
check_call
([
'
ectrans
'
,
'
-overwrite
'
,
'
-gateway
'
,
execute_
subprocess
([
'
ectrans
'
,
'
-overwrite
'
,
'
-gateway
'
,
c
.
gateway
,
'
-remote
'
,
c
.
destination
,
'
-source
'
,
ofile
])
'
-source
'
,
ofile
],
error_msg
=
'
TRANSFER TO LOCAL SERVER FAILED!
'
)
if
c
.
ecstorage
and
not
c
.
ecapi
:
p
=
subprocess
.
check_call
([
'
ecp
'
,
'
-o
'
,
ofile
,
os
.
path
.
expandvars
(
c
.
ecfsdir
)])
execute_subprocess
([
'
ecp
'
,
'
-o
'
,
ofile
,
os
.
path
.
expandvars
(
c
.
ecfsdir
)],
error_msg
=
'
COPY OF FILES TO ECSTORAGE
'
'
AREA FAILED!
'
)
if
c
.
outputdir
!=
c
.
inputdir
:
p
=
subprocess
.
check_call
([
'
mv
'
,
os
.
path
.
join
(
c
.
inputdir
,
ofile
),
c
.
outputdir
])
execute_subprocess
([
'
mv
'
,
os
.
path
.
join
(
c
.
inputdir
,
ofile
),
c
.
outputdir
],
error_msg
=
'
RELOCATION OF OUTPUT FILES
'
'
TO OUTPUTDIR FAILED!
'
)
return
...
...
@@ -1603,9 +1614,9 @@ class EcFlexpart(object):
# change to outputdir and start the grib2flexpart run
# afterwards switch back to the working dir
os
.
chdir
(
c
.
outputdir
)
p
=
subprocess
.
check_call
([
os
.
path
.
expandvars
(
os
.
path
.
expanduser
(
c
.
flexpartdir
))
+
'
/../FLEXPART_PROGRAM/grib2flexpart
'
,
'
useAvailable
'
,
'
.
'
]
)
cmd
=
[
os
.
path
.
expandvars
(
os
.
path
.
expanduser
(
c
.
flexpartdir
))
+
'
/../FLEXPART_PROGRAM/grib2flexpart
'
,
'
useAvailable
'
,
'
.
'
]
execute_subprocess
(
cmd
)
os
.
chdir
(
pwd
)
return
This diff is collapsed.
Click to expand it.
source/python/install.py
+
4
−
4
View file @
bf48c8a5
...
...
@@ -61,7 +61,7 @@ import _config
from
classes.ControlFile
import
ControlFile
from
classes.UioFiles
import
UioFiles
from
mods.tools
import
(
make_dir
,
put_file_to_ecserver
,
submit_job_to_ecserver
,
silent_remove
)
silent_remove
,
execute_subprocess
)
# ------------------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -676,9 +676,9 @@ def mk_convert_build(src_path, makefile):
print
(
'
ERROR: Makefile call failed:
'
)
print
(
e
)
else
:
subprocess
.
check_call
([
'
ls
'
,
'
-l
'
,
os
.
path
.
join
(
src_path
,
_config
.
FORTRAN
_
EXECUTABLE
)]
)
execute_
subprocess
([
'
ls
'
,
'
-l
'
,
os
.
path
.
join
(
src_path
,
_config
.
FORTRAN_EXECUTABLE
)],
error_msg
=
'
FORTRAN
EXECUTABLE
COULD NOT BE FOUND!
'
)
return
...
...
This diff is collapsed.
Click to expand it.
source/python/mods/tools.py
+
36
−
0
View file @
bf48c8a5
...
...
@@ -742,3 +742,39 @@ def get_dimensions(info, purefc, dtime, index_vals, start_date, end_date):
it
=
len
(
index_vals
[
2
])
*
len
(
index_vals
[
1
])
*
len
(
index_vals
[
0
])
return
(
ix
,
jy
,
it
)
def
execute_subprocess
(
cmd_list
,
error_msg
=
'
SUBPROCESS FAILED!
'
):
'''
Executes a command line instruction via a subprocess.
Error handling is done if an error occures.
Parameters
----------
cmd_list : :obj:`list` of `:obj:`string`
A list of the components for the command line execution. Each
list entry is a single part of the command which is seperated from
the rest by a blank space.
E.g. [
'
mv
'
, file1, file2]
Return
------
error_msg : :obj:`string`, optional
The possible error message if the subprocess failed.
By default it will just tell
"
SUBPROCESS FAILED!
"
.
'''
try
:
subprocess
.
check_call
(
cmd_list
)
except
subprocess
.
CalledProcessError
as
e
:
print
(
'
... ERROR CODE:
'
+
str
(
e
.
returncode
))
print
(
'
... ERROR MESSAGE:
\n
\t
'
+
str
(
e
))
sys
.
exit
(
'
...
'
+
error_msg
)
except
OSError
as
e
:
print
(
'
... ERROR CODE:
'
+
str
(
e
.
errno
))
print
(
'
... ERROR MESSAGE:
\n
\t
'
+
str
(
e
.
strerror
))
sys
.
exit
(
'
...
'
+
error_msg
)
return
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment