annotate scripts/vimutil.py @ 4:ae0fb567f459

Report error but don't crash when a solution points to a missing project.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 24 Oct 2019 11:15:37 -0700
parents 5d2c0db51914
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import io
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import sys
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 def runscript(scriptfunc, *args):
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 """ Executes a given function with the given args. This is because
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 the convention is that all python scripts here should have a `main`
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 function that takes a custom list of args to override the default
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 behaviour of using `sys.args`.
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 """
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 prevout = sys.stdout
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 captured = io.StringIO()
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 sys.stdout = captured
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 try:
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 scriptfunc(args)
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 finally:
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 sys.stdout = prevout
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 return captured.getvalue()
5d2c0db51914 Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19