forked from drmikehenry/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·52 lines (43 loc) · 1.14 KB
/
setup.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
#!/usr/bin/env python
import os
import re
import sys
from subprocess import Popen, PIPE, STDOUT
class RunError(Exception):
pass
def runArgsOutErr(args):
p = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
return out, err
def runArgs(args):
out, err = runArgsOutErr(args)
if err:
raise RunError("%s" % str(args))
return out
def joinLines(lines):
return "".join([line + "\n" for line in lines])
def readLines(path):
f = open(path, "r")
lines = f.read().splitlines()
f.close()
return lines
def writeLines(path, lines):
f = open(path, "w")
f.write(joinLines(lines))
f.close()
def main():
homePath = os.path.expanduser("~")
vimrcPath = os.path.join(homePath, ".vimrc")
if os.path.isfile(vimrcPath):
vimrcLines = readLines(vimrcPath)
else:
vimrcLines = []
runtimeLine = "runtime vimrc"
for line in vimrcLines:
if re.match(r'(\s*"\s*)?' + re.escape(runtimeLine) + r"\s*$", line):
break
else:
vimrcLines.insert(0, runtimeLine)
writeLines(vimrcPath, vimrcLines)
if __name__ == '__main__':
main()