-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkconcore.py
639 lines (589 loc) · 27.4 KB
/
mkconcore.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
from bs4 import BeautifulSoup
import logging
import re
import sys
import os
import shutil
import stat
MKCONCORE_VER = "21-06-25"
GRAPHML_FILE = sys.argv[1]
TRIMMED_LOGS = True
CONCOREPATH = "."
CPPWIN = "g++" #Windows C++ 6/22/21
CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21
PYTHONEXE = "python3" #Ubuntu/macOS python 3
PYTHONWIN = "python" #Windows python 3
MATLABEXE = "matlab" #Ubuntu/macOS matlab
MATLABWIN = "matlab" #Windows matlab
OCTAVEEXE = "octave" #Ubuntu/macOS octave
OCTAVEWIN = "octave" #Windows octave
M_IS_OCTAVE = False #treat .m as octave
MCRPATH = "~/MATLAB/R2021a" #path to local Ubunta Matlab Compiler Runtime
DOCKEREXE = "sudo docker"#assume simple docker install
DOCKEREPO = "markgarnold"#where pulls come from 3/28/21
INDIRNAME = ":/in"
OUTDIRNAME = ":/out"
prefixedgenode = ""
sourcedir = sys.argv[2]
outdir = sys.argv[3]
if not os.path.isdir(sourcedir):
print(sourcedir+" does not exist")
quit()
if len(sys.argv) < 4:
print("usage: py mkconcore.py file.graphml sourcedir outdir [type]")
print(" type must be posix (macos or ubuntu), windows, or docker")
quit()
elif len(sys.argv) == 4:
prefixedgenode = outdir+"_" #nodes and edges prefixed with outdir_ only in case no type specified 3/24/21
concoretype = "docker"
else:
concoretype = sys.argv[4]
if not (concoretype in ["posix","windows","docker","macos","ubuntu"]):
print(" type must be posix (macos or ubuntu), windows, or docker")
quit()
ubuntu = False #6/24/21
if concoretype == "ubuntu":
concoretype = "posix"
ubuntu = True
if concoretype == "macos":
concoretype = "posix"
if os.path.exists(outdir):
print(outdir+" already exists")
print("if intended, remove or rename "+outdir+" first")
quit()
currentdir = os.getcwd()
os.mkdir(outdir)
os.chdir(outdir)
if concoretype == "windows":
fbuild = open("build.bat","w")
frun = open("run.bat", "w")
fdebug = open("debug.bat", "w")
fstop = open("stop.bat", "w") #3/27/21
fclear = open("clear.bat", "w")
else:
fbuild = open("build","w")
frun = open("run", "w")
fdebug = open("debug", "w")
fstop = open("stop", "w") #3/27/21
fclear = open("clear", "w")
os.mkdir("src")
os.chdir("..")
print("mkconcore "+MKCONCORE_VER)
print("concore path: "+CONCOREPATH)
print("graphml input: "+GRAPHML_FILE)
print("source directory: "+sourcedir)
print("output directory: "+outdir)
print("control core type: "+concoretype)
# Output in a preferred format.
if TRIMMED_LOGS:
logging.basicConfig(level=logging.INFO, format='%(message)s')
else:
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
f = open(GRAPHML_FILE, "r")
text_str = f.read()
soup = BeautifulSoup(text_str, 'xml')
edges_text = soup.find_all('edge')
nodes_text = soup.find_all('node')
# Store the edges and nodes in a dictionary
edges_dict = dict()
nodes_dict = dict()
for node in nodes_text:
node_key = node.get_text()
length = len(node.find_all('data'))
for i in range(length):
try:
data = node.find_all('data')[i]
node_label = prefixedgenode + data.find('y:NodeLabel').text #3/23/21
nodes_dict[node['id']] = re.sub(r'(\s+|\n)', ' ', node_label)
except IndexError:
logging.debug('IndexError: A node with no valid properties encountered and ignored')
except AttributeError:
logging.debug('AttributeError: A node with no valid properties encountered and ignored')
for edge in edges_text:
length = len(edge.find_all('data'))
for i in range(length):
try:
data = edge.find_all('data')[i]
edge_label = prefixedgenode + data.find('y:EdgeLabel').text # 3/23/21
if edges_dict.get(edge_label) != None:
targets = edges_dict[edge_label][1]
else:
targets = []
targets.append(nodes_dict[edge['target']])
edges_dict[edge_label] = [nodes_dict[edge['source']], targets]
except IndexError:
logging.debug('An edge with no valid properties encountered and ignored')
except AttributeError:
logging.debug('AttributeError: An edge with no valid properties encountered and ignored')
# Print the edges_dict
#logging.info(edges_dict)
############## Mark's Docker
import numpy as np
i=0
nodes_num=dict()
for node in nodes_dict:
nodes_num[nodes_dict[node]] = i
i=i+1
m=np.zeros((len(nodes_dict),len(nodes_dict)))
for edges in edges_dict:
for dest in (edges_dict[edges])[1]:
m[nodes_num[edges_dict[edges][0]]][nodes_num[dest]] = 1
mp = np.eye(len(nodes_dict))
ms = np.zeros((len(nodes_dict),len(nodes_dict)))
for i in range(0,len(nodes_dict)):
mp = mp@m
ms += mp
if (ms == 0).any():
print("not all nodes reachable")
#not right for PM2_1_1 and PM2_1_2
volswr = len(nodes_dict)*['']
i = 0
for edges in edges_dict:
volswr[nodes_num[edges_dict[edges][0]]] += ' -v '+str(edges)+OUTDIRNAME+str(volswr[nodes_num[edges_dict[edges][0]]].count('-v')+1)
i += 1
#save indir
indir = len(nodes_dict)*[[]]
volsro = len(nodes_dict)*['']
i = 0
for edges in edges_dict:
for dest in (edges_dict[edges])[1]:
incount = volsro[nodes_num[dest]].count('-v')
volIndirPair = str(edges)+INDIRNAME+str(incount+1)
indir[nodes_num[dest]] = indir[nodes_num[dest]] + [volIndirPair]
volsro[nodes_num[dest]] += ' -v '+volIndirPair+':ro'
i += 1
#copy sourcedir into ./src
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
dockername,langext = sourcecode.split(".")
try:
fsource = open(sourcedir+"/"+sourcecode)
except:
print(sourcecode+" does not exist in "+sourcedir)
quit()
with open(outdir+"/src/"+sourcecode,"w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
if concoretype == "docker": # 3/30/21
try:
fsource = open(sourcedir+"/Dockerfile."+dockername)
with open(outdir+"/src/Dockerfile."+dockername,"w") as fcopy:
fcopy.write(fsource.read())
print(" Using custom Dockerfile for "+dockername)
except:
print(" Using default Dockerfile for "+dockername)
fsource.close()
if os.path.isdir(sourcedir+"/"+dockername+".dir"):
shutil.copytree(sourcedir+"/"+dockername+".dir",outdir+"/src/"+dockername+".dir")
#copy proper concore.py into /src
try:
if concoretype=="docker":
fsource = open(CONCOREPATH+"/concoredocker.py")
else:
fsource = open(CONCOREPATH+"/concore.py")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/concore.py","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
#copy proper concore.hpp into /src 6/22/21
try:
if concoretype=="docker":
fsource = open(CONCOREPATH+"/concoredocker.hpp")
else:
fsource = open(CONCOREPATH+"/concore.hpp")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/concore.hpp","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
#copy mkcompile into /src 5/27/21
try:
fsource = open(CONCOREPATH+"/mkcompile")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/mkcompile","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
os.chmod(outdir+"/src/mkcompile",stat.S_IRWXU)
#copy concore*.m into /src 4/2/21
try:
fsource = open(CONCOREPATH+"/concore_unchanged.m")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/concore_unchanged.m","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
try:
fsource = open(CONCOREPATH+"/concore_read.m")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/concore_read.m","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
try:
fsource = open(CONCOREPATH+"/concore_write.m")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/concore_write.m","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
try: #4/9/21
fsource = open(CONCOREPATH+"/concore_initval.m")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/concore_initval.m","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
try: # 4/4/21
if concoretype=="docker":
fsource = open(CONCOREPATH+"/import_concoredocker.m")
else:
fsource = open(CONCOREPATH+"/import_concore.m")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/import_concore.m","w") as fcopy:
fcopy.write(fsource.read())
fsource.close()
#generate input portmap file
i=0
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
iportmap_dict = dict()
for pair in indir[i]:
volname,portnum = pair.split(INDIRNAME)
iportmap_dict[volname] = int(portnum)
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
dockername,langext = sourcecode.split(".")
if os.path.exists(outdir+"/src/"+dockername+".iport"):
print("warning: "+dockername+" has multiple instantiations; iport/oport may be invalid")
with open(outdir+"/src/"+dockername+".iport", "w") as fport:
if prefixedgenode == "": # 5/18/21
fport.write(str(iportmap_dict))
else:
fport.write(str(iportmap_dict).replace("'"+prefixedgenode,"'"))
i=i+1
#generate output portmap file
outcount = len(nodes_dict)*[0]
#wrong, this aliases single dict for all elements: oportmap = len(nodes_dict)*[dict()]
#instead, need to use a loop to initialize:
oportmap_dict = []
for node in nodes_dict:
oportmap_dict += [dict()]
for edges in edges_dict:
containername,sourcecode = edges_dict[edges][0].split(':')
outcount[nodes_num[edges_dict[edges][0]]] += 1
oportmap_dict[nodes_num[edges_dict[edges][0]]][edges] = outcount[nodes_num[edges_dict[edges][0]]]
i=0
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
dockername,langext = sourcecode.split(".")
with open(outdir+"/src/"+dockername+".oport", "w") as fport:
if prefixedgenode == "": # 5/18/21
fport.write(str(oportmap_dict[i]))
else:
fport.write(str(oportmap_dict[i]).replace("'"+prefixedgenode,"'"))
i=i+1
#if docker, make docker-dirs, generate build, run, stop, clear scripts and quit
if (concoretype=="docker"):
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
dockername,langext = sourcecode.split(".")
if not os.path.exists(outdir+"/src/Dockerfile."+dockername): # 3/30/21
try:
if langext=="py":
fsource = open(CONCOREPATH+"/Dockerfile.py")
print("assuming .py extension for Dockerfile")
elif langext == "cpp": # 6/22/21
fsource = open(CONCOREPATH+"/Dockerfile.cpp")
print("assuming .cpp extension for Dockerfile")
elif langext == "sh": # 5/19/21
fsource = open(CONCOREPATH+"/Dockerfile.sh")
print("assuming .sh extension for Dockerfile")
else:
print("assuming .m extension for Dockerfile")
fsource = open(CONCOREPATH+"/Dockerfile.m")
except:
print(CONCOREPATH+" is not correct path to concore")
quit()
with open(outdir+"/src/Dockerfile."+dockername,"w") as fcopy:
fcopy.write(fsource.read())
if langext=="py":
fcopy.write('CMD ["python", "-i", "'+sourcecode+'"]\n')
if langext=="m":
fcopy.write('CMD ["octave", "-qf", "--eval", "run('+"'"+sourcecode+"'"+')"]\n') #3/28/21
if langext=="sh":
fcopy.write('CMD ["./'+sourcecode+'" ,"/opt/mcr/v910"]') # 5/19/21
#["./run_pmmat.sh", "/opt/mcr/MATLAB/MATLAB_Runtime/v910"]
fsource.close()
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
dockername,langext = sourcecode.split(".")
fbuild.write("mkdir docker-"+dockername+"\n")
fbuild.write("cd docker-"+dockername+"\n")
fbuild.write("cp ../src/Dockerfile."+dockername+" Dockerfile\n")
#copy sourcefiles from ./src into corresponding directories
fbuild.write("cp ../src/"+sourcecode+" .\n")
if langext == "py": #4/29/21
fbuild.write("cp ../src/concore.py .\n")
elif langext == "cpp": #6/22/21
fbuild.write("cp ../src/concore.hpp .\n")
if langext == "m":
fbuild.write("cp ../src/concore_*.m .\n")
fbuild.write("cp ../src/import_concore.m .\n")
if langext == "sh": #5/27/21
fbuild.write("chmod u+x "+sourcecode+"\n")
fbuild.write("cp ../src/"+dockername+".iport concore.iport\n")
fbuild.write("cp ../src/"+dockername+".oport concore.oport\n")
#include data files in here if they exist
if os.path.isdir(sourcedir+"/"+dockername+".dir"):
fbuild.write("cp -r ../src/"+dockername+".dir/* .\n")
fbuild.write(DOCKEREXE+" build -t docker-"+dockername+" .\n")
fbuild.write("cd ..\n")
fbuild.close()
i=0
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
if sourcecode.find(".")==-1:
print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" "+DOCKEREPO+"/docker-"+sourcecode)
frun.write(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" "+DOCKEREPO+"/docker-"+sourcecode+"&\n")
else:
dockername,langext = sourcecode.split(".")
print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername)
frun.write(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername+"&\n")
#if langext != "m": #3/27/21
# print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername)
# frun.write(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername+"&\n")
#else:
# print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername+' octave -qf --eval "run('+"'"+sourcecode+"'"+')"'+"&\n")
# frun.write(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername+' octave -qf --eval "run('+"'"+sourcecode+"'"+')"'+"&\n")
i=i+1
frun.close()
i=0 # 3/27/21
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
#dockername,langext = sourcecode.split(".")
dockername = sourcecode.split(".")[0] # 3/28/21
fstop.write(DOCKEREXE+' stop '+containername+"\n")
fstop.write(DOCKEREXE+' rm '+containername+"\n")
i=i+1
fstop.close()
i=0 # 3/27/21
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
dockername = sourcecode.split(".")[0] #3/28/21
fclear.write(DOCKEREXE+' volume rm ' +volswr[i].split(":")[0].split("-v")[1]+"\n")
i=i+1
fclear.close()
i=0
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21
dockername,langext = sourcecode.split(".")
fdebug.write(DOCKEREXE+' run -it --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername+"&\n")
i=i+1
fdebug.close()
os.chmod(outdir+"/build",stat.S_IRWXU)
os.chmod(outdir+"/run",stat.S_IRWXU)
os.chmod(outdir+"/debug",stat.S_IRWXU)
os.chmod(outdir+"/stop",stat.S_IRWXU)
os.chmod(outdir+"/clear",stat.S_IRWXU)
quit()
#remaining code deals only with posix or windows
#copy sourcefiles from ./src into corresponding directories
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
if sourcecode.find(".")==-1:
print("cannot pull container "+sourcecode+" with control core type "+concoretype) #3/28/21
quit()
dockername,langext = sourcecode.split(".")
fbuild.write('mkdir '+containername+"\n")
if concoretype == "windows":
fbuild.write("copy .\\src\\"+sourcecode+" .\\"+containername+"\\"+sourcecode+"\n")
if langext == "py":
fbuild.write("copy .\\src\\concore.py .\\" + containername + "\\concore.py\n")
elif langext == "cpp": # 6/22/21
fbuild.write("copy .\\src\\concore.hpp .\\" + containername + "\\concore.hpp\n")
elif langext == "m": # 4/2/21
fbuild.write("copy .\\src\\concore_*.m .\\" + containername + "\\\n")
fbuild.write("copy .\\src\\import_concore.m .\\" + containername + "\\\n")
fbuild.write("copy .\\src\\"+dockername+".iport .\\"+containername+"\\concore.iport\n")
fbuild.write("copy .\\src\\"+dockername+".oport .\\"+containername+"\\concore.oport\n")
#include data files in here if they exist
if os.path.isdir(sourcedir+"/"+dockername+".dir"):
fbuild.write("copy .\\src\\"+dockername+".dir\\*.* .\\"+containername+"\n")
else:
fbuild.write("cp ./src/"+sourcecode+" ./"+containername+"/"+sourcecode+"\n")
if langext == "py":
fbuild.write("cp ./src/concore.py ./"+containername+"/concore.py\n")
elif langext == "cpp":
fbuild.write("cp ./src/concore.hpp ./"+containername+"/concore.hpp\n")
elif langext == "m": # 4/2/21
fbuild.write("cp ./src/concore_*.m ./"+containername+"/\n")
fbuild.write("cp ./src/import_concore.m ./"+containername+"/\n")
fbuild.write("./src/mkcompile "+dockername+" "+containername+"/\n") # 5/27/21
elif langext == "sh": # 4/2/28
fbuild.write("chmod u+x ./"+containername+"/"+sourcecode+"\n")
fbuild.write("cp ./src/"+dockername+".iport ./"+containername+"/concore.iport\n")
fbuild.write("cp ./src/"+dockername+".oport ./"+containername+"/concore.oport\n")
#include data files in here if they exist
if os.path.isdir(sourcedir+"/"+dockername+".dir"):
fbuild.write("cp -r ./src/"+dockername+".dir/* ./"+containername+"\n")
#make directories equivalent to volumes
for edges in edges_dict:
#print("mkdir "+edges)
fbuild.write("mkdir "+edges+"\n")
#make links for out directories
outcount = len(nodes_dict)*[0]
for edges in edges_dict:
containername,sourcecode = edges_dict[edges][0].split(':')
outcount[nodes_num[edges_dict[edges][0]]] += 1
if len(sourcecode)!=0:
dockername,langext = sourcecode.split(".")
fbuild.write('cd '+containername+"\n")
if concoretype=="windows":
fbuild.write("mklink /J out"+str(outcount[nodes_num[edges_dict[edges][0]]])+" ..\\"+str(edges)+"\n")
else:
fbuild.write("ln -s ../" + str(edges) + ' out'+str(outcount[nodes_num[edges_dict[edges][0]]])+"\n")
fbuild.write("cd .."+"\n")
#make links for in directories
i=0
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
dockername,langext = sourcecode.split(".")
fbuild.write('cd '+containername+"\n")
for pair in indir[i]:
volname,dirname = pair.split(':/')
if concoretype=="windows":
fbuild.write("mklink /J "+dirname+" ..\\"+volname+"\n")
else:
fbuild.write("ln -s ../"+volname+" "+dirname+"\n")
fbuild.write('cd ..'+"\n")
i=i+1
#start running source in associated dirs (run and debug scripts)
i=0
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
dockername,langext = sourcecode.split(".")
if not (langext in ["py","m","sh","cpp"]): # 6/22/21
print("."+langext+" not supported (Yet)")
quit()
if concoretype=="windows":
if langext=="py":
frun.write('start /B /D '+containername+" "+PYTHONWIN+" "+sourcecode+" >"+containername+"\\concoreout.txt\n")
fdebug.write('start /D '+containername+" cmd /K "+PYTHONWIN+" "+sourcecode+"\n")
elif langext=="cpp": #6/25/21
frun.write('cd '+containername+'\n')
frun.write(CPPWIN+' '+sourcecode+'\n')
frun.write('cd ..\n')
frun.write('start /B /D '+containername+' cmd /c a >'+containername+'\\concoreout.txt\n')
#frun.write('start /B /D '+containername+' "'+CPPWIN+' '+sourcecode+'|a >'+containername+'\\concoreout.txt"\n')
fdebug.write('cd '+containername+'\n')
fdebug.write(CPPWIN+' '+sourcecode+'\n')
fdebug.write('cd ..\n')
fdebug.write('start /D '+containername+' cmd /K a\n')
#fdebug.write('start /D '+containername+' cmd /K "'+CPPWIN+' '+sourcecode+'|a"\n')
elif langext=="m": #3/23/21
if M_IS_OCTAVE:
frun.write('start /B /D '+containername+" "+OCTAVEWIN+' -qf --eval "run('+"'"+sourcecode+"'"+')"'+" >"+containername+"\\concoreout.txt\n")
fdebug.write('start /D '+containername+" cmd /K " +OCTAVEWIN+' -qf --eval "run('+"'"+sourcecode+"'"+')"'+"\n")
else: # 4/2/21
frun.write('start /B /D '+containername+" "+MATLABWIN+' -batch "run('+"'"+sourcecode+"'"+')"'+" >"+containername+"\\concoreout.txt\n")
fdebug.write('start /D '+containername+" cmd /K " +MATLABWIN+' -batch "run('+"'"+sourcecode+"'"+')"'+"\n")
else:
if langext=="py":
frun.write('(cd '+containername+";"+PYTHONEXE+" "+sourcecode+" >concoreout.txt&echo $!>concorepid)&\n")
if ubuntu:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+';bash"&\n')
else:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+PYTHONEXE+" "+sourcecode+'\\""\n')
elif langext=="cpp": # 6/22/21
frun.write('(cd '+containername+";"+CPPEXE+" "+sourcecode+";./a.out >concoreout.txt&echo $!>concorepid)&\n")
if ubuntu:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out;bash"&\n')
else:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+CPPEXE+" "+sourcecode+';./a.out\\""\n')
elif langext=="sh": # 5/19/21
frun.write('(cd '+containername+";./"+sourcecode+" "+ MCRPATH + " >concoreout.txt&echo $!>concorepid)&\n")
if ubuntu:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";./"+sourcecode+';bash"&\n')
else:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";./"+sourcecode+'\\""\n')
elif langext=="m": #3/23/21
if M_IS_OCTAVE:
frun.write('(cd '+containername+";"+ OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n")
if ubuntu:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('xterm -e bash -c "cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&'+"\n")
else:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/'+containername+";"+OCTAVEEXE+' -qf --eval run\\\\\\(\\\\\\'+"'"+sourcecode+"\\\\\\'"+'\\\\\\)\\""'+"\n")
else: # 4/2/21
frun.write('(cd '
+containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\)'+" >concoreout.txt&echo $!>concorepid)&\n")
if ubuntu:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('xterm -e bash -c "cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\);bash"&\n' )
else:
fdebug.write('concorewd=`pwd`\n')
fdebug.write('osascript -e "tell application \\"Terminal\\" to do script \\"cd $concorewd/' +containername+";"+ MATLABEXE+' -batch run\\(\\'+"'"+sourcecode+"\\'"+'\\)\n' )
i=0 # 3/30/21
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
dockername = sourcecode.split(".")[0] # 3/28/21
if concoretype=="windows":
fstop.write('cmd /C '+containername+"\\concorekill\n")
fstop.write('del '+containername+"\\concorekill.bat\n")
else:
fstop.write('kill -9 `cat '+containername+"/concorepid`\n")
fstop.write('rm '+containername+"/concorepid\n")
i=i+1
fstop.close()
i=0 # 3/30/21
for node in nodes_dict:
containername,sourcecode = nodes_dict[node].split(':')
if len(sourcecode)!=0:
dockername = sourcecode.split(".")[0] #3/28/21
if concoretype=="windows":
fclear.write('del /Q' +volswr[i].split(":")[0].split("-v")[1]+"\\*\n")
else:
fclear.write('rm ' +volswr[i].split(":")[0].split("-v")[1]+"/*\n")
i=i+1
fclear.close()
frun.close()
fbuild.close()
fdebug.close()
fstop.close()
fclear.close()
if concoretype != "windows":
os.chmod(outdir+"/build",stat.S_IRWXU)
os.chmod(outdir+"/run",stat.S_IRWXU)
os.chmod(outdir+"/debug",stat.S_IRWXU)
os.chmod(outdir+"/stop",stat.S_IRWXU)
os.chmod(outdir+"/clear",stat.S_IRWXU)