44
55"""CLI Analysis scripts"""
66
7+ from os import getcwd
8+ from os .path import expanduser , join as path_join , normpath
9+ from shutil import copytree , Error as shutil_error
10+
711from matplotlib import use
812
913use ("agg" )
1216from .metrics import MPI_Metrics , MPI_OpenMP_Metrics , OpenMP_Metrics
1317from .dimemas import dimemas_idealise
1418from .config import set_dimemas_path , set_paramedir_path , set_tmpdir_path
19+ from .examples import examples_directory
1520
1621from argparse import ArgumentParser
1722
@@ -96,7 +101,9 @@ def _preprocess_traces_parse_args():
96101 )
97102
98103 parser .add_argument (
99- "--force-recalculation" , action = "store_true" , help = "Force recalculation & overwrite existing data"
104+ "--force-recalculation" ,
105+ action = "store_true" ,
106+ help = "Force recalculation & overwrite existing data" ,
100107 )
101108 parser .add_argument (
102109 "--chop-to-roi" , action = "store_true" , help = "Chop to region of interest"
@@ -108,10 +115,16 @@ def _preprocess_traces_parse_args():
108115 "--dimemas-path" , type = str , metavar = "PATH" , help = "Path to Dimemas executable"
109116 )
110117 parser .add_argument (
111- "--outfile-path" , type = str , metavar = "PATH" , help = "Path in which to save chopped/ideal traces"
118+ "--outfile-path" ,
119+ type = str ,
120+ metavar = "PATH" ,
121+ help = "Path in which to save chopped/ideal traces" ,
112122 )
113123 parser .add_argument (
114- "--tmpdir-path" , type = str , metavar = "PATH" , help = "Path for PyPOP to save temporary files"
124+ "--tmpdir-path" ,
125+ type = str ,
126+ metavar = "PATH" ,
127+ help = "Path for PyPOP to save temporary files" ,
115128 )
116129
117130 return parser .parse_args ()
@@ -221,11 +234,16 @@ def preprocess_traces():
221234
222235 if config .dimemas_path :
223236 set_dimemas_path (config .dimemas_path )
224-
237+
225238 if config .tmpdir_path :
226239 set_tmpdir_path (config .tmpdir_path )
227-
228- TraceSet (config .traces , force_recalculation = config .force_recalculation , chop_to_roi = config .chop_to_roi , outpath = config .outfile_path )
240+
241+ TraceSet (
242+ config .traces ,
243+ force_recalculation = config .force_recalculation ,
244+ chop_to_roi = config .chop_to_roi ,
245+ outpath = config .outfile_path ,
246+ )
229247
230248
231249def dimemas_idealise ():
@@ -240,3 +258,39 @@ def dimemas_idealise():
240258 for tracefile in tqdm (config .traces , desc = "Running Dimemas" ):
241259 outfile = tracefile .split (".prv" )[0 ] + ".sim.prv"
242260 dimemas_idealise (tracefile , outfile )
261+
262+
263+ def _copy_examples_parse_args ():
264+
265+ # make an argument parser
266+ parser = ArgumentParser (description = "Copy PyPOP example files to a user directory" )
267+
268+ # First define collection of traces
269+ parser .add_argument (
270+ "target_dir" ,
271+ type = str ,
272+ nargs = "?" ,
273+ metavar = "dir" ,
274+ help = "Target directory (default is current working dir)" ,
275+ )
276+
277+ return parser .parse_args ()
278+
279+
280+ def copy_examples ():
281+ """Entrypoint for example copy routine
282+ """
283+
284+ config = _copy_examples_parse_args ()
285+
286+ outpath = (
287+ getcwd () if config .target_dir is None else expanduser (config .target_dir )
288+ )
289+
290+ outpath = normpath (path_join (outpath , 'pypop_examples' ))
291+
292+ try :
293+ copytree (examples_directory (), outpath )
294+ except shutil_error as err :
295+ print ("Copy failed: {}" .format (str (err )))
296+ return - 1
0 commit comments