diff scripts/vimutil.py @ 0:5d2c0db51914

Initial commit
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 17 Sep 2019 13:24:24 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/vimutil.py	Tue Sep 17 13:24:24 2019 -0700
@@ -0,0 +1,19 @@
+import io
+import sys
+
+
+def runscript(scriptfunc, *args):
+    """ Executes a given function with the given args. This is because
+        the convention is that all python scripts here should have a `main`
+        function that takes a custom list of args to override the default
+        behaviour of using `sys.args`.
+    """
+    prevout = sys.stdout
+    captured = io.StringIO()
+    sys.stdout = captured
+    try:
+        scriptfunc(args)
+    finally:
+        sys.stdout = prevout
+    return captured.getvalue()
+