def execute_tester(submission): base_dir = os.path.dirname(__file__) s_cmd = submission.command s_id = submission.id (s_path, s_pkg_name) = os.path.split(submission.package.path) # Move to the submission directory os.chdir(s_path) s_split = s_cmd.split() if len(s_split) == 1: # This is run.sh or run.py so add exec permissions os.chmod( os.path.join(s_path, s_split[0]), stat.S_IEXEC | stat.S_IREAD ) for test in TEST_FILE_NAMES: map_path = os.path.join( base_dir, '../static/maps', test) result_file_name = os.path.join( s_path, test + '_' + RESULT_JSON_FILE_NAME) if not os.path.exists(result_file_name): open(result_file_name, 'w').close() cmd = [ 'python2.7', base_dir + '/../bin/simulator/main.py', '-c', '--map', map_path, '--robot', s_cmd, '--output', result_file_name ] proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() # Log testing process here print s_id, 'stderr', stderr # Log result lines = stdout.splitlines() result = json.load(open(result_file_name)) db_result = Result() db_result.submission_id = s_id db_result.report = json.dumps(result) print s_id, 'report', db_result.report db_result.log = stdout + stderr db_result.save() print '\n\nResult saved.\n\n'
def execute_tester(submission): base_dir = os.path.dirname(__file__) s_cmd = submission.command s_id = submission.id (s_path, s_pkg_name) = os.path.split(submission.package.path) # Move to the submission directory os.chdir(s_path) s_split = s_cmd.split() if len(s_split) == 1: # This is run.sh or run.py so add exec permissions os.chmod(os.path.join(s_path, s_split[0]), stat.S_IEXEC | stat.S_IREAD) for test in TEST_FILE_NAMES: map_path = os.path.join(base_dir, '../static/maps', test) result_file_name = os.path.join(s_path, test + '_' + RESULT_JSON_FILE_NAME) if not os.path.exists(result_file_name): open(result_file_name, 'w').close() cmd = [ 'python2.7', base_dir + '/../bin/simulator/main.py', '-c', '--map', map_path, '--robot', s_cmd, '--output', result_file_name ] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() # Log testing process here print s_id, 'stderr', stderr # Log result lines = stdout.splitlines() result = json.load(open(result_file_name)) db_result = Result() db_result.submission_id = s_id db_result.report = json.dumps(result) print s_id, 'report', db_result.report db_result.log = stdout + stderr db_result.save() print '\n\nResult saved.\n\n'
def execute_tester(submission): try: (s_path, s_pkg_name) = os.path.split(submission.package.path) # Move to the submission directory os.chdir(s_path) s_cmd = './run.sh' if not os.path.exists(s_cmd): s_cmd = './run.py' if not os.path.exists(s_cmd): db_result = Result() db_result.submission = submission db_result.report = json.dumps( {'service_error': 'Brakuje `run.sh` lub `run.py`!'}) db_result.log = '' db_result.save() return submission.command = s_cmd submission.save() s_cmd = os.path.join(s_path, s_cmd) os.chmod(s_cmd, stat.S_IEXEC | stat.S_IREAD) for test_suite in TEST_SUITES: print "Running simulator for test suite: {}".format(test_suite) map_path = os.path.join(settings.STATIC_ROOT, 'maps', test_suite['map']) result_file_name = os.path.join( s_path, test_suite['map'] + '_' + RESULT_JSON_FILE_NAME) if not os.path.exists(result_file_name): open(result_file_name, 'w').close() cmd = [ 'python2.7', os.path.join(settings.BIN_DIR, 'simulator/main.py'), '-c', '--map', map_path, '--robot', s_cmd, '--output', result_file_name, '--steering_noise', str(test_suite['steering_noise']), '--distance_noise', str(test_suite['distance_noise']), '--forward_steering_drift', str(test_suite['forward_steering_drift']) ] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() # Log testing process here print submission.id, 'stderr', stderr # Log result lines = stdout.splitlines() result = json.load(open(result_file_name)) db_result = Result() db_result.submission = submission db_result.report = json.dumps(result) print submission.id, 'report', db_result.report db_result.log = stdout + stderr db_result.save() print '\n\nResult saved.\n\n' except Exception as error: report = 'Blad wewnetrzny testerki: ' + str(error) print 'ERROR:', report db_result = Result() db_result.submission = submission db_result.report = json.dumps({'service_error': report}) db_result.log = '' db_result.save()
def execute_tester(submission): try: (s_path, s_pkg_name) = os.path.split(submission.package.path) # Move to the submission directory os.chdir(s_path) s_cmd = './run.sh' if not os.path.exists(s_cmd): s_cmd = './run.py' if not os.path.exists(s_cmd): db_result = Result() db_result.submission = submission db_result.report = json.dumps( {'service_error': 'Brakuje `run.sh` lub `run.py`!'}) db_result.log = '' db_result.save() return submission.command = s_cmd submission.save() s_cmd = os.path.join(s_path, s_cmd) os.chmod(s_cmd, stat.S_IEXEC | stat.S_IREAD) for test_suite in TEST_SUITES: print "Running simulator for test suite: {}".format(test_suite) map_path = os.path.join( settings.STATIC_ROOT, 'maps', test_suite['map']) result_file_name = os.path.join( s_path, test_suite['map'] + '_' + RESULT_JSON_FILE_NAME) if not os.path.exists(result_file_name): open(result_file_name, 'w').close() cmd = [ 'python2.7', os.path.join(settings.BIN_DIR, 'simulator/main.py'), '-c', '--map', map_path, '--robot', s_cmd, '--output', result_file_name, '--steering_noise', str(test_suite['steering_noise']), '--distance_noise', str(test_suite['distance_noise']), '--forward_steering_drift', str(test_suite['forward_steering_drift']) ] proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() # Log testing process here print submission.id, 'stderr', stderr # Log result lines = stdout.splitlines() result = json.load(open(result_file_name)) db_result = Result() db_result.submission = submission db_result.report = json.dumps(result) print submission.id, 'report', db_result.report db_result.log = stdout + stderr db_result.save() print '\n\nResult saved.\n\n' except Exception as error: report = 'Blad wewnetrzny testerki: ' + str(error) print 'ERROR:', report db_result = Result() db_result.submission = submission db_result.report = json.dumps({'service_error': report}) db_result.log = '' db_result.save()