- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathsymlink.py
29 lines (25 loc) · 862 Bytes
/
symlink.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
#!/usr/bin/env python3
importos
importsubprocess
importsys
iflen(sys.argv) <3:
print('Too few args to '+sys.argv[0])
print('Usage: symlink.py <link_points_to> <link_path> [--dir | --file]')
sys.exit(1)
points_to=sys.argv[1]
link_path=sys.argv[2]
ifsys.platform=='win32':
points_to=points_to.replace('/', '\\')
link_path=link_path.replace('/', '\\')
iflen(sys.argv) >=4andsys.argv[3] =='--dir':
is_dir=True
eliflen(sys.argv) >=4andsys.argv[3] =='--file':
is_dir=False
else:
is_dir=os.path.isdir(sys.argv[1])
# Windows symlink support was introduced in python 3.2
subprocess.check_call(['cmd.exe', '/C',
'mklink '+ ('/D'ifis_direlse''),
link_path, points_to])
else:
os.symlink(points_to, link_path)