Module: check_mk
Branch: master
Commit: 50fe58790a3483c3d470d4c004cd3bfe57ee31ff
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=50fe58790a3483…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Thu Dec 15 13:45:15 2016 +0100
Autorefactor: repaired bracket count.
Change-Id: I2cd274aed4c7e0cca7106df22f9c4a2fe58eabc6
---
tests/web/auto_refactor.py | 46 ++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/tests/web/auto_refactor.py b/tests/web/auto_refactor.py
index 7660e65..895ff96 100644
--- a/tests/web/auto_refactor.py
+++ b/tests/web/auto_refactor.py
@@ -125,13 +125,13 @@ def test_replace_inputs():
# this function does a big chunk of the refactoring for me
def replace_tags(html, indent = 0):
-
# I want to refactor only lines with html.write
if not html.lstrip(' ').startswith('html.write('):
return html
# unbalanced paranthesis indicates sth that goes across line border
- if html.count('(') != html.count(')'):
+ no_comments = '\n'.join(re.sub('#.*', '', line) for line in
html.split('\n'))
+ if no_comments.count('(') != no_comments.count(')'):
return html
html, rest = split_html(html)
@@ -192,27 +192,29 @@ def replace_tags(html, indent = 0):
return orig_html + "\n(new)" + html + "\n" + rest
-import re
-html = sys.argv[1]
-if html.endswith('.py'):
- whole_text = ''
- with open(html, 'r') as rfile:
- whole_text = "".join(line for line in rfile)
- parts = whole_text.split("html.write(")
- with open("refactored_file.py", "w") as wfile:
- part = parts.pop(0)
- wfile.write(part)
- indent = 0
- while indent < len(part) and part[len(part) - 1 - indent] == ' ':
- indent += 1
- for part in parts:
- part = "html.write(" + part
- wfile.write(replace_tags(part, indent))
+
+if __name__ == "__main__":
+
+ html = sys.argv[1]
+ if html.endswith('.py'):
+ whole_text = ''
+ with open(html, 'r') as rfile:
+ whole_text = "".join(line for line in rfile)
+ parts = whole_text.split("html.write(")
+ with open("refactored_file.py", "w") as wfile:
+ part = parts.pop(0)
+ wfile.write(part)
indent = 0
while indent < len(part) and part[len(part) - 1 - indent] == ' ':
indent += 1
-elif html == "test":
- test_replace_inputs()
-else:
- print replace_tags(html)
+ for part in parts:
+ part = "html.write(" + part
+ wfile.write(replace_tags(part, indent))
+ indent = 0
+ while indent < len(part) and part[len(part) - 1 - indent] == '
':
+ indent += 1
+ elif html == "test":
+ test_replace_inputs()
+ else:
+ print replace_tags(html)