1 """
2 Application-class that implements pyFoamCloneCase.py
3 """
4
5 from PyFoamApplication import PyFoamApplication
6
7 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
8 from PyFoam.Error import error,warning
9
10 from os import path
11
14 description="""
15 Clones a case by copying the system, constant and 0-directories
16 """
17 PyFoamApplication.__init__(self,args=args,description=description,usage="%prog <source> <destination>",interspersed=True,nr=2)
18
20 self.parser.add_option("--chemkin",
21 action="store_true",
22 dest="chemkin",
23 default=False,
24 help="Also copy the Chemkin-directory")
25 self.parser.add_option("--add-item",
26 action="append",
27 dest="additional",
28 default=[],
29 help="Add a subdirectory to the list of cloned items (can be used more often than once)")
30 self.parser.add_option("--no-pyfoam",
31 action="store_false",
32 dest="dopyfoam",
33 default=True,
34 help="Don't copy PyFoam-specific stuff")
35 self.parser.add_option("--force",
36 action="store_true",
37 dest="force",
38 default=False,
39 help="Overwrite destination if it exists")
40
42 if len(self.parser.getArgs())>2:
43 error("Too many arguments:",self.parser.getArgs()[2:],"can not be used")
44
45 sName=self.parser.getArgs()[0]
46 dName=self.parser.getArgs()[1]
47
48 if path.exists(dName):
49 if self.parser.getOptions().force:
50 warning("Replacing",dName,"(--force option)")
51 elif path.exists(path.join(dName,"system","controlDict")):
52 error("Destination",dName,"already existing and a Foam-Case")
53 elif path.isdir(dName):
54 dName=path.join(dName,path.basename(sName))
55 if path.exists(dName) and not self.parser.getOptions().force:
56 error(dName,"already existing")
57 elif not path.exists(path.dirname(dName)):
58 warning("Directory",path.dirname(dName),"does not exist. Creating")
59
60 sol=SolutionDirectory(sName,archive=None,paraviewLink=False)
61
62 if self.parser.getOptions().chemkin:
63 sol.addToClone("chemkin")
64
65 if self.parser.getOptions().dopyfoam:
66 sol.addToClone("customRegexp")
67
68 for a in self.parser.getOptions().additional:
69 sol.addToClone(a)
70
71 sol.cloneCase(dName)
72