Skip to content

Commit

Permalink
make sure to execute gssha from working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan D. Snow committed Jun 2, 2017
1 parent b0f62a6 commit 617e9b2
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions gsshapy/modeling/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,30 +635,31 @@ def run(self, subdirectory=None):
directory=working_directory,
name=self.project_manager.name)

# RUN SIMULATION
if self.gssha_executable and find_executable(self.gssha_executable) is not None:
log.info("Running GSSHA simulation ...")

try:
run_gssha_command = [self.gssha_executable,
os.path.join(working_directory, self.project_filename)]
# run GSSHA
out = subprocess.check_output(run_gssha_command)

# write out GSSHA output
log_file_path = os.path.join(working_directory, 'simulation.log')
with open(log_file_path, mode='w') as logfile:
logfile.write(out.decode('utf-8'))
# log to other logger if debug mode on
if log.isEnabledFor(logging.DEBUG):
for line in out.split(b'\n'):
log.debug(line.decode('utf-8'))

except subprocess.CalledProcessError as ex:
log.error("{0}: {1}".format(ex.returncode, ex.output))
with tmp_chdir(working_directory):
# RUN SIMULATION
if self.gssha_executable and find_executable(self.gssha_executable) is not None:
log.info("Running GSSHA simulation ...")

else:
log.warning("GSSHA executable not found. Skipping GSSHA simulation run ...")
try:
run_gssha_command = [self.gssha_executable,
os.path.join(working_directory, self.project_filename)]
# run GSSHA
out = subprocess.check_output(run_gssha_command)

# write out GSSHA output
log_file_path = os.path.join(working_directory, 'simulation.log')
with open(log_file_path, mode='w') as logfile:
logfile.write(out.decode('utf-8'))
# log to other logger if debug mode on
if log.isEnabledFor(logging.DEBUG):
for line in out.split(b'\n'):
log.debug(line.decode('utf-8'))

except subprocess.CalledProcessError as ex:
log.error("{0}: {1}".format(ex.returncode, ex.output))

else:
log.warning("GSSHA executable not found. Skipping GSSHA simulation run ...")

return working_directory

Expand Down

0 comments on commit 617e9b2

Please sign in to comment.