From ba3efd8abd467278ae087a1edcbba90b70d3bd4c Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Tue, 24 Nov 2020 22:30:13 +0100 Subject: [PATCH] normalize-usercode: try block --- devtools/code-tools/normalize-usercode.py | 44 ++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/devtools/code-tools/normalize-usercode.py b/devtools/code-tools/normalize-usercode.py index 6c59226830f..804ec30e210 100755 --- a/devtools/code-tools/normalize-usercode.py +++ b/devtools/code-tools/normalize-usercode.py @@ -19,26 +19,30 @@ def normalize_text(ti, fname): return t def normalize_file(fname, inplace): - with open(fname, 'rb') as f: - ti = f.read() - t = normalize_text(ti, fname) - if t == ti: - print(f'Nothing changed in file {fname}') - return - t2 = normalize_text(t, fname) - if t2 != t: - with open("out1.py", 'w') as f: - f.write(t) - with open("out2.py", 'w') as f: - f.write(t2) - exit("Script changes under second normalization, see files out1.py and out2.py") - - if inplace: - with open(fname, 'w') as f: - f.write(t) - print(f'Normalized file {fname}') - else: - print(t) + try: + with open(fname, 'rb') as f: + ti = f.read() + t = normalize_text(ti, fname) + if t == ti: + print(f'Nothing changed in file {fname}') + return + t2 = normalize_text(t, fname) + if t2 != t: + with open("out1.py", 'w') as f: + f.write(t) + with open("out2.py", 'w') as f: + f.write(t2) + exit("Script changes under second normalization, see files out1.py and out2.py") + + if inplace: + with open(fname, 'w') as f: + f.write(t) + print(f'Normalized file {fname}') + else: + print(t) + except Exception as e: + print(f'Failed for file {fname}: {e}') + if __name__ == '__main__': -- GitLab