Skip to content

Commit ca6bfe0

Browse files
committed
Review comments: Add a child logger, close json file after reading, minor
formatting updates.
1 parent e3dbb82 commit ca6bfe0

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

tools/check_release.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def get_compilation_failure(messages):
110110
continue
111111

112112
if msg_type == 'error' or msg_type == 'tool_error':
113-
logging.error(message)
113+
rel_log.error(message)
114114
return "Error"
115115
else:
116-
logging.debug(message)
116+
rel_log.debug(message)
117117

118118
return "Internal"
119119

@@ -134,26 +134,26 @@ def invoke_api(payload, url, auth, polls, begin="start/"):
134134
"""
135135

136136
# send task to api
137-
logging.debug(url + begin + "| data: " + str(payload))
137+
rel_log.debug(url + begin + "| data: " + str(payload))
138138
r = requests.post(url + begin, data=payload, auth=auth)
139-
logging.debug(r.request.body)
139+
rel_log.debug(r.request.body)
140140

141141
if r.status_code != 200:
142-
logging.error("HTTP code %d reported.", r.status_code)
142+
rel_log.error("HTTP code %d reported.", r.status_code)
143143
return False, "Internal"
144144

145145
response = r.json()
146-
logging.debug(response)
146+
rel_log.debug(response)
147147
uuid = response['result']['data']['task_id']
148-
logging.debug("Task accepted and given ID: %s", uuid)
148+
rel_log.debug("Task accepted and given ID: %s", uuid)
149149
result = False
150150
fail_type = None
151151

152152
# It currently seems to take the onlide IDE API ~30s to process the compile
153153
# request and provide a response. Set the poll time to half that in case it
154154
# does manage to compile quicker.
155155
poll_delay = 15
156-
logging.debug("Running with a poll for response delay of: %ss", poll_delay)
156+
rel_log.debug("Running with a poll for response delay of: %ss", poll_delay)
157157

158158
# poll for output
159159
for check in range(polls):
@@ -169,15 +169,15 @@ def invoke_api(payload, url, auth, polls, begin="start/"):
169169
# 3) Internal failure of the online compiler
170170
result = bool(data['compilation_success'])
171171
if result:
172-
logging.info("\t\tCompilation SUCCESSFUL\n")
172+
rel_log.info("COMPILATION SUCCESSFUL\n")
173173
else:
174174
# Did this fail due to a genuine compilation error or a failue of
175175
# the api itself ?
176-
logging.info("\t\tCompilation FAILURE\n")
176+
rel_log.info("COMPILATION FAILURE\n")
177177
fail_type = get_compilation_failure(data['new_messages'])
178178
break
179179
else:
180-
logging.info("\t\tCompilation FAILURE\n")
180+
rel_log.info("COMPILATION FAILURE\n")
181181

182182
if not result and fail_type == None:
183183
fail_type = "Internal"
@@ -219,11 +219,11 @@ def run_cmd(command, exit_on_failure=False):
219219
Returns:
220220
result - True/False indicating the success/failure of the command
221221
"""
222-
logging.debug('[Exec] %s', ' '.join(command))
222+
rel_log.debug('[Exec] %s', ' '.join(command))
223223
return_code = subprocess.call(command, shell=True)
224224

