Package PyFoam :: Package Applications :: Module InitVCSCase
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.InitVCSCase

  1  """ 
  2  Application-class that implements pyFoamInitVCSCase.py 
  3  """ 
  4  from optparse import OptionGroup 
  5   
  6  from PyFoamApplication import PyFoamApplication 
  7   
  8  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
  9   
 10  from PyFoam.Basics.GeneralVCSInterface import getVCS 
 11   
 12  from os import path 
 13   
 14  ruleList=[(False,".*\\.gz$"), 
 15            (False,".+~$")] 
 16   
17 -def addRegexpInclude(option,opt,value,parser,*args,**kwargs):
18 ruleList.append((True,value))
19
20 -def addRegexpExclude(option,opt,value,parser,*args,**kwargs):
21 ruleList.append((False,value))
22
23 -class InitVCSCase(PyFoamApplication):
24 - def __init__(self,args=None):
25 description=""" 26 This utility initializes a Version Control System (VCS) in an 27 OpenFOAM-directory. Certain parts of PyFoam take advantages of this. 28 29 Currenty only Mercurial is supported as a VCS-backend 30 """ 31 PyFoamApplication.__init__(self, 32 args=args, 33 description=description, 34 usage="%prog <caseDirectory>", 35 interspersed=True, 36 changeVersion=False, 37 nr=1, 38 exactNr=False)
39
40 - def addOptions(self):
41 what=OptionGroup(self.parser, 42 "What", 43 "What should be added to version control") 44 self.parser.add_option_group(what) 45 46 what.add_option("--include-files", 47 action="callback", 48 callback=addRegexpInclude, 49 type="string", 50 help="Files that should be added in instead of the usual suspects (Regular expression)") 51 what.add_option("--exclude-files", 52 action="callback", 53 callback=addRegexpExclude, 54 type="string", 55 help="Files that should not be added (regular expression)") 56 what.add_option("--additional", 57 action="append", 58 dest="additional", 59 default=[], 60 help="Additional files and directories to be added") 61 62 vcs=OptionGroup(self.parser, 63 "VCS System", 64 "Control the source-control system") 65 self.parser.add_option_group(vcs) 66 67 vcs.add_option("--no-init", 68 action="store_false", 69 default=True, 70 dest="init", 71 help="Don't initialize the repository (assumes that it is already under source control)") 72 73 self.vcsChoices=["hg"] 74 vcs.add_option("--vcs", 75 type="choice", 76 default="hg", 77 dest="vcs", 78 action="store", 79 choices=self.vcsChoices, 80 help="Which VCS should be used (Choices: "+", ".join(self.vcsChoices)+") Default: %default") 81 82 how=OptionGroup(self.parser, 83 "Behaviour", 84 "What should be done") 85 self.parser.add_option_group(vcs) 86 87 vcs.add_option("--commit-message", 88 action="store", 89 default="Initial commit", 90 dest="commitMessage", 91 help="Message that should be added to the initial commit")
92
93 - def run(self):
94 sol=SolutionDirectory(self.parser.getArgs()[0]) 95 if not self.opts.init: 96 vcs=sol.determineVCS() 97 if vcs==None: 98 self.error("not under version control") 99 if not vcs in self.vcsChoices: 100 self.error("Unsupported VCS",vcs) 101 else: 102 vcs=self.opts.vcs 103 104 vcsInter=getVCS(vcs, 105 path=sol.name, 106 init=self.opts.init) 107 108 vcsInter.addPath(path.join(sol.name,"constant"),rules=ruleList) 109 vcsInter.addPath(path.join(sol.name,"system"),rules=ruleList) 110 vcsInter.addPath(sol.initialDir(),rules=ruleList) 111 vcsInter.addPath(path.join(sol.name,"customRegexp"),rules=ruleList) 112 for a in self.opts.additional: 113 vcsInter.addPath(a,rules=ruleList) 114 115 vcsInter.commit(self.opts.commitMessage)
116