forked from ycm-core/lsp-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·87 lines (67 loc) · 2.14 KB
/
install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
import os
import argparse
import subprocess
import contextlib
import sys
import platform
DIR_OF_THIS_SCRIPT = os.path.dirname( os.path.abspath( __name__ ) )
parser = argparse.ArgumentParser()
def OnWindows():
return platform.system() == 'Windows'
@contextlib.contextmanager
def TemporaryWorkingDirectory( d ):
old_d = os.getcwd()
print( '*** Entering direcory ' + d + ' *** ' )
try:
os.chdir( d )
yield
finally:
os.chdir( old_d )
parser.add_argument( '--all', action='store_true' )
for d in os.listdir( DIR_OF_THIS_SCRIPT ):
dirname = os.path.join( DIR_OF_THIS_SCRIPT, d )
if os.path.isdir( dirname ):
parser.add_argument( '--enable-' + d, action='store_true' )
parser.add_argument( '--disable-' + d, action='store_true' )
args = parser.parse_args()
done = []
failed = []
for d in os.listdir( DIR_OF_THIS_SCRIPT ):
dirname = os.path.join( DIR_OF_THIS_SCRIPT, d )
if not os.path.isdir( dirname ):
continue
if not args.all and not getattr( args, 'enable_' + d ):
continue
if getattr( args, 'disable_' + d ):
continue
try:
with TemporaryWorkingDirectory( dirname ):
if not OnWindows() and os.path.exists( 'install' ):
subprocess.check_call( [ 'bash', 'install' ] )
elif os.path.exists( 'install.py' ):
subprocess.check_call( [ sys.executable, 'install.py' ] )
done.append( d )
except Exception:
failed.append( d )
vimrc = ''
if done:
print( "** SUCCEEDED **: {}".format( ', '.join( done ) ) )
vimrc = f"""
let g:ycm_lsp_dir = '{ DIR_OF_THIS_SCRIPT }'
let g:ycm_language_server = []
"""
for d in done:
snippet = os.path.join( DIR_OF_THIS_SCRIPT, d, 'snippet.vim' )
if os.path.exists( snippet ):
with open( snippet, 'r' ) as f:
vimrc += f.read()
if failed:
print( "** FAILED **: {}".format( ', '.join( failed ) ) )
if not ( done + failed ):
parser.print_help()
if vimrc:
with open( os.path.join( DIR_OF_THIS_SCRIPT, 'vimrc.generated' ), 'w' ) as f:
f.write( vimrc )
print( "OK, now add the following to your vimrc:\n" )
print( f"source { os.path.join( DIR_OF_THIS_SCRIPT, 'vimrc.generated' ) }" )