-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
49 lines (39 loc) · 1.57 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
import os, os.path, re, shutil, time
config_dir = os.path.split(os.path.realpath(__file__))[0]
def link_in_home(from_file, to_file):
from_file = os.path.join(config_dir, from_file)
to_file = os.path.join(home_dir, to_file)
try:
# delete any existing file
if os.path.lexists(to_file):
os.unlink(to_file)
os.symlink(from_file, to_file)
except OSError as e:
print to_file, 'cannot be replaced'
print e
print 'Linked %s to %s' % (from_file, to_file)
def insert_text_in_file(filename, text, comment_char):
try:
f_str = open(filename, 'rw').read()
if not re.search(r'JDB', f_str):
print 'Adding custom text to %s' % filename
shutil.copy(filename, filename + '.bak_%f' % time.time())
f = open(filename, 'a')
print >> f, ''
print >> f, comment_char * 78
print >> f, '%s Added by my setup script - SHY' % comment_char
print >> f, text
print >> f, comment_char * 78
f.close()
except:
print 'Unable to add custom text to %s' % filename
if __name__ == '__main__':
home_dir = os.path.expanduser('~')
print 'Home dir: %s' % home_dir
print 'Config dir: %s' % config_dir
# make symlinks in home directory to config files
link_in_home('tmux/tmux.conf', '.tmux.conf')
# have bash call my stuff on startup
bashrc_filename = os.path.join(home_dir, '.bashrc')
text = 'source %s' % os.path.join(home_dir, 'config/bash/bashrc')
insert_text_in_file(bashrc_filename, text, '#')