-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·41 lines (33 loc) · 1.12 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# © 2017-2021 qsuscs, TobiX
# Should still run with Python 2.7...
from __future__ import print_function, unicode_literals
import os
import sys
from glob import glob
os.chdir(os.path.dirname(os.path.abspath(__file__)))
home = os.path.realpath(os.path.expanduser('~'))
exit = 0
for f in glob('dot.*'):
dst_home = f[3:].replace("--", "\ufffd").replace("-", "/").replace("\ufffd", "-")
dst = home + '/' + dst_home
src = os.path.join(os.getcwd(), f)
src_rel = os.path.relpath(src, os.path.dirname(dst))
try:
os.makedirs(os.path.dirname(dst))
except OSError:
pass
try:
os.symlink(src_rel, dst)
except OSError:
# Broken symbolic links do not "exist"
if not os.path.exists(dst):
print('"{}" is a broken link pointing to "{}", replacing.'.format(
dst_home, os.readlink(dst)))
os.remove(dst)
os.symlink(src_rel, dst)
elif not os.path.samefile(src, dst):
print('"{}" exists and does not link to "{}".'.format(dst_home, f))
exit = 1
sys.exit(exit)