Module: check_mk
Branch: master
Commit: 8c79627c3052e596d8ba73f4695fe2debf81f739
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8c79627c3052e5…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Mon Oct 31 14:53:09 2016 +0100
Fixed bug in autorefactor.
---
tests/web/auto_refactor.py | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/tests/web/auto_refactor.py b/tests/web/auto_refactor.py
index 144ed74..80938a4 100644
--- a/tests/web/auto_refactor.py
+++ b/tests/web/auto_refactor.py
@@ -67,6 +67,17 @@ def split_html(text):
index += 1
return text[:index], text[index:]
+
+def stripper(x):
+ x = re.sub(r' %\s+\(.*', '', x)
+ index = len(x) - 1
+ while index >= 0 and x[index] in ['n', ' ', ')',
'"', '\'']:
+ if x[index] == 'n' and index > 0 and x[index - 1] == '\\':
+ index -= 1
+ index -= 1
+ return x[:index+1]
+
+
# this function does a big chunk of the refactoring for me
def replace_tags(html, indent = 0):
@@ -81,6 +92,9 @@ def replace_tags(html, indent = 0):
html, rest = split_html(html)
orig_html = html
+ # strip all comments
+ html = re.sub(r'#.*', '', html)
+
if len(html.split(" % ")) == 2:
html, string_input = html.split(" % ")
string_input =
string_input.lstrip("(").rstrip("$").rstrip("\n").rstrip('
').rstrip(")")
@@ -93,7 +107,7 @@ def replace_tags(html, indent = 0):
return orig_html + rest
inbetween = re.split(r'<[^<]*>',
re.sub(r'\s*html\.write\([\'|"]?', '', html, 1))
- inbetween[-1] = ''.join(list(reversed(re.sub(r'\n\)["|\']',
'', ''.join(list(reversed(inbetween[-1]))), count=1))))
+ inbetween = map(stripper, inbetween)
html = orig_html + "\n(new)"
@@ -115,7 +129,7 @@ def replace_tags(html, indent = 0):
if not skip_next and inbetween[counter].strip(' ') not in ['',
'\n']:
html = append_to_html(html, indent, "html.write(%s)" %
inbetween[counter])
- return html + rest + "\n(/new)"
+ return html + "\n(/new)" + rest
import re