7
7
from sorcha .modules .PPConfigParser import PPFindDirectoryOrExit
8
8
9
9
10
- def copy_demo_configs (copy_location , which_configs ):
10
+ def copy_demo_configs (copy_location , which_configs , force_overwrite ):
11
11
"""
12
12
Copies the example Sorcha configuration files to a user-specified location.
13
13
@@ -19,6 +19,9 @@ def copy_demo_configs(copy_location, which_configs):
19
19
which_configs : string
20
20
String indicating which configuration files to retrieve. Should be "rubin", "demo" or "all".
21
21
22
+ force_overwrite: boolean
23
+ Flag for determining whether existing files should be overwritten.
24
+
22
25
Returns
23
26
-----------
24
27
None
@@ -49,6 +52,9 @@ def copy_demo_configs(copy_location, which_configs):
49
52
)
50
53
51
54
for config in config_locations :
55
+ if not force_overwrite and os .path .isfile (config ):
56
+ sys .exit ("Identical file exists at location. Re-run with -f or --force to force overwrite." )
57
+
52
58
shutil .copy (config , copy_location )
53
59
54
60
print ("Example configuration files {} copied to {}." .format (config_locations , copy_location ))
@@ -91,10 +97,10 @@ def main():
91
97
to a user-specified location. Filepath to copy files to is specified by command-line
92
98
flag. Selection of configuration files is done via user input.
93
99
94
- usage: sorcha_copy_configs [-h] [-f FILEPATH ]
100
+ usage: sorcha_copy_configs [-h] [-p PATH ]
95
101
arguments:
96
102
-h, --help Show this help message and exit.
97
- [-f FILEPATH , --filename FILEPATH ] Filepath where you want to copy the config files. Default is current working directory.
103
+ [-p PATH , --path PATH ] Filepath where you want to copy the config files. Default is current working directory.
98
104
99
105
Parameters
100
106
-----------
@@ -111,13 +117,21 @@ def main():
111
117
)
112
118
113
119
parser .add_argument (
114
- "-f " ,
115
- "--filepath " ,
120
+ "-p " ,
121
+ "--path " ,
116
122
help = "Filepath where you want to copy the config files. Default is current working directory." ,
117
123
type = str ,
118
124
default = "./" ,
119
125
)
120
126
127
+ parser .add_argument (
128
+ "-f" ,
129
+ "--force" ,
130
+ help = "Force deletion/overwrite of existing config file(s). Default False." ,
131
+ action = "store_true" ,
132
+ default = False ,
133
+ )
134
+
121
135
args = parser .parse_args ()
122
136
123
137
print ("\n Which configuration file(s) would you like to copy?:\n " )
@@ -128,8 +142,8 @@ def main():
128
142
129
143
which_configs = parse_file_selection (file_select )
130
144
131
- copy_location = os .path .abspath (args .filepath )
132
- copy_demo_configs (copy_location , which_configs )
145
+ copy_location = os .path .abspath (args .path )
146
+ copy_demo_configs (copy_location , which_configs , args . force )
133
147
134
148
135
149
if __name__ == "__main__" :
0 commit comments