FLEXPART Testing Environment CTBTO WO8
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | Private Attributes | List of all members
flextest.FlexpartExecutable.FlexpartExecutable Class Reference

Public Member Functions

def __init__
 
def modify_makefile
 
def executable_exists
 
def compile_it
 
def get_expected_executable_path
 

Private Attributes

 _srcdir
 
 _destdir
 
 _makefile
 
 _path_to_executable
 
 _parmodfile
 
 _destdir_ok
 

Detailed Description

Definition at line 16 of file FlexpartExecutable.py.

Constructor & Destructor Documentation

def flextest.FlexpartExecutable.FlexpartExecutable.__init__ (   self,
  srcdir = None,
  destdir = None,
  makefile = None,
  parmodfile = None,
  executable_name = None 
)
Set up the class

srcdir : full path to location of FLEXPART src tree
destdir : full path to copy the FLEXPART src tree into.
  Files will be copied directly in here
makefile : The makefile to use - if there is no leading path, then
   file is assumed to be in srcdir.  Otherwise, it is 
   assumed to be located as defined by the path
parmodfile : full path to an external (from source code) par_mod.F90
executable_name : The name of the expected executable (stripped path)

Definition at line 21 of file FlexpartExecutable.py.

21 
22  executable_name=None):
23 
24  """Set up the class
25 
26  srcdir : full path to location of FLEXPART src tree
27  destdir : full path to copy the FLEXPART src tree into.
28  Files will be copied directly in here
29  makefile : The makefile to use - if there is no leading path, then
30  file is assumed to be in srcdir. Otherwise, it is
31  assumed to be located as defined by the path
32  parmodfile : full path to an external (from source code) par_mod.F90
33  executable_name : The name of the expected executable (stripped path)
34  """
35 
36  # Reasons to abort ##########################
37 
38  # Test that srcdir is found
39  if os.path.isdir(srcdir):
40  self._srcdir = srcdir
41  else:
42  msg = 'srcdir not found: ' + srcdir
43  raise Exception(msg)
44 
45  # test for a destdir argument
46  if destdir:
47  # Make sure it doesn't already exist
48  if os.path.isdir(destdir):
49  msg = 'destdir cannot already exist: ' + destdir
50  raise Exception(msg)
51  else:
52  self._destdir = destdir
53  else:
54  msg = 'No destdir argument'
55  raise Exception(msg)
56 
57 
58  # test for a makefile argument. If the argument has a prefixed path,
59  # then put the whole path in the makefile name. Otherwise, it is
60  # assumed to be in the source directory
61  if makefile:
62  # Make sure the we get the correct path on the makefile
63  path_tuple = os.path.split(makefile)
64  #print path_tuple
65  if len(path_tuple[0]) == 0:
66  # No leading path
67  self._makefile = self._srcdir + '/' + makefile
68  else:
69  # Full path
70  self._makefile = makefile
71  #print self._makefile
72  # Now let's make sure it actually exists
73  if not os.path.isfile(self._makefile):
74  msg = 'source makefile not found: ' + makefile
75  self._makefile = None
76  raise Exception(msg)
77  else:
78  msg = 'No makefile argument'
79  raise Exception(msg)
80 
81  # test for executable_name argument
82  if executable_name:
83  self._path_to_executable = destdir + '/' + executable_name
84  else:
85  msg = 'No executable_name argument'
86  raise Exception(msg)
87 
88  # Test for external par_mod.F90 and, if it's valid, store path
89  self._parmodfile = None
90  if parmodfile:
91  if os.path.isfile(parmodfile):
92  self._parmodfile = parmodfile
93  else:
94  msg = 'parmodfile not found: ' + parmodfile
95  raise Exception(msg)
96 
97 
98  #print self._path_to_executable
99  self._destdir_ok = False # This indicates if copy to destdir was ok
100 
101  init_success = True
102 
103 
104  # Make sure destdir does not already exist
105  if not os.path.isdir(destdir):
106  # Copy the distribution from srcdir into destdir and validate success
107  try:
108  #print srcdir, destdir
109  shutil.copytree(srcdir, destdir)
110  logging.info('FlexpartExecutable: copying source code to temp location')
111 
112  # Compare the directories. Success would be indicated
113  # by an empty list diffs.diff_files
114  diffs = filecmp.dircmp(srcdir, destdir)
115  if diffs.diff_files:
116  logging.warning('FlexpartExecutable: src and dest differ')
117  init_success = False
118 
119 
120  except:
121  init_success = False
122  logging.warning('FlexpartExecutable: copy failed')
123 
124  # If we made it here, one last step is to copy in a substitute
125  # parmodfile, if it was specified
126  if init_success and self._parmodfile:
127  try:
128  shutil.copy(self._parmodfile, destdir + '/par_mod.F90')
129  except:
130  init_success = False
131  logging.warning('FlexpartExecutable: parmodfile copy failed')
132 
133  else:
134  init_success = False
135  logging.warning('FlexpartExecutable: destdir exists')
136 
137  if init_success:
138  self._destdir_ok = True
139 
140  # Remove any *.o and *.mod files
141  extensions = ('.o', '.mod')
142  for current_file in os.listdir(destdir):
143  if any(current_file.endswith(ext) for ext in extensions):
144  os.remove(destdir + '/' + current_file)
145 
146 

