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 behave.add_option("--symlink-mode",
82 action="store_true",
83 dest="symlinkMode",
84 default=False,
85 help="Clone in symbolic link mode. This means that all directories down to the level specified in 'symlink-level' are created and populated with symbolic links to the appropriate files. Below that level a symlink to the whole directory is created. Exception are the 'polyMesh'-directories where all files except 'blockMeshDict' are being copied. If for certain files a copy instead of the symbolic link is wanted use 'pyFoamSymlinkToFile.py'")
86 behave.add_option("--symlink-level",
87 action="store",
88 dest="symlinkLevel",
89 type=int,
90 default=1,
91 help="Level until which no symlinks to directories are created. Default: %default")
92 behave.add_option("--relative-symlink",
93 action="store_true",
94 dest="symlinkRelative",
95 default=False,
96 help="With '--symlink-mode' make the symbolic links relative instead of absolute")
98 if len(self.parser.getArgs())>2:
99 error("Too many arguments:",self.parser.getArgs()[2:],"can not be used")
100
101 sName=self.parser.getArgs()[0]
102 dName=self.parser.getArgs()[1]
103
104 if path.exists(dName):
105 if self.parser.getOptions().force:
106 warning("Replacing",dName,"(--force option)")
107 elif path.exists(path.join(dName,"system","controlDict")):
108 error("Destination",dName,"already existing and a Foam-Case")
109 elif path.isdir(dName):
110 dName=path.join(dName,path.basename(sName))
111 if path.exists(dName) and not self.parser.getOptions().force:
112 error(dName,"already existing")
113 elif not path.exists(path.dirname(dName)):
114 warning("Directory",path.dirname(dName),"does not exist. Creating")
115
116 sol=SolutionDirectory(sName,
117 archive=None,
118 paraviewLink=False,
119 addLocalConfig=True,
120 parallel=self.opts.parallel)
121
122 if sol.determineVCS()!=None and self.opts.vcs:
123 if self.opts.chemkin or self.opts.additional or self.opts.latest:
124 self.error("Using an unimplemented option together with VCS")
125
126 vcsInter=getVCS(sol.determineVCS(),
127 path=sol.name)
128 vcsInter.clone(dName)
129 return
130
131 if self.parser.getOptions().chemkin:
132 sol.addToClone("chemkin")
133
134 if self.parser.getOptions().dopyfoam:
135 sol.addToClone("customRegexp")
136
137 for a in self.parser.getOptions().additional:
138 sol.addToClone(a)
139
140 if self.parser.getOptions().latest:
141 sol.addToClone(sol.getLast())
142
143 if self.opts.symlinkMode:
144 sol.symlinkCase(
145 dName,
146 followSymlinks=self.parser.getOptions().followSymlinks,
147 maxLevel=self.opts.symlinkLevel,
148 relPath=self.opts.symlinkRelative
149 )
150 else:
151 sol.cloneCase(
152 dName,
153 followSymlinks=self.parser.getOptions().followSymlinks
154 )
155
156 self.addToCaseLog(dName,"Cloned to",dName)
157
158
159