-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.py
106 lines (93 loc) · 2.29 KB
/
startup.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
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
import subprocess
import sys
import os
DIR = sys.path[0]
def getCmds():
file = open(DIR + '/config.txt', 'r')
lines = file.readlines()
cmds = [];
for line in lines:
segments = line.split(" ")
path = line.replace(segments[0], '', 1).replace(segments[1], '', 1).strip()
cmd = segments[0] + " " + path + "\\" + segments[1]
cmds.append(cmd)
return cmds
def list():
cmds = getCmds();
for index in xrange(len(cmds)):
print '%d\t%s' % (index+1, cmds[index])
def start():
if len(sys.argv) < 3:
print 'format \'start|s [name]\''
return
name = sys.argv[2]
cmds = getCmds();
for cmd in cmds:
cmdexe = cmd.split(" ")
if cmdexe[0].lower() == name.lower():
cmdStr = '"' + cmd.replace(cmdexe[0], '', 1).strip() + '"'
subprocess.Popen(cmdStr)
return
print 'not found %s, use \'add\'' % name
def add():
if len(sys.argv) < 5:
print 'format \'add [name] [exeName] [path]\''
return
name = sys.argv[2]
exeName = sys.argv[3]
path = sys.argv[4]
file = open(DIR + '/config.txt', 'a')
file.writelines('%s %s %s\n' % (name, exeName, path))
file.close()
def delete():
if len(sys.argv) < 3:
print 'format \'delete|d [name]\''
return
name = sys.argv[2]
with open(DIR + "/config.txt","r") as r:
lines = r.readlines()
with open(DIR + "/config.txt","w") as w:
for line in lines:
if line.split(" ")[0].lower() == name.lower():
continue
w.write(line)
def set():
if len(sys.argv) < 5:
print 'format \'set [name] [exeName] [path]\''
return
name = sys.argv[2]
exeName = sys.argv[3]
path = sys.argv[4]
with open(DIR + "/config.txt","r") as r:
lines = r.readlines()
res = False
with open(DIR + "/config.txt","w") as w:
for line in lines:
if line.split(" ")[0].lower() == name.lower():
w.write('%s %s %s\n' % (name, exeName, path))
res = True
else:
w.write(line)
if not res:
print '%s not found' % name
def printHelper():
print 'use list|ls add delete set start|s'
def main():
if len(sys.argv) < 2:
printHelper()
return
opt = sys.argv[1]
if opt == 'list' or opt == 'ls':
list()
elif opt == 'add':
add()
elif opt == 'delete' or opt == 'd':
delete()
elif opt == 'set':
set()
elif opt == 'start' or opt == 's':
start()
else:
printHelper()
if __name__ == '__main__':
main()