forked from b-ryan/powerline-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·49 lines (40 loc) · 1.47 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
#!/usr/bin/env python
from __future__ import print_function
import os
import stat
try:
import config
except ImportError:
print('Created personal config.py for your customizations')
import shutil
shutil.copyfile('config.py.dist', 'config.py')
import config
TEMPLATE_FILE = 'powerline_shell_base.py'
OUTPUT_FILE = 'powerline-shell.py'
SEGMENTS_DIR = 'segments'
THEMES_DIR = 'themes'
def load_source(srcfile):
try:
return ''.join(open(srcfile).readlines()) + '\n\n'
except IOError:
print('Could not open', srcfile)
return ''
if __name__ == "__main__":
source = load_source(TEMPLATE_FILE)
source += load_source(os.path.join(THEMES_DIR, 'default.py'))
if config.THEME != 'default':
source += load_source(os.path.join(THEMES_DIR, config.THEME + '.py'))
for segment in config.SEGMENTS:
source += load_source(os.path.join(SEGMENTS_DIR, segment + '.py'))
# assumes each segment file will have a function called
# add_segment__[segment] that accepts the powerline object
source += 'add_{}_segment(powerline)\n'.format(segment)
source += 'sys.stdout.write(powerline.draw())\n'
try:
open(OUTPUT_FILE, 'w').write(source)
st = os.stat(OUTPUT_FILE)
os.chmod(OUTPUT_FILE, st.st_mode | stat.S_IEXEC)
print(OUTPUT_FILE, 'saved successfully')
except IOError:
print('ERROR: Could not write to powerline-shell.py. Make sure it is writable')
exit(1)