1 """
2 Application-class that implements pyFoamPackCase.py
3 """
4
5 from PyFoamApplication import PyFoamApplication
6
7 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
8
9 from os import path
10 from optparse import OptionGroup
11
14 description="""
15 Packs a case into a tar-file copying the system, constant and 0-directories.
16 Excludes all .svn-direcotries and all files ending with ~
17 """
18 PyFoamApplication.__init__(self,
19 args=args,
20 description=description,
21 usage="%prog <case>",
22 interspersed=True,
23 changeVersion=False,
24 nr=1)
25
27 what=OptionGroup(self.parser,
28 "What",
29 "Define what should be packed")
30 self.parser.add_option_group(what)
31
32 what.add_option("--last",
33 action="store_true",
34 dest="last",
35 default=False,
36 help="Also add the last time-step")
37 what.add_option("--pyfoam",
38 action="store_true",
39 dest="pyfoam",
40 default=False,
41 help="Add all files starting with PyFoam to the tarfile")
42 what.add_option("--chemkin",
43 action="store_true",
44 dest="chemkin",
45 default=False,
46 help="Also add the Chemkin-directory")
47 what.add_option("--add",
48 action="append",
49 dest="additional",
50 default=[],
51 help="Add all files and directories in the case directory that fit a glob-pattern to the tar (can be used more than once)")
52 what.add_option("--exclude",
53 action="append",
54 dest="exclude",
55 default=[],
56 help="Exclude all files and directories that fit this glob pattern from being added, no matter at level (can be used more than once)")
57 what.add_option("--no-polyMesh",
58 action="store_true",
59 dest="noPloyMesh",
60 help="Exclude the polyMesh-directory")
61 self.parser.add_option("--tarname",
62 action="store",
63 dest="tarname",
64 default=None,
65 help='Name of the tarfile. If unset the name of the case plus ".tgz" will be used')
66 self.parser.add_option("--base-name",
67 action="store",
68 dest="basename",
69 default=None,
70 help='Name of the case inside the tar-file. If not set the actual basename of the case is used')
71
73 sName=self.parser.getArgs()[0]
74 if sName[-1]==path.sep:
75 sName=sName[:-1]
76
77 if self.parser.getOptions().tarname!=None:
78 dName=self.parser.getOptions().tarname
79 else:
80 dName=sName+".tgz"
81 if self.parser.getOptions().pyfoam:
82 self.parser.getOptions().additional.append("PyFoam*")
83
84 sol=SolutionDirectory(sName,archive=None,paraviewLink=False)
85 if not sol.isValid():
86 self.error(sName,"does not look like real OpenFOAM-case because",sol.missingFiles(),"are missing or of the wrong type")
87
88 if self.parser.getOptions().chemkin:
89 sol.addToClone("chemkin")
90
91 if self.opts.noPloyMesh:
92 self.parser.getOptions().exclude.append("polyMesh")
93
94 sol.packCase(dName,
95 last=self.parser.getOptions().last,
96 additional=self.parser.getOptions().additional,
97 exclude=self.parser.getOptions().exclude,
98 base=self.parser.getOptions().basename)
99