#!/usr/bin/env python# -*- coding: utf-8 -*-'''init_sim.pyinitialize a new simulation directory structure using `pwd` as the rootdirectory.If there are files present in this directory defined in the directorystructure, they will me moved to the corresponding directoriescommand -s: if this parameter reads "silent", don't print any warnings.'''importosimportshutilfromoptparseimportOptionParserimportcrtomo.cfg
[docs]defhandle_cmd_options():''' Get the options from the command line. '''parser=OptionParser()parser.add_option("-s","--silent",action="store_true",dest="silent",help="print any warnings",default=False)(options,args)=parser.parse_args()returnoptions,args
[docs]defmove(fname,folder,options):"""Move file to dir if existing """ifos.path.isfile(fname):shutil.move(fname,folder)else:ifoptions.silentisFalse:print('{0} missing'.format(fname))
[docs]defmain():(options,args)=handle_cmd_options()foriin['config','exe','grid','mod','mod/sens','mod/pot','inv','rho']:os.mkdir(i)files=['config.dat','elem.dat','elec.dat','rho.dat','volt.dat','crt.noisemod','decoupling.dat']folders=['config','grid','grid','rho','mod','exe','exe']fori,jinzip(files,folders):move(i,j,options)ifos.path.isfile('crmod.cfg'):shutil.move('crmod.cfg','exe')elifos.path.isfile('config/config.dat'):# only copy the crmod.cfg file if a config.dat file existscfg=crtomo.cfg.crmod_config()cfg.write_to_file('exe/crmod.cfg')ifos.path.isfile('crtomo.cfg'):shutil.move('crtomo.cfg','exe')else:cfg=crtomo.cfg.crtomo_config()cfg.write_to_file('exe/crtomo.cfg')