|
52 | 52 | # Importamos #
|
53 | 53 |
|
54 | 54 | import os
|
| 55 | +import sys |
55 | 56 | import subprocess
|
56 | 57 | from concurrent.futures import ProcessPoolExecutor
|
57 | 58 |
|
|
132 | 133 | yes_no = input("¿Desea continuar? [y/[n]]\n")
|
133 | 134 | if yes_no.lower() not in ["y", "yes", "s", "si"]:
|
134 | 135 | print("Saliendo.")
|
135 |
| - exit(1) |
| 136 | + sys.exit() |
136 | 137 | ## Ejecutable
|
137 | 138 | if not os.path.isfile(oprogr):
|
138 | 139 | msg = "Executable file {} does not exist.".format(oprogr)
|
|
146 | 147 | if tomfile and (not existe_otom):
|
147 | 148 | print("ERROR: Tau-Omega-Mass file {} does not exist.".format(otom))
|
148 | 149 | print("Saliendo.")
|
149 |
| - exit(1) |
| 150 | + sys.exit() |
150 | 151 | ## Chaosfile
|
151 | 152 | if final_chaos is None:
|
152 | 153 | final_chaos = "sump"
|
|
174 | 175 | yes_no = input("Do you want to continue? y/[n]\n")
|
175 | 176 | if yes_no.lower() not in ["y", "yes", "s", "si"]:
|
176 | 177 | print("Saliendo.")
|
177 |
| - exit(1) |
| 178 | + sys.exit() |
178 | 179 |
|
179 | 180 | if all_in_one and (not torque):
|
180 | 181 | print(
|
|
183 | 184 | yes_no = input("Do you want to continue? y/[n]\n")
|
184 | 185 | if yes_no.lower() not in ["y", "yes", "s", "si"]:
|
185 | 186 | print("Saliendo.")
|
186 |
| - exit(1) |
| 187 | + sys.exit() |
187 | 188 |
|
188 | 189 | if torque and (not all_in_one):
|
189 | 190 | print("WARNING: All particles will be integrated independently,")
|
190 | 191 | print(" but each of them will induce torque to its asteroid.")
|
191 | 192 | yes_no = input("Do you want to continue? y/[n]\n")
|
192 | 193 | if yes_no.lower() not in ["y", "yes", "s", "si"]:
|
193 | 194 | print("Saliendo.")
|
194 |
| - exit(1) |
| 195 | + sys.exit() |
195 | 196 |
|
196 | 197 |
|
197 | 198 | # Leemos input
|
|
205 | 206 | # Obtener el número de líneas del archivo de partículas
|
206 | 207 | nsys = len(lines)
|
207 | 208 | if nsys == 0:
|
208 |
| - print("No hay partículas para integrar.") |
209 |
| - exit(1) |
210 |
| -print("Cantidad total de partículas: {}".format(nsys)) |
| 209 | + print("No hay partículas para integrar en el archivo %s." % partfile) |
| 210 | + print("Saliendo.") |
| 211 | + sys.exit() |
| 212 | +else: |
| 213 | + print("Cantidad total de partículas: {}".format(nsys)) |
211 | 214 |
|
212 | 215 | # Ver si hay que hacer todo, o ya hay alguna realizadas
|
213 | 216 | new_simulation = True
|
|
229 | 232 | else "este directorio"
|
230 | 233 | )
|
231 | 234 | )
|
232 |
| - if any( |
233 |
| - [ |
234 |
| - os.path.isdir(os.path.join(wrk_dir, name)) |
235 |
| - and name.startswith(pref) |
236 |
| - for name in os.listdir(wrk_dir) |
237 |
| - ] |
238 |
| - ): |
239 |
| - command = ( |
240 |
| - f"find {pref}* -name 'chaos*{suffix}.out' " |
241 |
| - f"| sed -e 's/.*chaos\\([0-9]*\\){suffix}\\.out/\\1/' " |
242 |
| - f"| sort -n" |
243 |
| - ) |
244 |
| - result = subprocess.run( |
245 |
| - command, |
246 |
| - shell=True, |
247 |
| - stdout=subprocess.PIPE, |
248 |
| - text=True, |
249 |
| - cwd=wrk_dir, |
250 |
| - ) |
251 |
| - if result.returncode == 0: |
252 |
| - output_lines = result.stdout.splitlines() |
253 |
| - else: |
254 |
| - raise IOError("Error al leer integraciones ya realizadas.") |
255 |
| - done = set([int(cint) for cint in output_lines if cint != ""]) |
256 |
| - missing_lines = [x for x in range(1, nsys + 1) if x not in done] |
257 |
| - print(" Cantidad de sistemas ya integrados: {}".format(len(done))) |
258 |
| - nsys = len(missing_lines) |
259 |
| - print(" Cantidad de sistemas a integrar: {}".format(nsys)) |
260 |
| - new_simulation = False |
| 235 | + |
| 236 | + # Lista de archivos done.txt |
| 237 | + file_list = [] |
| 238 | + |
| 239 | + # Recorre todas las subcarpetas en la carpeta raíz |
| 240 | + for subdir in os.listdir(wrk_dir): |
| 241 | + # Verifica si el nombre de la subcarpeta comienza con 'pref' |
| 242 | + this_list = [] |
| 243 | + if subdir.startswith(pref): |
| 244 | + subdir_path = os.path.join(wrk_dir, subdir) |
| 245 | + # Recorre todos los archivos en la subcarpeta |
| 246 | + this_list = [os.path.join(subdir_path, "done.txt") |
| 247 | + for f in os.listdir(subdir_path) |
| 248 | + if f == "done.txt"] |
| 249 | + file_list.extend(this_list) |
| 250 | + |
| 251 | + done = [] |
| 252 | + for file in file_list: |
| 253 | + with open(file, "r") as f: |
| 254 | + done.extend([int(cint) for cint in f.readlines() if cint != ""]) |
| 255 | + missing_lines = [x for x in range(1, nsys + 1) if x not in done] |
| 256 | + print(" Cantidad de sistemas ya integrados: {}".format(len(done))) |
| 257 | + nsys = len(missing_lines) |
| 258 | + print(" Cantidad de sistemas a integrar: {}".format(nsys)) |
| 259 | + new_simulation = False |
261 | 260 |
|
262 | 261 |
|
263 | 262 | # Hay que hacer?
|
264 | 263 | if len(missing_lines) == 0:
|
265 | 264 | print("Ya se han integrado todas las partículas.")
|
266 |
| - exit(1) |
267 |
| - |
268 |
| - |
269 |
| -# Obtener el número de workers |
270 |
| -workers = min(max(1, min(int(workers), len(os.sched_getaffinity(0)))), nsys) |
271 |
| -print("Workers: {}\n".format(workers)) |
| 265 | +else: |
| 266 | + # Obtener el número de workers |
| 267 | + workers = min(max(1, min(int(workers), len(os.sched_getaffinity(0)))), nsys) |
| 268 | + print("Workers: {}\n".format(workers)) |
272 | 269 |
|
273 | 270 | # Argumentos. Estos son:
|
274 | 271 | args = " --nomapf"
|
@@ -326,16 +323,19 @@ def integrate_n(i):
|
326 | 323 | # ESTO SE ESTÁ EJECUTANDO EN LA SHELL #
|
327 | 324 | # print("Running: ./%s %s %s %s"%(program, args, this_args, my_line))
|
328 | 325 | # (Lines debe ser último porque termina en "\n") #
|
329 |
| - p = subprocess.run( |
330 |
| - ["./%s %s %s %s" % (program, args, this_args, my_line)], |
331 |
| - cwd=dirp, |
332 |
| - check=True, |
333 |
| - shell=True, |
334 |
| - ) |
335 |
| - if p.returncode != 0: |
| 326 | + try: |
| 327 | + p = subprocess.run( |
| 328 | + ["./%s %s %s %s" % (program, args, this_args, my_line)], |
| 329 | + cwd=dirp, |
| 330 | + check=True, |
| 331 | + shell=True, |
| 332 | + ) |
| 333 | + except: |
336 | 334 | print("The system %d has failed." % i)
|
337 | 335 | return
|
338 | 336 | print("System %d has been integrated." % i)
|
| 337 | + with open(os.path.join(dirp, "done.txt"), "a") as f: |
| 338 | + f.write("%d\n" % i) |
339 | 339 | return
|
340 | 340 |
|
341 | 341 |
|
@@ -383,13 +383,13 @@ def make_sum(final_chaos, suffix=""):
|
383 | 383 | outs.insert(-1, ".out")
|
384 | 384 | final_chaos = "".join(outs)
|
385 | 385 | command = ' '.join([file for file in file_list])
|
386 |
| - p = subprocess.run( |
387 |
| - ["cat %s > %s" % (command, final_chaos)], |
388 |
| - cwd=wrk_dir, check=True, shell=True |
389 |
| - ) |
390 |
| - |
391 |
| - if p.returncode != 0: |
392 |
| - print("Could not create % with cat."%final_chaos) |
| 386 | + try: |
| 387 | + p = subprocess.run( |
| 388 | + ["cat %s > %s" % (command, final_chaos)], |
| 389 | + cwd=wrk_dir, check=True, shell=True |
| 390 | + ) |
| 391 | + except: |
| 392 | + print("Could not create %s with cat."%final_chaos) |
393 | 393 | print(" Trying with pure python...")
|
394 | 394 | with open(os.path.join(wrk_dir, final_chaos), "w") as f_out:
|
395 | 395 | for file in file_list:
|
@@ -441,13 +441,13 @@ def make_sal(salida, suffix=""):
|
441 | 441 | outs.insert(-1, ".out")
|
442 | 442 | salida = "".join(outs)
|
443 | 443 | command = ' '.join([file for file in file_list])
|
444 |
| - p = subprocess.run( |
445 |
| - ["cat %s > %s" % (command, salida)], |
446 |
| - cwd=wrk_dir, check=True, shell=True |
447 |
| - ) |
448 |
| - |
449 |
| - if p.returncode != 0: |
450 |
| - print("Could not create % with cat."%salida) |
| 444 | + try: |
| 445 | + p = subprocess.run( |
| 446 | + ["cat %s > %s" % (command, salida)], |
| 447 | + cwd=wrk_dir, check=True, shell=True |
| 448 | + ) |
| 449 | + except: |
| 450 | + print("Could not create %s with cat."%salida) |
451 | 451 | print(" Trying with pure python...")
|
452 | 452 | with open(os.path.join(wrk_dir, salida), "w") as f_out:
|
453 | 453 | for file in file_list:
|
|
0 commit comments