225225
if return_code:
226-
logging.warning("The command '%s' failed with return code: %s",
226+
rel_log.warning("The command '%s' failed with return code: %s",
227227
(' '.join(command), return_code))
228228
if exit_on_failure:
229229
sys.exit(1)
@@ -245,13 +245,13 @@ def run_cmd_with_output(command, exit_on_failure=False):
245245
result - True/False indicating the success/failure of the command
246246
output - The output of the command if it was successful, else empty string
247247
"""
248-
logging.debug('[Exec] %s', ' '.join(command))
248+
rel_log.debug('[Exec] %s', ' '.join(command))
249249
returncode = 0
250250
output = ""
251251
try:
252252
output = subprocess.check_output(command, shell=True)
253253
except subprocess.CalledProcessError as e:
254-
logging.warning("The command '%s' failed with return code: %s",
254+
rel_log.warning("The command '%s' failed with return code: %s",
255255
(' '.join(command), e.returncode))
256256
returncode = e.returncode
257257
if exit_on_failure:
@@ -273,15 +273,15 @@ def upgrade_test_repo(test, user, library, ref, repo_path):
273273
Returns:
274274
updated - True if library was updated, False otherwise
275275
"""
276-
logging.info("Updating test repo: '%s' to SHA: %s", test, ref)
276+
rel_log.info("Updating test repo: '%s' to SHA: %s", test, ref)
277277
cwd = os.getcwd()
278278

279279
repo = "https://" + user + '@developer.mbed.org/users/' + user + '/code/' + test
280280

281281
# Clone the repo if it doesn't already exist
282282
path = abspath(repo_path + '/' + test)
283283
if not os.path.exists(path):
284-
logging.info("Test repo doesn't exist, cloning...")
284+
rel_log.info("Test repo doesn't exist, cloning...")
285285
os.chdir(abspath(repo_path))
286286
clone_cmd = ['hg', 'clone', repo]
287287
run_cmd(clone_cmd, exit_on_failure=True)
@@ -300,7 +300,7 @@ def upgrade_test_repo(test, user, library, ref, repo_path):
300300

301301
os.rename(lib_file, bak_file)
302302
else:
303-
logging.error("!! Failure to backup lib file prior to updating.")
303+
rel_log.error("Failure to backup lib file prior to updating.")
304304
return False
305305

306306
# mbed 2 style lib file contains one line with the following format
@@ -338,7 +338,7 @@ def upgrade_test_repo(test, user, library, ref, repo_path):
338338
run_cmd(cmd, exit_on_failure=True)
339339

340340
except:
341-
logging.info("Lib file already up to date and thus nothing to commit")
341+
rel_log.info("Lib file already up to date and thus nothing to commit")
342342

343343
os.chdir(cwd)
344344
return updated
@@ -395,12 +395,11 @@ def get_latest_library_versions(repo_path):
395395
return mbed, mbed_dev
396396

397397
def log_results(lst, title):
398-
logging.info(title)
399398
if len(lst) == 0:
400-
logging.info("\tNone\n")
399+
rel_log.info("%s - None", title)
401400
else:
402401
for entry in lst:
403-
logging.info("\tTest: %s, Target: %s\n", entry[0], entry[1])
402+
rel_log.info("%s - Test: %s, Target: %s", title, entry[0], entry[1])
404403

405404

406405
if __name__ == '__main__':
@@ -417,11 +416,12 @@ def log_results(lst, title):
417416

418417
# Set logging level
419418
logging.basicConfig(level=level)
419+
rel_log = logging.getLogger("check-release")
420420

421421
# Read configuration data
422-
json_data = json.load(open(os.path.join(os.path.dirname(__file__),
423-
"check_release.json")))
424-
422+
with open(os.path.join(os.path.dirname(__file__), "check_release.json")) as config:
423+
json_data = json.load(config)
424+
425425
supported_targets = []
426426

427427
if len(json_data["target_list"]) > 0:
@@ -452,11 +452,11 @@ def log_results(lst, title):
452452
mbed, mbed_dev = get_latest_library_versions(repo_path)
453453

454454
if not mbed or not mbed_dev:
455-
logging.error("Could not obtain latest versions of library files!!")
455+
rel_log.error("Could not obtain latest versions of library files!!")
456456
exit(1)
457457

458-
logging.info("Latest mbed lib version = %s", mbed)
459-
logging.info("Latest mbed-dev lib version = %s", mbed_dev)
458+
rel_log.info("Latest mbed lib version = %s", mbed)
459+
rel_log.info("Latest mbed-dev lib version = %s", mbed_dev)
460460

461461
# First update test repos to latest versions of their embedded libraries
462462
for test in test_list:
@@ -473,10 +473,10 @@ def log_results(lst, title):
473473

474474
# Compile each test for each supported target
475475
for test in tests:
476-
logging.info("Test compiling program: %s\n", test)
476+
rel_log.info("COMPILING PROGRAM: %s\n", test)
477477
for target in supported_targets:
478478
for retry in range(0, retries):
479-
logging.info("\tCompiling target: %s , attempt %u\n", target, retry)
479+
rel_log.info("COMPILING TARGET: %s , attempt %u\n", target, retry)
480480
result, mesg = build_repo(target, test, user, password)
481481
if not result:
482482
if mesg == 'Internal':
@@ -490,19 +490,19 @@ def log_results(lst, title):
490490
passes += (int)(result)
491491
break
492492
else:
493-
logging.error("\t\tCompilation failed due to internal errors.\n")
494-
logging.error("\t\tSkipping test/target combination!\n")
493+
rel_log.error("Compilation failed due to internal errors.\n")
494+
rel_log.error("Skipping test/target combination!\n")
495495
total -= 1
496496
skipped.append([test, target])
497497

498-
logging.info(" SUMMARY OF COMPILATION RESULTS")
499-
logging.info(" ------------------------------\n")
500-
logging.info(" NUMBER OF TEST APPS: %d, NUMBER OF TARGETS: %d\n",
498+
rel_log.info(" SUMMARY OF COMPILATION RESULTS")
499+
rel_log.info(" ------------------------------")
500+
rel_log.info(" NUMBER OF TEST APPS: %d, NUMBER OF TARGETS: %d\n",
501501
len(tests), len(supported_targets))
502-
log_results(failures, " FAILURES:\n")
503-
log_results(skipped, " SKIPPED:\n")
502+
log_results(failures, " FAILED")
503+
log_results(skipped, " SKIPPED")
504504

505505
# Output a % pass rate, indicate a failure if not 100% successful
506506
pass_rate = (float(passes) / float(total)) * 100.0
507-
logging.info(" PASS RATE %.1f %%\n", pass_rate)
507+
rel_log.info(" PASS RATE %.1f %%\n", pass_rate)
508508
sys.exit(not (pass_rate == 100))

0 commit comments

Comments
 (0)