Module: check_mk
Branch: master
Commit: 7e3925cf146c988ecb5f1b473ed31294a94af87f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7e3925cf146c98…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Thu Dec 15 14:12:26 2016 +0100
Set state to master.
Change-Id: Ida0de3713621a1b2c0ee7bbaff167627ee601c5f
---
tests/web/auto_refactor.py | 57 +++++++++++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/tests/web/auto_refactor.py b/tests/web/auto_refactor.py
index e72a547..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)
@@ -180,30 +180,41 @@ def replace_tags(html, indent = 0):
if "[[[%s]]]" % index in html:
html = re.sub("[[[%s]]]" % index, input, html)
- return orig_html + "\n(new)" + html + "\n" + rest
+ try:
+ return orig_html + "\n(new)" + html + "\n" + rest
+ except:
+ print "orig_html:\n", orig_html
+ print "__________________________________________"
+ print "html:\n", html
+ print "__________________________________________"
+ print "rest:\n", rest
+ 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)