Skip to content
Snippets Groups Projects
Commit ba3efd8a authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

normalize-usercode: try block

parent e1b87dac
No related branches found
No related tags found
No related merge requests found
......@@ -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__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment