8080import autosubmit .history .utils as HUtils
8181import autosubmit .helpers .autosubmit_helper as AutosubmitHelper
8282import autosubmit .statistics .utils as StatisticsUtils
83- from autosubmit .helpers .utils import check_jobs_file_exists
83+ from autosubmit .helpers .utils import check_jobs_file_exists , get_rc_path
8484
8585from contextlib import suppress
8686
@@ -2149,7 +2149,7 @@ def refresh_log_recovery_process(platforms: List[Platform], as_conf: AutosubmitC
21492149 p .work_event .set ()
21502150
21512151 @staticmethod
2152- def run_experiment (expid , notransitive = False , start_time = None , start_after = None , run_only_members = None , profile = False ):
2152+ def run_experiment (expid , notransitive = False , start_time = None , start_after = None , run_only_members = None , profile = False ) -> int :
21532153 """
21542154 Runs and experiment (submitting all the jobs properly and repeating its execution in case of failure).
21552155 :param expid: the experiment id
@@ -2158,7 +2158,7 @@ def run_experiment(expid, notransitive=False, start_time=None, start_after=None,
21582158 :param start_after: the expid after which the experiment should start
21592159 :param run_only_members: the members to run
21602160 :param profile: if True, the function will be profiled
2161- :return: None
2161+ :return: exit status
21622162
21632163 """
21642164 # Start profiling if the flag has been used
@@ -3406,7 +3406,7 @@ def describe(input_experiment_list="*",get_from_user=""):
34063406
34073407 @staticmethod
34083408 def configure (advanced , database_path , database_filename , local_root_path , platforms_conf_path , jobs_conf_path ,
3409- smtp_hostname , mail_from , machine , local ):
3409+ smtp_hostname , mail_from , machine : bool , local : bool ):
34103410 """
34113411 Configure several paths for autosubmit: database, local root and others. Can be configured at system,
34123412 user or local levels. Local level configuration precedes user level and user level precedes system
@@ -3486,61 +3486,54 @@ def configure(advanced, database_path, database_filename, local_root_path, platf
34863486 Log .error ("jobs.yml path does not exist." )
34873487 return False
34883488
3489- if machine :
3490- rc_path = '/etc'
3491- elif local :
3492- rc_path = '.'
3493- else :
3494- rc_path = home_path
3495- rc_path = rc_path .joinpath ('.autosubmitrc' )
3489+ rc_path : Path = get_rc_path (machine , local )
34963490
3497- config_file = open (rc_path , 'w' )
3498- Log .info ("Writing configuration file..." )
3499- try :
3500- parser = ConfigParser ()
3501- parser .add_section ('database' )
3502- parser .set ('database' , 'path' , str (database_path ))
3503- if database_filename is not None and len (str (database_filename )) > 0 :
3504- parser .set ('database' , 'filename' , str (database_filename ))
3505- parser .add_section ('local' )
3506- parser .set ('local' , 'path' , str (local_root_path ))
3507- if (jobs_conf_path is not None and len (str (jobs_conf_path )) > 0 ) or (
3508- platforms_conf_path is not None and len (str (platforms_conf_path )) > 0 ):
3509- parser .add_section ('conf' )
3510- if jobs_conf_path is not None :
3511- parser .set ('conf' , 'jobs' , str (jobs_conf_path ))
3512- if platforms_conf_path is not None :
3513- parser .set ('conf' , 'platforms' , str (platforms_conf_path ))
3514- if smtp_hostname is not None or mail_from is not None :
3515- parser .add_section ('mail' )
3516- parser .set ('mail' , 'smtp_server' , smtp_hostname )
3517- parser .set ('mail' , 'mail_from' , mail_from )
3518- parser .add_section ("globallogs" )
3519- parser .set ("globallogs" , "path" , str (global_logs_path ))
3520- parser .add_section ("structures" )
3521- parser .set ("structures" , "path" , str (structures_path ))
3522- parser .add_section ("historicdb" )
3523- parser .set ("historicdb" , "path" , str (historicdb_path ))
3524- parser .add_section ("historiclog" )
3525- parser .set ("historiclog" , "path" , str (historiclog_path ))
3526- parser .add_section ("autosubmitapi" )
3527- parser .set ("autosubmitapi" , "url" , autosubmitapi_url )
3528- # parser.add_section("hosts")
3529- # parser.set("hosts", "whitelist", " localhost # Add your machine names")
3530- parser .write (config_file )
3531- config_file .close ()
3532- Log .result (f"Configuration file written successfully: \n \t { rc_path } " )
3533- HUtils .create_path_if_not_exists (local_root_path )
3534- HUtils .create_path_if_not_exists (global_logs_path )
3535- HUtils .create_path_if_not_exists (structures_path )
3536- HUtils .create_path_if_not_exists (historicdb_path )
3537- HUtils .create_path_if_not_exists (historiclog_path )
3538- Log .result (f"Directories configured successfully: \n \t { str (database_path )} \n \t { str (local_root_path )} "
3539- f" \n \t { str (global_logs_path )} \n \t { str (structures_path )} \n \t { str (historicdb_path )} "
3540- f" \n \t { str (historiclog_path )} " )
3541- except (IOError , OSError ) as e :
3542- raise AutosubmitCritical (
3543- "Can not write config file: {0}" , 7012 , e .message )
3491+ with open (rc_path , 'w' ) as config_file :
3492+ Log .info ("Writing configuration file..." )
3493+ try :
3494+ parser = ConfigParser ()
3495+ parser .add_section ('database' )
3496+ parser .set ('database' , 'path' , str (database_path ))
3497+ if database_filename is not None and len (str (database_filename )) > 0 :
3498+ parser .set ('database' , 'filename' , str (database_filename ))
3499+ parser .add_section ('local' )
3500+ parser .set ('local' , 'path' , str (local_root_path ))
3501+ if (jobs_conf_path is not None and len (str (jobs_conf_path )) > 0 ) or (
3502+ platforms_conf_path is not None and len (str (platforms_conf_path )) > 0 ):
3503+ parser .add_section ('conf' )
3504+ if jobs_conf_path is not None :
3505+ parser .set ('conf' , 'jobs' , str (jobs_conf_path ))
3506+ if platforms_conf_path is not None :
3507+ parser .set ('conf' , 'platforms' , str (platforms_conf_path ))
3508+ if smtp_hostname is not None or mail_from is not None :
3509+ parser .add_section ('mail' )
3510+ parser .set ('mail' , 'smtp_server' , smtp_hostname )
3511+ parser .set ('mail' , 'mail_from' , mail_from )
3512+ parser .add_section ("globallogs" )
3513+ parser .set ("globallogs" , "path" , str (global_logs_path ))
3514+ parser .add_section ("structures" )
3515+ parser .set ("structures" , "path" , str (structures_path ))
3516+ parser .add_section ("historicdb" )
3517+ parser .set ("historicdb" , "path" , str (historicdb_path ))
3518+ parser .add_section ("historiclog" )
3519+ parser .set ("historiclog" , "path" , str (historiclog_path ))
3520+ parser .add_section ("autosubmitapi" )
3521+ parser .set ("autosubmitapi" , "url" , autosubmitapi_url )
3522+ # parser.add_section("hosts")
3523+ # parser.set("hosts", "whitelist", " localhost # Add your machine names")
3524+ parser .write (config_file )
3525+ Log .result (f"Configuration file written successfully: \n \t { rc_path } " )
3526+ HUtils .create_path_if_not_exists (local_root_path )
3527+ HUtils .create_path_if_not_exists (global_logs_path )
3528+ HUtils .create_path_if_not_exists (structures_path )
3529+ HUtils .create_path_if_not_exists (historicdb_path )
3530+ HUtils .create_path_if_not_exists (historiclog_path )
3531+ Log .result (f"Directories configured successfully: \n \t { str (database_path )} \n \t { str (local_root_path )} "
3532+ f" \n \t { str (global_logs_path )} \n \t { str (structures_path )} \n \t { str (historicdb_path )} "
3533+ f" \n \t { str (historiclog_path )} " )
3534+ except (IOError , OSError ) as e :
3535+ raise AutosubmitCritical (
3536+ "Can not write config file: {0}" , 7012 , e .message )
35443537 except (AutosubmitCritical , AutosubmitError ) as e :
35453538 raise
35463539 except BaseException as e :
0 commit comments