1 """
2 Application-class that implements pyFoamCloneCase.py
3 """
4
5 from optparse import OptionGroup
6
7 from PyFoamApplication import PyFoamApplication
8
9 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
10 from PyFoam.Error import error,warning
11
12 from os import path
13
14 from PyFoam.Basics.GeneralVCSInterface import getVCS
15
18 description="""\
19 Clones a case by copying the system, constant and 0-directories
20
21 If the case is under VCS then the cloning mechanism of the VCS is used
22 """
23 PyFoamApplication.__init__(self,
24 args=args,
25 description=description,
26 usage="%prog <source> <destination>",
27 changeVersion=False,
28 interspersed=True,
29 nr=2)
30
32 what=OptionGroup(self.parser,
33 "What",
34 "Define what should be cloned")
35 self.parser.add_option_group(what)
36
37 what.add_option("--chemkin",
38 action="store_true",
39 dest="chemkin",
40 default=False,
41 help="Also copy the Chemkin-directory")
42 what.add_option("--add-item",
43 action="append",
44 dest="additional",
45 default=[],
46 help="Add a subdirectory to the list of cloned items (can be used more often than once)")
47 what.add_option("--no-pyfoam",
48 action="store_false",
49 dest="dopyfoam",
50 default=True,
51 help="Don't copy PyFoam-specific stuff")
52 what.add_option("--latest-time",
53 action="store_true",
54 dest="latest",
55 default=[],
56 help="Add the latest time-step")
57
58 behave=OptionGroup(self.parser,
59 "Behaviour")
60 self.parser.add_option_group(behave)
61 behave.add_option("--parallel",
62 action="store_true",
63 dest="parallel",
64 default=False,
65 help="Clone the processor-directories")
66 behave.add_option("--force",
67 action="store_true",
68 dest="force",
69 default=False,
70 help="Overwrite destination if it exists")
71 behave.add_option("--follow-symlinks",
72 action="store_true",
73 dest="followSymlinks",
74 default=False,
75 help="Follow symlinks instead of just copying them")
76 behave.add_option("--no-vcs",
77 action="store_false",
78 dest="vcs",
79 default=True,
80 help="Do NOT use the VCS-clone mechanism if the case is under source control")
81
83 if len(self.parser.getArgs())>2:
84 error("Too many arguments:",self.parser.getArgs()[2:],"can not be used")
85
86 sName=self.parser.getArgs()[0]
87 dName=self.parser.getArgs()[1]
88
89 if path.exists(dName):
90 if self.parser.getOptions().force:
91 warning("Replacing",dName,"(--force option)")
92 elif path.exists(path.join(dName,"system","controlDict")):
93 error("Destination",dName,"already existing and a Foam-Case")
94 elif path.isdir(dName):
95 dName=path.join(dName,path.basename(sName))
96 if path.exists(dName) and not self.parser.getOptions().force:
97 error(dName,"already existing")
98 elif not path.exists(path.dirname(dName)):
99 warning("Directory",path.dirname(dName),"does not exist. Creating")
100
101 sol=SolutionDirectory(sName,
102 archive=None,
103 paraviewLink=False,
104 parallel=self.opts.parallel)
105
106 if sol.determineVCS()!=None and self.opts.vcs:
107 if self.opts.chemkin or self.opts.additional or self.opts.latest:
108 self.error("Using an unimplemented option together with VCS")
109
110 vcsInter=getVCS(sol.determineVCS(),
111 path=sol.name)
112 vcsInter.clone(dName)
113 return
114
115 if self.parser.getOptions().chemkin:
116 sol.addToClone("chemkin")
117
118 if self.parser.getOptions().dopyfoam:
119 sol.addToClone("customRegexp")
120
121 for a in self.parser.getOptions().additional:
122 sol.addToClone(a)
123
124 if self.parser.getOptions().latest:
125 sol.addToClone(sol.getLast())
126
127 sol.cloneCase(
128 dName,
129 followSymlinks=self.parser.getOptions().followSymlinks
130 )
131
132 self.addToCaseLog(dName,"Cloned to",dName)
133