-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.py
36 lines (29 loc) · 950 Bytes
/
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
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
ntfsutils.junction.unlink(path)
def rmtree(location, nonlinks=True):
# Explicitly unlink all junction'd links
for root, dirs, files in os.walk(location, topdown=False):
for dir in dirs:
path = os.path.join(root, dir)
unlink(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