1 """
2 Class that implements the common functionality commiting cases to the VCS
3 """
4
5 from optparse import OptionGroup
6 from os import path
7 import sys
8
9 from PyFoam.Basics.GeneralVCSInterface import getVCS
10
12 """ The class that defines options for commiting cases
13 """
14
16 grp=OptionGroup(self.parser,
17 "Commit to VCS",
18 "Whether a VCS-controlled case should be commited")
19
20 grp.add_option("--commit-to-vcs",
21 action="store_true",
22 dest="commitToVCS",
23 default=False,
24 help="Should the case be commited before further action is taken")
25
26 grp.add_option("--message-to-commit",
27 dest="commitMessage",
28 default=None,
29 help="Message that should go along with the commit. If undefined an automatic mesage is used. If undefined implicitly assumes --commit-to-vcs")
30
31 self.parser.add_option_group(grp)
32
34 """
35 @param sol: SolutionDirectory that should be commited
36 @param msg: The commit message that should be used if none is specified by the user
37 """
38
39 if self.opts.commitToVCS or self.opts.commitMessage:
40 if msg==None:
41 msg=path.basename(sys.argv[0])
42
43 if self.opts.commitMessage:
44 msg=self.opts.commitMessage+" ("+msg+")"
45 vcs=sol.determineVCS()
46 if vcs==None:
47 self.warning("Case",sol.name,"is not under version control.",
48 "Can not commit with message:",msg)
49 return
50
51 vcsInter=getVCS(vcs,
52 path=sol.name)
53 vcsInter.commit(msg)
54