-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
40 lines (33 loc) · 1.01 KB
/
utils.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
import sys, os, shutil
WIN32 = False
if sys.platform[:3].lower() == "win":
WIN32 = True
if WIN32:
import ntfsutils.junction
islink = ntfsutils.junction.isjunction
def symlink(source, link_name):
if not os.path.isdir(source):
return
ntfsutils.junction.create(source, link_name)
def unlink(path):
if not ntfsutils.junction.isjunction(path):
return False
ntfsutils.junction.unlink(path)
return True
def rmtree(location, nonlinks=True):
# Explicitly unlink all junction'd links
names = os.listdir(location)
for dir in names:
path = os.path.join(location, dir)
if unlink(path):
continue
if os.path.isdir(path):
rmtree(path)
# Then get rid of everything else
if nonlinks:
shutil.rmtree(location)
else:
symlink = os.symlink
islink = os.path.islink
rmtree = shutil.rmtree
unlink = None