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
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 ()
@@ -190,11 +203,16 @@ def preprocess_traces():
190203
191204 if config .dimemas_path :
192205 set_dimemas_path (config .dimemas_path )
193-
206+
194207 if config .tmpdir_path :
195208 set_tmpdir_path (config .tmpdir_path )
196-
197- TraceSet (config .traces , force_recalculation = config .force_recalculation , chop_to_roi = config .chop_to_roi , outpath = config .outfile_path )
209+
210+ TraceSet (
211+ config .traces ,
212+ force_recalculation = config .force_recalculation ,
213+ chop_to_roi = config .chop_to_roi ,
214+ outpath = config .outfile_path ,
215+ )
198216
199217
200218def dimemas_idealise ():
@@ -209,3 +227,39 @@ def dimemas_idealise():
209227 for tracefile in tqdm (config .traces , desc = "Running Dimemas" ):
210228 outfile = tracefile .split (".prv" )[0 ] + ".sim.prv"
211229 dimemas_idealise (tracefile , outfile )
230+
231+
232+ def _copy_examples_parse_args ():
233+
234+ # make an argument parser
235+ parser = ArgumentParser (description = "Copy PyPOP example files to a user directory" )
236+
237+ # First define collection of traces
238+ parser .add_argument (
239+ "target_dir" ,
240+ type = str ,
241+ nargs = "?" ,
242+ metavar = "dir" ,
243+ help = "Target directory (default is current working dir)" ,
244+ )
245+
246+ return parser .parse_args ()
247+
248+
249+ def copy_examples ():
250+ """Entrypoint for example copy routine
251+ """
252+
253+ config = _copy_examples_parse_args ()
254+
255+ outpath = (
256+ getcwd () if config .target_dir is None else expanduser (config .target_dir )
257+ )
258+
259+ outpath = normpath (path_join (outpath , 'pypop_examples' ))
260+
261+ try :
262+ copytree (examples_directory (), outpath )
263+ except shutil_error as err :
264+ print ("Copy failed: {}" .format (str (err )))
265+ return - 1
0 commit comments