@@ -25,7 +25,7 @@ class pythonProgramOptions:
2525 # in the bin directory (rather than the src directory)
2626 compas_executable_override = os .environ .get ('COMPAS_EXECUTABLE_PATH' )
2727 print ('compas_executable_override' , compas_executable_override )
28-
28+
2929 if (compas_executable_override is None ):
3030 git_directory = os .environ .get ('COMPAS_ROOT_DIR' )
3131 compas_executable = os .path .join (git_directory , 'src/COMPAS' )
@@ -50,7 +50,7 @@ class pythonProgramOptions:
5050 # if COMPAS_LOGS_OUTPUT_DIR_PATH is not set (== None) the current working directory
5151 # is used as the value for the --output-path option
5252 compas_logs_output_override = os .environ .get ('COMPAS_LOGS_OUTPUT_DIR_PATH' )
53-
53+
5454 if (compas_logs_output_override is None ):
5555 output = os .getcwd ()
5656 output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
@@ -210,7 +210,7 @@ class pythonProgramOptions:
210210
211211 neutrino_mass_loss_BH_formation = "FIXED_MASS" # "FIXED_FRACTION"
212212 neutrino_mass_loss_BH_formation_value = 0.1 # Either fraction or mass (Msol) to lose
213-
213+
214214 remnant_mass_prescription = 'FRYER2012' #
215215 fryer_supernova_engine = 'DELAYED'
216216 black_hole_kicks = 'FALLBACK'
@@ -299,17 +299,6 @@ class pythonProgramOptions:
299299 debug_to_file = False
300300 errors_to_file = False
301301
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
312-
313302 def booleanChoices (self ):
314303 booleanChoices = [
315304 self .enable_warnings ,
@@ -668,12 +657,12 @@ def generateCommandLineOptionsDict(self):
668657 and run directly as a terminal command, or passed to the stroopwafel interface
669658 where some of them may be overwritten. Options not to be included in the command
670659 line should be set to pythons None (except booleans, which should be set to False)
671-
660+
672661 Parameters
673662 -----------
674663 self : pythonProgramOptions
675664 Contains program options
676-
665+
677666 Returns
678667 --------
679668 commands : str or list of strs
@@ -682,17 +671,17 @@ def generateCommandLineOptionsDict(self):
682671 booleanCommands = self .booleanCommands ()
683672 nBoolean = len (booleanChoices )
684673 assert len (booleanCommands ) == nBoolean
685-
674+
686675 numericalChoices = self .numericalChoices ()
687676 numericalCommands = self .numericalCommands ()
688677 nNumerical = len (numericalChoices )
689678 assert len (numericalCommands ) == nNumerical
690-
679+
691680 stringChoices = self .stringChoices ()
692681 stringCommands = self .stringCommands ()
693682 nString = len (stringChoices )
694683 assert len (stringCommands ) == nString
695-
684+
696685 listChoices = self .listChoices ()
697686 listCommands = self .listCommands ()
698687 nList = len (listChoices )
@@ -702,23 +691,23 @@ def generateCommandLineOptionsDict(self):
702691 ### Collect all options into a dictionary mapping option name to option value
703692
704693 command = {'compas_executable' : self .compas_executable }
705-
694+
706695 for i in range (nBoolean ):
707696 if booleanChoices [i ] == True :
708697 command .update ({booleanCommands [i ] : '' })
709-
698+
710699 for i in range (nNumerical ):
711700 if not numericalChoices [i ] == None :
712701 command .update ({numericalCommands [i ] : str (numericalChoices [i ])})
713-
702+
714703 for i in range (nString ):
715704 if not stringChoices [i ] == None :
716- command .update ({stringCommands [i ] : stringChoices [i ]})
717-
705+ command .update ({stringCommands [i ] : cleanStringParameter ( stringChoices [i ]) })
706+
718707 for i in range (nList ):
719708 if listChoices [i ]:
720709 command .update ({listCommands [i ] : ' ' .join (map (str ,listChoices [i ]))})
721-
710+
722711 return command
723712
724713
@@ -730,13 +719,20 @@ def combineCommandLineOptionsDictIntoShellCommand(commandOptions):
730719 """
731720
732721 shellCommand = commandOptions ['compas_executable' ]
733- del commandOptions ['compas_executable' ]
722+ del commandOptions ['compas_executable' ]
734723 for key , val in commandOptions .items ():
735724 shellCommand += ' ' + key + ' ' + val
736725
737726 return shellCommand
738727
739728
729+ def cleanStringParameter (str_param ):
730+ """ strip quotes and escape spaces to avoid confusing Boost """
731+ if str_param is not None :
732+ str_param = re .sub (r"(?<!\\) " , r"\ " , str_param ).replace ("'" , "" ).replace ('"' , '' )
733+ return str_param
734+
735+
740736if __name__ == "__main__" :
741737
742738 #-- Get the program options
0 commit comments