-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
145 lines (122 loc) · 4.19 KB
/
run.py
File metadata and controls
145 lines (122 loc) · 4.19 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import subprocess
import os
import sys
SCRIPT_NAME = ".pyjh"
PATHCONF = "/"
CMD_LIST = (
"chdir:",
"run:",
"reChdir:"
)
def pathFullPath(p:str) -> str :
pList = p.split(PATHCONF)
print(p)
pathVector = []
if chr(126):
pathVector.append(os.getenv("HOME"))
pList.pop(0)
elif p[0] != '/':
pathVector.append(os.getcwd())
for element in pList:
if element == ".":
continue
elif element == "..":
if len(pathVector) > 0:
pathVector.pop()
else:
pathVector.append(element)
path = ""
for p in pathVector:
path = os.path.join(path, p)
return path
class PythonScriptor:
def __init__(self) -> None:
self.curScriptor = ""
self.scriptList = []
self.cmdQ = []
self.pathQ = []
self.scriptFinder()
self.scriptSelector()
self.scriptorReader()
self.runScriptorVector()
def scriptFinder(self):
fileList = list(os.walk(os.getcwd()))
for a,b,c in fileList:
for element in c:
if SCRIPT_NAME in element:
self.scriptList.append(os.path.join(a,element))
def scriptSelector(self):
if len(self.scriptList) == 0:
return False
for idx in range(10):
if idx > 0:
print("Retry your number")
print(" ===== select your runscriptor ===== ")
for i, e in enumerate(self.scriptList):
print(f"[{i}] {e}")
try:
fidx = int(input("junhyeong >> "))
except ValueError:
fidx = 0
if fidx < 0 or fidx >= len(self.scriptList):
continue
else:
self.curScriptor = self.scriptList[fidx]
return True
return False
def scriptorReader(self):
''' scriptor Reader : 번역기'''
with open(self.curScriptor, "r", encoding="utf-8") as f:
lists = f.readlines()
curNum = -1
for line in lists:
cmdFlag = False
for i, s in enumerate(CMD_LIST):
if line.split("#")[0].strip().upper() == s.upper():
curNum = i
cmdFlag = True
break
if cmdFlag:
continue
appendLine = line.split("#")[0].strip()
if appendLine != "":
appendLine = appendLine.replace("~", os.getenv("HOME"))
self.cmdQ.append([curNum, line.split("#")[0].strip()])
def runScriptorVector(self):
if len(self.cmdQ) == 0:
print("None Command Vector")
return False
for cmdNum, cmdString in self.cmdQ:
if cmdNum == 0:
self.pathQ.append(os.getcwd())
cmdString = pathFullPath(cmdString)
os.chdir(cmdString)
print(f"change directory --> {os.getcwd()}")
elif cmdNum == 1:
#cmdSplitter = cmdString.split(" ")
#print(f"run system ==> {cmdSplitter}")
try:
subprocess.run(cmdString, shell=True)
except Exception:
print(f"수동으로 명령어를 입력해주십시오 : {cmdString}")
exit(0)
elif cmdNum == 2:
if cmdString == "init":
os.chdir(self.pathQ[0])
self.pathQ.clear()
else:
os.chdir(self.pathQ.pop())
print(f"change directory --> {os.getcwd()}")
else:
print("Wrong cmdNumber")
if __name__ == "__main__":
#subprocess.run(['conda', 'activate', 'cotta'], shell=True)
#subprocess.run(['bash', 'run_cifar10.sh'],shell=True)
myScript = PythonScriptor()
print(myScript.curScriptor)
'''
if __name__ == "__main__":
os.chdir("/home/junhyeong/cotta2/cifar")
subprocess.run(['conda', 'activate', 'cotta'], shell=True)
subprocess.run(['bash', 'run_cifar10.sh'])
'''