Member Function Documentation

def flextest.FlexpartExecutable.FlexpartExecutable.compile_it (   self)
Compile the code.  Return True or False depending on success

Definition at line 166 of file FlexpartExecutable.py.

167  def compile_it(self):
168  """Compile the code. Return True or False depending on success"""
169 
170  make_command = 'make -f ' + self._makefile
171 
172  with open(self._destdir + '/compile.out', 'w') as out:
173  make_process = subprocess.Popen(make_command, shell=True,
174  stdout=out,
175  stderr=out,
176  cwd=self._destdir)
177 
178 
179  STATUS = make_process.wait()
180  #print 'STATUS: ' + str(STATUS)
181  if STATUS == 0:
182  return True
183  else:
184  return False
185 
def flextest.FlexpartExecutable.FlexpartExecutable.executable_exists (   self)
Returns True or False depending on whether the expected
executable exists.  Note that this says nothing about whether it
is a good executable or not - simply that an executable file of the
expected name exists in the expected location 

Definition at line 152 of file FlexpartExecutable.py.

153  def executable_exists(self):
154  """ Returns True or False depending on whether the expected
155  executable exists. Note that this says nothing about whether it
156  is a good executable or not - simply that an executable file of the
157  expected name exists in the expected location """
158 
159  return_value = False
160  if self._path_to_executable and \
161  os.path.isfile(self._path_to_executable) and \
162  os.access(self._path_to_executable, os.X_OK):
163  return_value = True
164 
165  return return_value
def flextest.FlexpartExecutable.FlexpartExecutable.get_expected_executable_path (   self)
Return path to expected executable.  Note that this does not
imply that the executable actually exists

Definition at line 186 of file FlexpartExecutable.py.

188 
189  """Return path to expected executable. Note that this does not
190  imply that the executable actually exists"""
191 
192  return copy.copy(self._path_to_executable)
def flextest.FlexpartExecutable.FlexpartExecutable.modify_makefile (   self)
Can't remember why I might have considered this method 

Definition at line 147 of file FlexpartExecutable.py.

148  def modify_makefile(self):
149  """ Can't remember why I might have considered this method """
150 
151  pass

Member Data Documentation

flextest.FlexpartExecutable.FlexpartExecutable._destdir
private

Definition at line 51 of file FlexpartExecutable.py.

flextest.FlexpartExecutable.FlexpartExecutable._destdir_ok
private

Definition at line 98 of file FlexpartExecutable.py.

flextest.FlexpartExecutable.FlexpartExecutable._makefile
private

Definition at line 66 of file FlexpartExecutable.py.

flextest.FlexpartExecutable.FlexpartExecutable._parmodfile
private

Definition at line 88 of file FlexpartExecutable.py.

flextest.FlexpartExecutable.FlexpartExecutable._path_to_executable
private

Definition at line 82 of file FlexpartExecutable.py.

flextest.FlexpartExecutable.FlexpartExecutable._srcdir
private

Definition at line 39 of file FlexpartExecutable.py.


The documentation for this class was generated from the following file: