def run(self): if len(self.parser.getArgs())>2: error("Too many arguments:",self.parser.getArgs()[2:],"can not be used") sName=self.parser.getArgs()[0] dName=self.parser.getArgs()[1] if path.exists(dName): if self.parser.getOptions().force: warning("Replacing",dName,"(--force option)") elif path.exists(path.join(dName,"system","controlDict")): error("Destination",dName,"already existing and a Foam-Case") elif path.isdir(dName): dName=path.join(dName,path.basename(sName)) if path.exists(dName) and not self.parser.getOptions().force: error(dName,"already existing") elif not path.exists(path.dirname(dName)): warning("Directory",path.dirname(dName),"does not exist. Creating") sol=SolutionDirectory(sName, archive=None, paraviewLink=False, addLocalConfig=True, parallel=self.opts.parallel) if sol.determineVCS()!=None and self.opts.vcs: if self.opts.chemkin or self.opts.additional or self.opts.latest: self.error("Using an unimplemented option together with VCS") vcsInter=getVCS(sol.determineVCS(), path=sol.name) vcsInter.clone(dName) return if self.parser.getOptions().chemkin: sol.addToClone("chemkin") if self.parser.getOptions().dopyfoam: sol.addToClone("customRegexp") for a in self.parser.getOptions().additional: sol.addToClone(a) if self.parser.getOptions().latest: sol.addToClone(sol.getLast()) if self.opts.symlinkMode: sol.symlinkCase( dName, followSymlinks=self.parser.getOptions().followSymlinks, maxLevel=self.opts.symlinkLevel, relPath=self.opts.symlinkRelative ) else: sol.cloneCase( dName, followSymlinks=self.parser.getOptions().followSymlinks ) self.addToCaseLog(dName,"Cloned to",dName)
def cloneCase(self, srcPath, dstName): dName = self.parser.getArgs()[1] srcCase = SolutionDirectory(srcPath, archive=None, paraviewLink=False, addLocalConfig=True, parallel=self.opts.parallel) if self.parser.getOptions().symlink: srcCase.symlinkCase(dstName, followSymlinks=True, maxLevel=1, relPath=True) else: srcCase.cloneCase(dstName, followSymlinks=False) print 'Copied to {:s}'.format(os.path.join(dName, dstName))
def run(self): if len(self.parser.getArgs())!=2: error("Need two arguments.",len(self.parser.getArgs()),"found") # get directory names sName=self.parser.getArgs()[0] dName=self.parser.getArgs()[1] # check if the destination directory exists if path.exists(dName): if self.parser.getOptions().force: warning("Replacing",dName,"(--force option)") elif path.exists(path.join(dName,"system","controlDict")): error("Destination",dName,"already existing and a Foam-Case") elif path.isdir(dName): dName=path.join(dName,path.basename(sName)) if path.exists(dName) and not self.parser.getOptions().force: error(dName,"already existing") elif not path.exists(path.dirname(dName)): warning("Directory",path.dirname(dName),"does not exist. Creating") # copy domain and lagrangian.org mkdir(dName) chdir(dName) domainSrc=SolutionDirectory('../%s/%s' % (sName, 'domain'), archive=None, paraviewLink=False, addLocalConfig=True, parallel=self.opts.parallel) if self.parser.getOptions().symlink: domainSrc.symlinkCase( 'domain', followSymlinks=True, maxLevel=1, relPath=True ) else: domainSrc.cloneCase( 'domain', followSymlinks=False ) print 'Copied to %s/%s' % (dName, 'domain.') lagSrc=SolutionDirectory('../%s/%s' % (sName, 'lagrangian.org'), archive=None, paraviewLink=False, addLocalConfig=True, parallel=self.opts.parallel) if self.parser.getOptions().symlink: lagSrc.symlinkCase( 'lagrangian.org', followSymlinks=True, maxLevel=1, relPath=True ) else: lagSrc.cloneCase( 'lagrangian.org', followSymlinks=False ) print 'Copied to %s/%s' % (dName, 'lagrangian.org.') # replace domain.foam by <eulerianCaseName>.foam system('mv domain/domain.foam domain/%s.foam' % dName) # replace list of files by their original if self.parser.getOptions().symlink: replaceFiles = ['domain/system/controlDict', 'domain/system/fvSchemes', 'domain/system/fvSolution', 'domain/system/RBCInletDict', 'domain/constant/polyMesh/blockMeshDict'] for f in replaceFiles: system('pyFoamSymlinkToFile.py %s' % f) system('pyFoamSymlinkToFile.py domain/0/*') # creates list of files to copy or to link to copyFiles = ['config_vars', 'geometricData', 'initialConditions', 'simParams.json', '.gitignore', 'domain/.gitignore', 'lagrangian.org/.gitignore'] symlinkFiles = [] for f in os.listdir('../%s' % sName): if f.endswith('.stl'): symlinkFiles.append(f) optionDependentFiles = \ ['Allrun', 'AllrunRestart', 'cleanCase', 'createMesh', 'makeLinks', 'prepareEulerianCase', 'prepareLagrangianCases', 'removeLinks', 'runCase'] if self.parser.getOptions().symlink: symlinkFiles.extend(optionDependentFiles) else: copyFiles.extend(optionDependentFiles) for f in copyFiles: srcName = os.path.join('..', sName,f) if os.path.isdir(srcName): if os.path.isdir(f): shutil.rmtree(f) try: shutil.copytree(srcName, f) except IOError: print 'Could not copy the directory {}'.format(srcName) else: try: shutil.copy(srcName, f) except IOError: print 'Could not copy the directory {}'.format(srcName) for f in symlinkFiles: system('ln -s ../%s/%s %s' % (sName, f, f))