-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
39 lines (35 loc) · 1.2 KB
/
Copy pathtools.py
File metadata and controls
39 lines (35 loc) · 1.2 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
import os, glob
import setup
def extract(dir, nth=0):
file = setup.ARCHIVES[dir]
if os.path.isdir(dir):
print('directory: {0} already exists'.format(dir))
else:
if file.endswith('.tar.gz'):
os.system('7z x archives\\{0} -y >nul'.format(file))
file = file[:-3]
print('extracting {0} to {1}...'.format(file, dir))
os.system('7z x {0} -o{1} -y >nul'.format(file, dir))
kill(file)
else:
print('extracting {0} to {1}...'.format(file, dir))
os.system('7z x archives\\{0} -otmp -y >nul'.format(file, dir))
tmp = glob.glob('tmp\\*')[nth]
rename(tmp, dir)
kill('tmp')
def kill(path):
if os.path.exists(path):
if os.path.isfile(path):
os.system('del /q {0}'.format(path))
elif os.path.isdir(path):
os.system('rd /s /q {0}'.format(path))
def rename(old, new):
tries = 0
while tries < 10:
try:
kill(new)
os.rename(old, new)
tries = 10
except OSError as e:
print('warning: failed to rename {0} to {1} ({2})'.format(old, new, e.strerror))
tries += 1