diff --git a/src/python/clawutil/data.py b/src/python/clawutil/data.py index 276a0df..4b37806 100644 --- a/src/python/clawutil/data.py +++ b/src/python/clawutil/data.py @@ -14,7 +14,14 @@ from __future__ import absolute_import from __future__ import print_function import os -from inspect import signature +import sys +import inspect +import tarfile +import zipfile +import string +import six +from six.moves import range +from six.moves import input try: from urllib.request import urlopen @@ -22,14 +29,7 @@ # Fall back to Python 2's urllib2 from urllib2 import urlopen -import tarfile -import zipfile -import string - import numpy as np -import six -from six.moves import range -from six.moves import input # ====================== # Remote file handling @@ -302,7 +302,7 @@ def close_data_file(self): self._out_file = None - def write(self,out_file,data_source='setrun.py'): + def write(self, out_file, data_source='setrun.py'): r"""Write out all data files in this ClawData object""" # Open data file @@ -528,7 +528,14 @@ def write(self, out_dir = ''): if isinstance(data_object, UserData): fname = data_object.__fname__ else: - fname = signature(data_object.write).parameters['out_file'].default + if six.PY2: + argspec = inspect.getargspec(data_object.write) + index = argspec.args.index('out_file') - (len(argspec.args) + - len(argspec.defaults)) + fname = argspec.defaults[index] + else: + argspec = inspect.signature(data_object.write) + fname = argspec.parameters['out_file'].default fpath = os.path.join(out_dir,fname) if isinstance(data_object, amrclaw.GaugeData): data_object.write(self.clawdata.num_eqn, self.clawdata.num_aux, out_file=fpath) diff --git a/src/python/clawutil/runclaw.py b/src/python/clawutil/runclaw.py index 8d8f4d3..38691dd 100755 --- a/src/python/clawutil/runclaw.py +++ b/src/python/clawutil/runclaw.py @@ -10,12 +10,17 @@ from __future__ import absolute_import from __future__ import print_function +import six + import os import sys import glob import shutil import shlex import subprocess +import time + +from clawpack.clawutil.data import ClawData from clawpack.clawutil.claw_git_status import make_git_status_file # define an execution error class that returns a @@ -30,7 +35,7 @@ def __str__(self): def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, rundir=None, print_git_status=False, nohup=False, nice=None, - xclawout=subprocess.PIPE, xclawerr=subprocess.PIPE): + xclawout=None, xclawerr=None, verbose=True): """ Run the Fortran version of Clawpack using executable xclawcmd, which is typically set to 'xclaw', 'xamr', etc. @@ -66,14 +71,12 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, ``xclawerr=subprocess.STDOUT``. """ - from clawpack.clawutil.data import ClawData - import os,glob,shutil,time - verbose = True - try: - nice = int(nice) - except: - nice = None + if nice is not None: + try: + nice = int(nice) + except: + nice = None # convert strings passed in from Makefile to boolean: if type(overwrite) is str: @@ -145,8 +148,15 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, except: print("==> runclaw: Could not move directory... copy already exists?") - - os.makedirs(outdir, exist_ok=True) + if six.PY2: + if (not os.path.isdir(outdir)): + try: + os.mkdir(outdir) + except: + print("Cannot make directory ",outdir) + return + else: + os.makedirs(outdir, exist_ok=True) if print_git_status not in [False,'False']: # create files claw_git_status.txt and claw_git_diffs.txt in @@ -184,7 +194,7 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, else: if rundir != outdir: for file in datafiles: - shutil.copy(file,os.path.join(outdir,os.path.basename(file))) + shutil.copy(file, os.path.join(outdir,os.path.basename(file))) # execute command to run fortran program: if nohup: @@ -204,29 +214,29 @@ def runclaw(xclawcmd=None, outdir=None, overwrite=True, restart=None, print("\n==> Running with command:\n ", cmd) cmd_split = shlex.split(cmd) - if isinstance(xclawout,str): + if isinstance(xclawout, str): xclawout = open(xclawout,'w', encoding='utf-8', buffering=1) - if isinstance(xclawerr,str): + if isinstance(xclawerr, str): xclawerr = open(xclawerr,'w', encoding='utf-8', buffering=1) try: - p = subprocess.run(cmd_split, - cwd=outdir, - stdout=xclawout, - stderr=xclawerr, - encoding='utf-8', - check=True) + proc = subprocess.check_call(cmd_split, + cwd=outdir, + stdout=xclawout, + stderr=xclawerr) + except subprocess.CalledProcessError as cpe: - raise ClawExeError('error', cpe.returncode, cpe.cmd, + exe_error_str = "\n\n*** FORTRAN EXE FAILED ***\n" + raise ClawExeError(exe_error_str, cpe.returncode, cpe.cmd, output=cpe.output, - stderr=cpe.stderr) from cpe + stderr=cpe.stderr) print('==> runclaw: Done executing %s via clawutil.runclaw.py' %\ xclawcmd) print('==> runclaw: Output is in ', outdir) - return p + return proc #----------------------------------------------------------