Module: check_mk
Branch: master
Commit: 5bb81552428f7524997b96d3aef33be7364453e9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5bb81552428f75…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jul 8 10:17:01 2015 +0200
Added draft of code indenting script
---
doc/helpers/fix_newlines_before_def | 43 +++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/doc/helpers/fix_newlines_before_def b/doc/helpers/fix_newlines_before_def
new file mode 100755
index 0000000..e039433
--- /dev/null
+++ b/doc/helpers/fix_newlines_before_def
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+# Tries to enforce exactly two newlines before a function definition.
+# Beware: This is not yet optimal. Do not use it yet.
+
+import sys, os, re
+
+
+if "--debug" in sys.argv:
+ opt_debug = True
+ sys.argv.remove("--debug")
+else:
+ opt_debug = False
+
+
+def main():
+ for filename in sys.argv[1:]:
+ try:
+ sys.stdout.write("%s..." % filename)
+ sys.stdout.flush()
+ something_changed = cleanup_indentation_style(filename)
+ sys.stdout.write(something_changed and "done.\n" or
"unchanged.\n")
+
+ except Exception, e:
+ sys.stdout.write("ERROR: %s\n" % e)
+ if opt_debug:
+ raise
+
+
+def cleanup_indentation_style(filename):
+ content = file(filename).read()
+ new_content = content
+ new_content = fix_two_empty_lines_before_indented_commented_def(new_content)
+ if new_content != content:
+ file(filename, "w").write(new_content)
+ return True
+ else:
+ return False
+
+def fix_two_empty_lines_before_indented_commented_def(content):
+ return re.sub(r"\n+(([ \t]*#[^\n]*\n)*)(\s*)def ", r"\n\n\n\1\3def
", content)
+
+main()