-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
executable file
·63 lines (50 loc) · 1.65 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
#!/usr/bin/env python
from os import mkdir
from os import rename
from os import symlink
from os.path import expanduser
from os.path import islink
from os.path import exists
VERSION = '0.1.0'
DESC = 'Creates symlinks from the home directory to the dotfiles repo. TODO: ZSH stuff'
FORMAT = '%(asctime)s %(levelname)s %(message)s'
HOME = expanduser('~')
DIR = 'dotfiles'
BACKUPDIR = 'dotfiles_old'
files = ['vimrc', 'vim', 'zshrc', 'oh-my-zsh', 'irssi', 'tmux.conf', 'lynx.cfg', 'ackrc']
def main():
makeBackupDir()
filesToBackup = {}
filesToLink = {}
for f in files:
filePath = HOME + '/.' + f
if not exists(filePath):
filesToLink[f] = filePath
else:
if not islink(filePath):
filesToLink[f] = filePath
backupCurrent(f, filePath)
if (len(filesToLink) > 0):
fileList = ', .'.join(filesToLink)
print 'These files are not yet symlinked to your dotfiles: .' + fileList
print 'Moving them to ' + HOME + '/' + BACKUPDIR
print 'Creating symlinks to version in your dotfiles repo'
for key in filesToLink:
createSymlink(key, filesToLink[key])
print 'Done!'
else:
print 'All dotfiles already symlinked. Nothing to do.'
def makeBackupDir():
backup = HOME + '/' + BACKUPDIR
if not exists(backup):
print 'Creating backup directory ' + backup
mkdir(backup)
def backupCurrent(fileName, filePath):
dest = HOME + '/' + BACKUPDIR + '/.' + fileName
rename(filePath, dest)
def createSymlink(fileName, filePath):
src = HOME + '/' + DIR + '/' + fileName
dest = HOME + '/.' + fileName
symlink(src, dest)
if __name__ == '__main__':
main()