Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions scripts/ccpp_prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys

# CCPP framework imports
from common import encode_container, decode_container, decode_container_as_dict, execute
from common import encode_container, decode_container, decode_container_as_dict
from common import CCPP_STAGES, CCPP_INTERNAL_VARIABLES, CCPP_STATIC_API_MODULE, CCPP_INTERNAL_VARIABLE_DEFINITON_FILE
from common import STANDARD_VARIABLE_TYPES, STANDARD_INTEGER_TYPE, CCPP_TYPE
from common import SUITE_DEFINITION_FILENAME_PATTERN
Expand Down Expand Up @@ -157,9 +157,14 @@ def clean_files(config, namespace):
os.path.join(config['static_api_dir'], static_api_file),
config['static_api_sourcefile'],
]
# Not very pythonic, but the easiest way w/o importing another Python module
cmd = 'rm -vf {0}'.format(' '.join(files_to_remove))
execute(cmd)
for f in files_to_remove:
try:
os.remove(f)
except FileNotFoundError:
pass
except Exception as e:
logging.error(f"Error removing {f}: {e}")
success = False
return success

def get_all_suites(suites_dir):
Expand Down
29 changes: 0 additions & 29 deletions scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,6 @@
# Maximum number of concurrent CCPP instances per MPI task
CCPP_NUM_INSTANCES = 200

def execute(cmd, abort = True):
"""Runs a local command in a shell. Waits for completion and
returns status, stdout and stderr. If abort = True, abort in
case an error occurs during the execution of the command."""

# Set debug to true if logging level is debug
debug = logging.getLogger().getEffectiveLevel() == logging.DEBUG

logging.debug('Executing "{0}"'.format(cmd))
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
stderr = subprocess.PIPE, shell = True)
(stdout, stderr) = p.communicate()
status = p.returncode
if debug:
message = 'Execution of "{0}" returned with exit code {1}\n'.format(cmd, status)
message += ' stdout: "{0}"\n'.format(stdout.decode(encoding='ascii', errors='ignore').rstrip('\n'))
message += ' stderr: "{0}"'.format(stderr.decode(encoding='ascii', errors='ignore').rstrip('\n'))
logging.debug(message)
if not status == 0:
message = 'Execution of command {0} failed, exit code {1}\n'.format(cmd, status)
message += ' stdout: "{0}"\n'.format(stdout.decode(encoding='ascii', errors='ignore').rstrip('\n'))
message += ' stderr: "{0}"'.format(stderr.decode(encoding='ascii', errors='ignore').rstrip('\n'))
if abort:
raise Exception(message)
else:
logging.error(message)
return (status, stdout.decode(encoding='ascii', errors='ignore').rstrip('\n'),
stderr.decode(encoding='ascii', errors='ignore').rstrip('\n'))

def split_var_name_and_array_reference(var_name):
"""Split an expression like foo(:,a,1:ddt%ngas)
into components foo and (:,a,1:ddt%ngas)."""
Expand Down
12 changes: 0 additions & 12 deletions test/unit_tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ class CommonTestCase(unittest.TestCase):

"""Tests functionality of functions in common.py"""

def test_execute(self):
"""Test execute() function"""

# Input for successful test: ls command on this file
self.assertEqual(common.execute(f"ls {TEST_FILE}"),(0,f"{TEST_FILE}",""))

# Input for failing test (no exception): exit 1 from a subshell
self.assertEqual(common.execute(f"(exit 1)",abort=False),(1,"",f""))

# Input for failing test (raise exception): exit 1 from a subshell
self.assertRaises(Exception,common.execute,f"(exit 1)",abort=True)

def test_split_var_name_and_array_reference(self):
"""Test split_var_name_and_array_reference() function"""

Expand Down