3 Created on Tue May 19 13:38:38 2015
8 Boreal Scientific Computing LLC, Fairbanks, Alaska, USA
9 Don.Morton@borealscicomp.com
10 http://www.borealscicomp.com/
16 christian.maurer@zamg.ac.at
17 delia.arnold-arias@zamg.ac.at
37 def __init__(self, src_dir=None, dest_dir=None,
38 met_dir=
None, met_nest_dir=
None, flexpart_exe=
None):
42 src_dir : a directory structure all set to run FLEXPART. Note that
43 the paths in pathnames must be all relative within this directory.
44 This directory will also need to contain the met data in directory
47 dest_dir : location that src_dir will be copied to, and where the
48 run will be executed. dest_dir cannot already exist. We make
49 this restriction to prevent accidental overwriting of something
52 met_dir : location of met files. Assumed to have a valid
56 flexpart_exe : full path to a FLEXPART executable
67 if os.path.isdir(src_dir):
70 msg =
'src_dir not found: ' + src_dir
73 msg =
'No src_dir argument'
79 if os.path.isdir(dest_dir):
80 msg =
'dest_dir cannot already exist: ' + dest_dir
85 msg =
'No dest_dir argument'
91 if os.path.isdir(met_dir):
94 msg =
'met_dir not found: ' + met_dir
97 msg =
'No met_dir argument'
103 if os.path.isdir(met_nest_dir):
106 msg =
'met_nest_dir not found: ' + met_nest_dir
112 if os.path.isfile(flexpart_exe)
and os.access(flexpart_exe, os.X_OK):
115 msg =
'flexpart_exe does not exist and/or is not executable'
118 msg =
'No flexpart_exe argument'
126 if not os.path.isdir(dest_dir):
130 shutil.copytree(src_dir, dest_dir)
131 logging.info(
'FlexpartCase: copying case dir to temp location')
135 diffs = filecmp.dircmp(src_dir, dest_dir)
137 logging.warning(
'FlexpartCase: src and dest differ')
143 logging.warning(
'FlexpartCase: copy failed')
146 logging.warning(
'FlexpartCase: dest_dir exists')
152 if not os.path.isdir(dest_dir +
'/output'):
155 os.mkdir(dest_dir +
'/output', 0755)
157 msg =
'No output dir present in case directory'
162 os.symlink(self.
_met_dir, dest_dir +
'/met_data')
164 msg =
'Unable to create met_data symlink to: ' + self.
_met_dir
172 msg =
'Unable to create met_data_nest symlink to: ' + \
177 if not os.path.isfile(dest_dir +
'/met_data/AVAILABLE'):
178 msg =
'Unable to find AVAILABLE in ' + dest_dir +
'/met_data'
182 if not os.path.isfile(dest_dir +
'/met_data_nest/AVAILABLE'):
183 msg =
'Unable to find AVAILABLE in ' + dest_dir +
'/met_data_nest'
200 """Runs the case - assumes that the original case template was
201 in good shape and that it was copied successfully. The variable
202 self._destdir_ok provides a very simple, but incomplete check.
204 This routine will launch the executable, and then wait for it to
205 complete. stdout will go to file stdout.txt at the top of the
209 stdoutFH = open(self.
_dest_dir +
'/stdout.txt',
'w')
211 start_time = time.time()
212 the_process = subprocess.Popen( self.
_flexpart_exe, shell=
True,
216 status=the_process.wait()
217 stop_time = time.time()
226 """Looks at last line of stdout and insures it contains some of the
227 expected key words. This is a very simple test and, in the future
228 should be replaced with something more robust that insures the expected
229 output files are all present
232 so_far_so_good =
True
236 stdoutFH = open(self.
_dest_dir +
'/stdout.txt',
'r')
238 so_far_so_good =
False
243 for the_line
in stdoutFH:
250 tokens = last_line.split()
252 so_far_so_good =
False
257 if so_far_so_good
and (
'CONGRATULATIONS:' and \
258 'SUCCESSFULLLY' and 'COMPLETED' \
259 and 'FLEXPART' in tokens):
271 """Returns value of execution time in seconds"""
def execution_time_seconds