-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot.py
More file actions
executable file
·90 lines (70 loc) · 2.26 KB
/
Copy pathdot.py
File metadata and controls
executable file
·90 lines (70 loc) · 2.26 KB
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
88
89
90
#!/usr/bin/env python
import os, sys
import shutil
HOME = os.getenv("HOME")
os.system("git submodule update --init --recursive")
def backup():
pass
def install():
current_folder = os.path.abspath(os.path.dirname(__file__))
print "Installing from %s" % current_folder
print
c = 0
for dirname, dirnames, filenames in os.walk(current_folder):
if "/.git" in dirname: continue
for subdirname in dirnames:
if subdirname.endswith(".symlink"):
src = os.path.join(dirname, subdirname)
dst = os.path.join(HOME, "." + subdirname[:-8])
if os.path.islink(dst):
print "Link exists, removing %s" % dst
os.unlink(dst)
elif os.path.exists(dst):
print "Folder exists, removing %s" % dst
shutil.rmtree(dst)
c = c + 1
os.symlink(src, dst)
print "[%d]\t%s -> %s" % (c, dst, src)
for filename in filenames:
if filename.endswith(".symlink"):
src = os.path.join(dirname, filename)
dst = os.path.join(HOME, "." + filename[:-8])
if os.path.islink(dst):
print "Link exists, removing %s" % dst
os.unlink(dst)
elif os.path.exists(dst):
print "File exists, removing %s" % dst
os.unlink(dst)
c = c + 1
os.symlink(src, dst)
print "[%d]\t%s -> %s" % (c, dst, src)
def uninstall():
pass
def restore():
pass
def clone():
pass
COMMANDS = {
"install": {
"description": "Install dot files",
"func": install,
},
"uninstall": {
"description": "Uninstall dot files"
},
"clone": {
"description": "Creates a real copy of the dot files"
}
}
def usage():
print "Usage: ./dot.py command [options]"
sys.exit(1)
def main():
if len(sys.argv) < 2:
usage()
if sys.argv[1] not in COMMANDS:
print "ERROR: Command '%s' not found" % sys.argv[1]
usage()
COMMANDS.get(sys.argv[1])['func']()
if __name__ == '__main__':
main()