Skip to content

Commit 421404e

Browse files
author
Tom Wagg
committed
use regex to escape unescaped spaces in paths
1 parent 5914445 commit 421404e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

preProcessing/pythonSubmit.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import numpy as np
2-
import subprocess
32
import sys
43
import os
5-
import pickle
6-
import itertools
74
from subprocess import call
5+
import re
86

97
# Check if we are using python 3
108
python_version = sys.version_info[0]
@@ -94,14 +92,6 @@ class pythonProgramOptions:
9492
else:
9593
logfile_definitions = compas_input_path_override + '/' + logfile_definitions
9694

97-
# ensure that no file paths have spaces that could confuse Boost
98-
for path in [output, grid_filename, logfile_definitions]:
99-
if path is not None and path.find(" ") >= 0:
100-
print("ERROR: File path contains spaces, replace with underscores or another character.")
101-
print("\t" + path)
102-
print("\t" + " " * path.find(" ") + "^")
103-
exit(1)
104-
10595
initial_mass = None # initial mass for SSE
10696
initial_mass_1 = None # primary initial mass for BSE
10797
initial_mass_2 = None # secondary initial mass for BSE
@@ -309,6 +299,16 @@ class pythonProgramOptions:
309299
debug_to_file = False
310300
errors_to_file = False
311301

302+
# ensure that no file paths have unescaped spaces that could confuse Boost
303+
paths = [output, grid_filename, logfile_definitions, logfile_common_envelopes, logfile_detailed_output,
304+
logfile_double_compact_objects, logfile_rlof_parameters, logfile_pulsar_evolution,
305+
logfile_supernovae, logfile_switch_log, logfile_system_parameters]
306+
for i in range(len(paths)):
307+
if paths[i] is not None:
308+
paths[i] = re.sub(r"(?<!\\) ", r"\ ", paths[i])
309+
output, grid_filename, logfile_definitions, logfile_common_envelopes, logfile_detailed_output,\
310+
logfile_double_compact_objects, logfile_rlof_parameters, logfile_pulsar_evolution,\
311+
logfile_supernovae, logfile_switch_log, logfile_system_parameters = paths
312312

313313
def booleanChoices(self):
314314
booleanChoices = [

0 commit comments

Comments
 (0)