Mercurial > vim-crosoft
comparison scripts/vimutil.py @ 0:5d2c0db51914
Initial commit
| author | Ludovic Chabant <ludovic@chabant.com> |
|---|---|
| date | Tue, 17 Sep 2019 13:24:24 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:5d2c0db51914 |
|---|---|
| 1 import io | |
| 2 import sys | |
| 3 | |
| 4 | |
| 5 def runscript(scriptfunc, *args): | |
| 6 """ Executes a given function with the given args. This is because | |
| 7 the convention is that all python scripts here should have a `main` | |
| 8 function that takes a custom list of args to override the default | |
| 9 behaviour of using `sys.args`. | |
| 10 """ | |
| 11 prevout = sys.stdout | |
| 12 captured = io.StringIO() | |
| 13 sys.stdout = captured | |
| 14 try: | |
| 15 scriptfunc(args) | |
| 16 finally: | |
| 17 sys.stdout = prevout | |
| 18 return captured.getvalue() | |
| 19 |
