|
28 | 28 | INDIRNAME = ":/in" |
29 | 29 | OUTDIRNAME = ":/out" |
30 | 30 |
|
| 31 | +logging.basicConfig( |
| 32 | + level=logging.INFO, |
| 33 | + format='%(message)s' if TRIMMED_LOGS else '%(asctime)s %(levelname)-8s %(message)s', |
| 34 | + datefmt='%Y-%m-%d %H:%M:%S' |
| 35 | +) |
31 | 36 |
|
32 | 37 | if os.path.exists(CONCOREPATH+"/concore.octave"): |
33 | 38 | M_IS_OCTAVE = True #treat .m as octave 9/27/21 |
|
46 | 51 | sourcedir = sys.argv[2] |
47 | 52 | outdir = sys.argv[3] |
48 | 53 | if not os.path.isdir(sourcedir): |
49 | | - print(sourcedir+" does not exist") |
| 54 | + logging.error(f"{sourcedir} does not exist") |
50 | 55 | quit() |
51 | 56 |
|
52 | 57 | if len(sys.argv) < 4: |
53 | | - print("usage: py mkconcore.py file.graphml sourcedir outdir [type]") |
54 | | - print(" type must be posix (macos or ubuntu), windows, or docker") |
| 58 | + logging.error("usage: py mkconcore.py file.graphml sourcedir outdir [type]") |
| 59 | + logging.error(" type must be posix (macos or ubuntu), windows, or docker") |
55 | 60 | quit() |
56 | 61 | elif len(sys.argv) == 4: |
57 | 62 | prefixedgenode = outdir+"_" #nodes and edges prefixed with outdir_ only in case no type specified 3/24/21 |
58 | 63 | concoretype = "docker" |
59 | 64 | else: |
60 | 65 | concoretype = sys.argv[4] |
61 | 66 | if not (concoretype in ["posix","windows","docker","macos","ubuntu"]): |
62 | | - print(" type must be posix (macos or ubuntu), windows, or docker") |
| 67 | + logging.error(" type must be posix (macos or ubuntu), windows, or docker") |
63 | 68 | quit() |
64 | 69 | ubuntu = False #6/24/21 |
65 | 70 | if concoretype == "ubuntu": |
|
69 | 74 | concoretype = "posix" |
70 | 75 |
|
71 | 76 | if os.path.exists(outdir): |
72 | | - print(outdir+" already exists") |
73 | | - print("if intended, remove or rename "+outdir+" first") |
| 77 | + logging.error(f"{outdir} already exists") |
| 78 | + logging.error(f"if intended, Remove/Rename {outdir} first") |
74 | 79 | quit() |
75 | 80 |
|
76 | 81 | os.mkdir(outdir) |
|
97 | 102 |
|
98 | 103 | os.mkdir("src") |
99 | 104 | os.chdir("..") |
100 | | - |
101 | | -print("mkconcore "+MKCONCORE_VER) |
102 | | -print("concore path: "+CONCOREPATH) |
103 | | -print("graphml input: "+GRAPHML_FILE) |
104 | | -print("source directory: "+sourcedir) |
105 | | -print("output directory: "+outdir) |
106 | | -print("control core type: "+concoretype) |
107 | | -print("treat .m as octave:"+str(M_IS_OCTAVE)) |
108 | | -print("MCR path: "+MCRPATH) |
109 | | -print("Docker repository: "+DOCKEREPO) |
110 | | - |
111 | | -# Output in a preferred format. |
112 | | -if TRIMMED_LOGS: |
113 | | - logging.basicConfig(level=logging.INFO, format='%(message)s') |
114 | | -else: |
115 | | - logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S') |
| 105 | + |
| 106 | +logging.info(f"mkconcore {MKCONCORE_VER}") |
| 107 | +logging.info(f"Concore path: {CONCOREPATH}") |
| 108 | +logging.info(f"graphml input: {GRAPHML_FILE}") |
| 109 | +logging.info(f"source directory: {sourcedir}") |
| 110 | +logging.info(f"output directory: {outdir}") |
| 111 | +logging.info(f"control core type: {concoretype}") |
| 112 | +logging.info(f"treat .m as octave: {str(M_IS_OCTAVE)}") |
| 113 | +logging.info(f"MCR path: {MCRPATH}") |
| 114 | +logging.info(f"Docker repository: {DOCKEREPO}") |
116 | 115 |
|
117 | 116 | f = open(GRAPHML_FILE, "r") |
118 | 117 | text_str = f.read() |
|
181 | 180 | ms += mp |
182 | 181 |
|
183 | 182 | if (ms == 0).any(): |
184 | | - print("not all nodes reachable") |
| 183 | + logging.warning("Unreachable nodes detected") |
185 | 184 |
|
186 | 185 | #not right for PM2_1_1 and PM2_1_2 |
187 | 186 | volswr = len(nodes_dict)*[''] |
|
211 | 210 | try: |
212 | 211 | fsource = open(sourcedir+"/"+sourcecode) |
213 | 212 | except: |
214 | | - print(sourcecode+" does not exist in "+sourcedir) |
| 213 | + logging.error(f"{sourcecode} not found in {sourcedir}") |
215 | 214 | quit() |
216 | 215 | with open(outdir+"/src/"+sourcecode,"w") as fcopy: |
217 | 216 | fcopy.write(fsource.read()) |
|
221 | 220 | fsource = open(sourcedir+"/Dockerfile."+dockername) |
222 | 221 | with open(outdir+"/src/Dockerfile."+dockername,"w") as fcopy: |
223 | 222 | fcopy.write(fsource.read()) |
224 | | - print(" Using custom Dockerfile for "+dockername) |
| 223 | + logging.info(f"Using custom Dockerfile for {dockername}") |
225 | 224 | except: |
226 | | - print(" Using default Dockerfile for "+dockername) |
| 225 | + logging.info(f"Using default Dockerfile for {dockername}") |
227 | 226 | fsource.close() |
228 | 227 | if os.path.isdir(sourcedir+"/"+dockername+".dir"): |
229 | 228 | shutil.copytree(sourcedir+"/"+dockername+".dir",outdir+"/src/"+dockername+".dir") |
|
235 | 234 | else: |
236 | 235 | fsource = open(CONCOREPATH+"/concore.py") |
237 | 236 | except: |
238 | | - print(CONCOREPATH+" is not correct path to concore") |
| 237 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
239 | 238 | quit() |
240 | 239 | with open(outdir+"/src/concore.py","w") as fcopy: |
241 | 240 | fcopy.write(fsource.read()) |
|
248 | 247 | else: |
249 | 248 | fsource = open(CONCOREPATH+"/concore.hpp") |
250 | 249 | except: |
251 | | - print(CONCOREPATH+" is not correct path to concore") |
| 250 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
252 | 251 | quit() |
253 | 252 | with open(outdir+"/src/concore.hpp","w") as fcopy: |
254 | 253 | fcopy.write(fsource.read()) |
|
261 | 260 | else: |
262 | 261 | fsource = open(CONCOREPATH+"/concore.v") |
263 | 262 | except: |
264 | | - print(CONCOREPATH+" is not correct path to concore") |
| 263 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
265 | 264 | quit() |
266 | 265 | with open(outdir+"/src/concore.v","w") as fcopy: |
267 | 266 | fcopy.write(fsource.read()) |
|
271 | 270 | try: |
272 | 271 | fsource = open(CONCOREPATH+"/mkcompile") |
273 | 272 | except: |
274 | | - print(CONCOREPATH+" is not correct path to concore") |
| 273 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
275 | 274 | quit() |
276 | 275 | with open(outdir+"/src/mkcompile","w") as fcopy: |
277 | 276 | fcopy.write(fsource.read()) |
|
282 | 281 | try: #maxtime in matlab 11/22/21 |
283 | 282 | fsource = open(CONCOREPATH+"/concore_default_maxtime.m") |
284 | 283 | except: |
285 | | - print(CONCOREPATH+" is not correct path to concore") |
| 284 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
286 | 285 | quit() |
287 | 286 | with open(outdir+"/src/concore_default_maxtime.m","w") as fcopy: |
288 | 287 | fcopy.write(fsource.read()) |
289 | 288 | fsource.close() |
290 | 289 | try: |
291 | 290 | fsource = open(CONCOREPATH+"/concore_unchanged.m") |
292 | 291 | except: |
293 | | - print(CONCOREPATH+" is not correct path to concore") |
| 292 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
294 | 293 | quit() |
295 | 294 | with open(outdir+"/src/concore_unchanged.m","w") as fcopy: |
296 | 295 | fcopy.write(fsource.read()) |
297 | 296 | fsource.close() |
298 | 297 | try: |
299 | 298 | fsource = open(CONCOREPATH+"/concore_read.m") |
300 | 299 | except: |
301 | | - print(CONCOREPATH+" is not correct path to concore") |
| 300 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
302 | 301 | quit() |
303 | 302 | with open(outdir+"/src/concore_read.m","w") as fcopy: |
304 | 303 | fcopy.write(fsource.read()) |
305 | 304 | fsource.close() |
306 | 305 | try: |
307 | 306 | fsource = open(CONCOREPATH+"/concore_write.m") |
308 | 307 | except: |
309 | | - print(CONCOREPATH+" is not correct path to concore") |
| 308 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
310 | 309 | quit() |
311 | 310 | with open(outdir+"/src/concore_write.m","w") as fcopy: |
312 | 311 | fcopy.write(fsource.read()) |
313 | 312 | fsource.close() |
314 | 313 | try: #4/9/21 |
315 | 314 | fsource = open(CONCOREPATH+"/concore_initval.m") |
316 | 315 | except: |
317 | | - print(CONCOREPATH+" is not correct path to concore") |
| 316 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
318 | 317 | quit() |
319 | 318 | with open(outdir+"/src/concore_initval.m","w") as fcopy: |
320 | 319 | fcopy.write(fsource.read()) |
321 | 320 | fsource.close() |
322 | 321 | try: #11/19/21 |
323 | 322 | fsource = open(CONCOREPATH+"/concore_iport.m") |
324 | 323 | except: |
325 | | - print(CONCOREPATH+" is not correct path to concore") |
| 324 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
326 | 325 | quit() |
327 | 326 | with open(outdir+"/src/concore_iport.m","w") as fcopy: |
328 | 327 | fcopy.write(fsource.read()) |
329 | 328 | fsource.close() |
330 | 329 | try: #11/19/21 |
331 | 330 | fsource = open(CONCOREPATH+"/concore_oport.m") |
332 | 331 | except: |
333 | | - print(CONCOREPATH+" is not correct path to concore") |
| 332 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
334 | 333 | quit() |
335 | 334 | with open(outdir+"/src/concore_oport.m","w") as fcopy: |
336 | 335 | fcopy.write(fsource.read()) |
|
341 | 340 | else: |
342 | 341 | fsource = open(CONCOREPATH+"/import_concore.m") |
343 | 342 | except: |
344 | | - print(CONCOREPATH+" is not correct path to concore") |
| 343 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
345 | 344 | quit() |
346 | 345 | with open(outdir+"/src/import_concore.m","w") as fcopy: |
347 | 346 | fcopy.write(fsource.read()) |
|
359 | 358 | if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21 |
360 | 359 | dockername,langext = sourcecode.split(".") |
361 | 360 | if os.path.exists(outdir+"/src/"+dockername+".iport"): |
362 | | - print("warning: "+dockername+" has multiple instantiations; iport/oport may be invalid") |
| 361 | + logging.warning(f"{dockername} has multiple instantiations ; iport/oport may be invalid") |
363 | 362 | with open(outdir+"/src/"+dockername+".iport", "w") as fport: |
364 | 363 | if prefixedgenode == "": # 5/18/21 |
365 | 364 | fport.write(str(iportmap_dict)) |
|
400 | 399 | try: |
401 | 400 | if langext=="py": |
402 | 401 | fsource = open(CONCOREPATH+"/Dockerfile.py") |
403 | | - print("assuming .py extension for Dockerfile") |
| 402 | + logging.info("assuming .py extension for Dockerfile") |
404 | 403 | elif langext == "cpp": # 6/22/21 |
405 | 404 | fsource = open(CONCOREPATH+"/Dockerfile.cpp") |
406 | | - print("assuming .cpp extension for Dockerfile") |
| 405 | + logging.info("assuming .cpp extension for Dockerfile") |
407 | 406 | elif langext == "v": # 6/26/21 |
408 | 407 | fsource = open(CONCOREPATH+"/Dockerfile.v") |
409 | | - print("assuming .v extension for Dockerfile") |
| 408 | + logging.info("assuming .v extension for Dockerfile") |
410 | 409 | elif langext == "sh": # 5/19/21 |
411 | 410 | fsource = open(CONCOREPATH+"/Dockerfile.sh") |
412 | | - print("assuming .sh extension for Dockerfile") |
| 411 | + logging.info("assuming .sh extension for Dockerfile") |
413 | 412 | else: |
414 | | - print("assuming .m extension for Dockerfile") |
415 | 413 | fsource = open(CONCOREPATH+"/Dockerfile.m") |
| 414 | + logging.info("assuming .m extension for Dockerfile") |
416 | 415 | except: |
417 | | - print(CONCOREPATH+" is not correct path to concore") |
| 416 | + logging.error(f"{CONCOREPATH} is not correct path to concore") |
418 | 417 | quit() |
419 | 418 | with open(outdir+"/src/Dockerfile."+dockername,"w") as fcopy: |
420 | 419 | fcopy.write(fsource.read()) |
|
467 | 466 | containername,sourcecode = nodes_dict[node].split(':') |
468 | 467 | if len(sourcecode)!=0: |
469 | 468 | if sourcecode.find(".")==-1: |
470 | | - print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" "+DOCKEREPO+"/docker-"+sourcecode) |
| 469 | + logging.debug(f"Generating Docker run command: {DOCKEREXE} run --name={containername+volswr[i]+volsro[i]} {DOCKEREPO}/docker- {sourcecode}") |
471 | 470 | frun.write(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" "+DOCKEREPO+"/docker-"+sourcecode+"&\n") |
472 | 471 | else: |
473 | 472 | dockername,langext = sourcecode.split(".") |
474 | | - print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername) |
| 473 | + logging.debug(f"Generating Docker run command for {dockername}: {DOCKEREXE} run --name={containername+volswr[i]+volsro[i]} docker-{dockername}") |
475 | 474 | frun.write(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername+"&\n") |
476 | 475 | #if langext != "m": #3/27/21 |
477 | 476 | # print(DOCKEREXE+' run --name='+containername+volswr[i]+volsro[i]+" docker-"+dockername) |
|
651 | 650 | containername,sourcecode = nodes_dict[node].split(':') |
652 | 651 | if len(sourcecode)!=0: |
653 | 652 | if sourcecode.find(".")==-1: |
654 | | - print("cannot pull container "+sourcecode+" with control core type "+concoretype) #3/28/21 |
| 653 | + logging.error("cannot pull container "+sourcecode+" with control core type "+concoretype) #3/28/21 |
655 | 654 | quit() |
656 | 655 | dockername,langext = sourcecode.split(".") |
657 | 656 | fbuild.write('mkdir '+containername+"\n") |
|
696 | 695 |
|
697 | 696 | #make directories equivalent to volumes |
698 | 697 | for edges in edges_dict: |
699 | | - #print("mkdir "+edges) |
700 | 698 | fbuild.write("mkdir "+edges+"\n") |
701 | 699 |
|
702 | 700 | #make links for out directories |
|
741 | 739 | if len(sourcecode)!=0: |
742 | 740 | dockername,langext = sourcecode.split(".") |
743 | 741 | if not (langext in ["py","m","sh","cpp","v"]): # 6/22/21 |
744 | | - print("."+langext+" not supported (Yet)") |
| 742 | + logging.error(f"Extension .{langext} is unsupported") |
745 | 743 | quit() |
746 | 744 | if concoretype=="windows": |
747 | 745 | if langext=="py": |
|
0 commit comments