3 Created on Wed Mar 11 12:30:25 2015
19 def __init__(self, srcdir=None, destdir=None,
20 makefile=
None, parmodfile=
None,
21 executable_name=
None):
25 srcdir : full path to location of FLEXPART src tree
26 destdir : full path to copy the FLEXPART src tree into.
27 Files will be copied directly in here
28 makefile : The makefile to use - if there is no leading path, then
29 file is assumed to be in srcdir. Otherwise, it is
30 assumed to be located as defined by the path
31 parmodfile : full path to an external (from source code) par_mod.F90
32 executable_name : The name of the expected executable (stripped path)
38 if os.path.isdir(srcdir):
41 msg =
'srcdir not found: ' + srcdir
47 if os.path.isdir(destdir):
48 msg =
'destdir cannot already exist: ' + destdir
53 msg =
'No destdir argument'
62 path_tuple = os.path.split(makefile)
64 if len(path_tuple[0]) == 0:
73 msg =
'source makefile not found: ' + makefile
77 msg =
'No makefile argument'
84 msg =
'No executable_name argument'
90 if os.path.isfile(parmodfile):
93 msg =
'parmodfile not found: ' + parmodfile
104 if not os.path.isdir(destdir):
108 shutil.copytree(srcdir, destdir)
109 logging.info(
'FlexpartExecutable: copying source code to temp location')
113 diffs = filecmp.dircmp(srcdir, destdir)
115 logging.warning(
'FlexpartExecutable: src and dest differ')
121 logging.warning(
'FlexpartExecutable: copy failed')
127 shutil.copy(self.
_parmodfile, destdir +
'/par_mod.F90')
130 logging.warning(
'FlexpartExecutable: parmodfile copy failed')
134 logging.warning(
'FlexpartExecutable: destdir exists')
140 extensions = (
'.o',
'.mod')
141 for current_file
in os.listdir(destdir):
142 if any(current_file.endswith(ext)
for ext
in extensions):
143 os.remove(destdir +
'/' + current_file)
148 """ Can't remember why I might have considered this method """
153 """ Returns True or False depending on whether the expected
154 executable exists. Note that this says nothing about whether it
155 is a good executable or not - simply that an executable file of the
156 expected name exists in the expected location """
159 if self._path_to_executable
and \
160 os.path.isfile(self._path_to_executable)
and \
161 os.access(self._path_to_executable, os.X_OK):
167 """Compile the code. Return True or False depending on success"""
169 make_command =
'make -f ' + self.
_makefile
171 with open(self.
_destdir +
'/compile.out',
'w')
as out:
172 make_process = subprocess.Popen(make_command, shell=
True,
178 STATUS = make_process.wait()
188 """Return path to expected executable. Note that this does not
189 imply that the executable actually exists"""
194 if __name__ ==
"__main__":
195 SRC=
'/u1/uaf/morton/tmp/C3'
196 DEST=
'/u1/uaf/morton/tmp/Cblah'
def get_expected_executable_path