-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
67 lines (46 loc) · 1.32 KB
/
util.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import shutil
import subprocess
import sys
import config
def cd(*path):
abs_path = getpath(*path)
if not os.path.exists(abs_path):
os.makedirs(abs_path)
os.chdir(abs_path)
print('cd : ' + abs_path)
def cp(src, dst):
shutil.copy(src, dst)
print('cp : ' + src + ' ' + dst)
def emptydir(*path):
abs_path = getpath(*path)
if os.path.exists(abs_path):
shutil.rmtree(abs_path)
os.mkdir(abs_path)
print('mkdir : ' + abs_path)
def exec(*cmds):
print('exec : ' + ' '.join(cmds))
subprocess.check_call(cmds, shell=(sys.platform == 'win32'))
def exec_stdout(*cmds):
proc = subprocess.Popen(cmds, stdout=subprocess.PIPE)
return proc.stdout.read()
def exec_stdin(data, *cmds):
print('exec : ' + ' '.join(cmds))
print(data)
proc = subprocess.Popen(cmds, stdin=subprocess.PIPE)
proc.communicate(data.encode('utf-8'))
def exists(*path):
abs_path = getpath(*path)
return os.path.exists(abs_path)
def getpath(*path):
return os.path.join(config.PATH_ROOT, *path)
def mv(src, dst):
shutil.move(src, dst)
print('mv : ' + src + ' ' + dst)
def rm(*path):
abs_path = getpath(*path)
if os.path.exists(abs_path):
if os.path.isdir(abs_path):
shutil.rmtree(abs_path)
else:
os.remove(abs_path)