-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharp
executable file
·262 lines (232 loc) · 7 KB
/
arp
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/python -O
versionstring = "beta3"
datestring = "june 30, 2006"
import os,sys,stat,re
import arp_help, arp_output, arp_utils
from arp_output import ctext
actions=[
"pack", "unpack", "list",
"delete", "make", "test",
"help"
]
options=["--tree", "--version", "--pretend","--help"]
shortmapping={"P":"--pack", "U":"--unpack", "L":"--list",
"D":"--delete", "M":"--make", "T":"--test",
"h":"--help","h":"--help",
"t":"--tree","v":"--version","p":"--pretend"}
myaction=None
myopts=[]
myfiles=[]
edebug=0
# process short actions
tmpcmdline=sys.argv[1:]
cmdline=[]
if tmpcmdline==[]:
arp_help.shorthelp()
sys.exit(0)
for x in tmpcmdline:
if x[0:1]=="-"and x[1:2]!="-":
for y in x[1:]:
if shortmapping.has_key(y):
if shortmapping[y] in cmdline:
print
print "*** Warning: Redundant use of",shortmapping[y]
else:
cmdline.append(shortmapping[y])
else:
print "!!! Error: -"+y+" is an invalid short action."
sys.exit(1)
else:
cmdline.append(x)
# process the options and command arguments
for x in cmdline:
if not x:
continue
if len(x)>=2 and x[0:2]=="--":
if x in options:
myopts.append(x)
elif x[2:] in actions:
if myaction:
if myaction not in ["system", "world"]:
myaction="--"+myaction
print
print ctext(['red'],"!!!")+ctext(['green'],\
" Multiple actions requested... Please choose one only.")
if myaction != x:
print ctext(['red'],"!!!")+" '"+\
ctext(['darkgreen'],myaction)+"' "+\
ctext(['red'],"or")+" '"+ctext(['darkgreen'],x)+"'"
print
sys.exit(1)
myaction=x[2:]
else:
print "!!! Error:",x,"is an invalid option."
sys.exit(1)
elif x[-1]=="/":
# this little conditional helps tab completion
myfiles.append(x[:-1])
else:
myfiles.append(x)
if ("--help" in myopts) or (myaction=="help") or (not myaction):
arp_help.shorthelp();
sys.exit(0)
if not myfiles:
print ctext(['red'],"!!! Error: please specify a target")
sys.exit(1)
# print "OPTIONS:",
# for x in myopts:
# print x,
# print
# print "ACTION:",
# print myaction
# print "FILES:",
# for x in myfiles:
# print x,
# print
mypath = os.getcwd()
dirlist = []
if ("all" in myfiles):
tmpdirlist = os.listdir(mypath+"/platforms")
for x in tmpdirlist:
tmpstat = os.lstat(mypath+"/platforms/"+x)
if stat.S_ISDIR(tmpstat[stat.ST_MODE]):
if ("svn" not in x):
dirlist.append(x)
elif "unpack" not in myaction:
for x in myfiles:
try:
tmpstat = os.lstat(mypath+"/platforms/"+x)
except:
try:
tmpstat = os.lstat(mypath+"/"+x)
except:
print ctext(['red'],"!!! Error: cannot access "+x)
sys.exit(1)
if stat.S_ISDIR(tmpstat[stat.ST_MODE]):
if ("svn" not in x):
dirlist.append(os.path.normpath(x))
elif stat.S_ISREG(tmpstat[stat.ST_MODE]):
print ctext(['red'],"!!! Error: argument must be a platform ("+x+")")
sys.exit(1)
else:
print ctext(['red'],"!!! Error: please verify "+x+" (seems a link)")
sys.exit(1)
if ("--tree" in myopts) and ( "list" != myaction):
print ctext(['red'],"!!! Error: option --tree only makes sense with list action.")
sys.exit(1)
if "unpack" in myaction:
for x in myfiles:
if not os.path.exists(x):
print ctext(['red'],"!!! Error: package "+x+" doesn't exists.")
else:
print "Unpacking platform "+x+"..."
cmd = "tar xmzf "+x
cstdin, cstdout, cstderr = os.popen3(cmd)
cstdin.close()
errors = cstderr.readlines()
if errors:
for y in errors:
print "-- "+y[5:],
print ctext(['red','blink'],"There are errors.")
cstderr.close()
cstdout.close()
print "Done."
elif "pack" in myaction:
print "PACK"
for x in dirlist:
if not os.path.exists("platforms/"+x+"/defs.arp"):
if os.path.exists(x):
head,tail=os.path.split(x)
print "Packing "+tail+"..."
cmd = "tar cz --exclude='*.svn*' -f "+tail+".arppack "+x
cstdin, cstdout, cstderr = os.popen3(cmd)
cstdin.close()
errors = cstderr.readlines()
if errors:
for y in errors:
print "-- "+y[5:],
print ctext(['red','blink'],"There are errors. Your package will be incomplete.")
cstderr.close()
cstdout.close()
else:
print ctext(['red'],"!!! Error: "+x+" doesn't exists (defs.arp missing?).")
else:
platname,platstruct = arp_utils.getdefstructure("platforms/"+x+"/defs.arp")
print "Packing platform "+x+"..."
cmd = "tar cz --exclude='*.svn*' -f "+x+".arppack "+" ".join(platstruct) +" platforms/"+x
cstdin, cstdout, cstderr = os.popen3(cmd)
cstdin.close()
errors = cstderr.readlines()
if errors:
for y in errors:
print "-- "+y[5:],
print ctext(['red','blink'],"There are errors. Your package will be incomplete.")
cstderr.close()
cstdout.close()
print "Done."
elif "list" in myaction:
for x in dirlist:
if not os.path.exists("platforms/"+x+"/defs.arp"):
print ctext(['red'],"!!! Error: platforms/"+x+"/defs.arp doesn't exists.")
else:
platname,platstruct = arp_utils.getdefstructure("platforms/"+x+"/defs.arp")
print "PLATAFORM "+x+" is:"
for y in platstruct:
print " -- "+y
print "---"
elif "delete" in myaction:
gooddirlist=[]
goodlist=[]
tmpdirlist = os.listdir(mypath+"/platforms")
for x in tmpdirlist:
tmpstat = os.lstat(mypath+"/platforms/"+x)
if stat.S_ISDIR(tmpstat[stat.ST_MODE]):
if (("svn" not in x) and (x not in dirlist)):
if os.path.exists("platforms/"+x+"/defs.arp"):
gooddirlist.append(x)
for x in gooddirlist:
platname,platstruct = arp_utils.getdefstructure("platforms/"+x+"/defs.arp")
for y in platstruct:
if y not in goodlist:
goodlist.append(y)
print "DELETE"
for x in dirlist:
if not os.path.exists("platforms/"+x+"/defs.arp"):
if os.path.exists(x):
head,tail=os.path.split(x)
print "Deleting "+tail+"..."
cmd = "rm -Rf "+x
cstdin, cstdout, cstderr = os.popen3(cmd)
cstdin.close()
errors = cstderr.readlines()
if errors:
for y in errors:
print "-- "+y[5:],
print ctext(['red','blink'],"There are errors.")
cstderr.close()
cstdout.close()
else:
print ctext(['red'],"!!! Error: "+x+" doesn't exists (defs.arp missing?).")
else:
platname,platstruct = arp_utils.getdefstructure("platforms/"+x+"/defs.arp")
print "Deleting platform "+x+"..."
for y in platstruct:
if y in goodlist:
print "ARP: "+y+" is part of another platform and will not be removed automatically."
print "ARP: Use arp --delete "+y+" to do it."
platstruct.remove(y)
cmd = "rm -Rf "+" ".join(platstruct) +" platforms/"+x
cstdin, cstdout, cstderr = os.popen3(cmd)
cstdin.close()
errors = cstderr.readlines()
if errors:
for y in errors:
print "-- "+y[5:],
print ctext(['red','blink'],"There are errors.")
cstderr.close()
cstdout.close()
print "Done."
elif "make" in myaction:
print "MAKE action recognized but not implemented yet."
elif "test" in myaction:
print "TEST action recognized but not implemented yet."