Example #1
0
    def run(self):
        sol = SolutionDirectory(self.parser.getArgs()[0])
        if not self.opts.init:
            vcs = sol.determineVCS()
            if vcs == None:
                self.error("not under version control")
            if not vcs in self.vcsChoices:
                self.error("Unsupported VCS", vcs)
        else:
            vcs = self.opts.vcs

        vcsInter = getVCS(vcs, path=sol.name, init=self.opts.init)

        vcsInter.addPath(path.join(sol.name, "constant"), rules=ruleList)
        vcsInter.addPath(path.join(sol.name, "system"), rules=ruleList)
        if sol.initialDir() != None:
            vcsInter.addPath(sol.initialDir(), rules=ruleList)
        else:
            self.warning("No initial-directory found")

        # special PyFoam-files
        for f in ["customRegexp", "LocalConfigPyFoam"]:
            p = path.join(sol.name, f)
            if path.exists(p):
                vcsInter.addPath(p, rules=ruleList)

        # Add the usual files from the tutorials
        for g in ["Allrun*", "Allclean*"]:
            for f in glob(path.join(sol.name, g)):
                vcsInter.addPath(f, rules=ruleList)

        for a in self.opts.additional:
            vcsInter.addPath(a, rules=ruleList)

        vcsInter.commit(self.opts.commitMessage)
Example #2
0
    def run(self):
        if len(self.parser.getArgs())>2:
            error("Too many arguments:",self.parser.getArgs()[2:],"can not be used")

        sName=self.parser.getArgs()[0]
        dName=self.parser.getArgs()[1]

        if path.exists(dName):
            if self.parser.getOptions().force:
                warning("Replacing",dName,"(--force option)")
            elif path.exists(path.join(dName,"system","controlDict")):
                error("Destination",dName,"already existing and a Foam-Case")
            elif path.isdir(dName):
                dName=path.join(dName,path.basename(sName))
                if path.exists(dName) and not self.parser.getOptions().force:
                    error(dName,"already existing")
        elif not path.exists(path.dirname(dName)):
            warning("Directory",path.dirname(dName),"does not exist. Creating")

        sol=SolutionDirectory(sName,
                              archive=None,
                              paraviewLink=False,
                              addLocalConfig=True,
                              parallel=self.opts.parallel)

        if sol.determineVCS()!=None and self.opts.vcs:
            if self.opts.chemkin or self.opts.additional or self.opts.latest:
                self.error("Using an unimplemented option together with VCS")

            vcsInter=getVCS(sol.determineVCS(),
                            path=sol.name)
            vcsInter.clone(dName)
            return

        if self.parser.getOptions().chemkin:
            sol.addToClone("chemkin")

        if self.parser.getOptions().dopyfoam:
            sol.addToClone("customRegexp")

        for a in self.parser.getOptions().additional:
            sol.addToClone(a)

        if self.parser.getOptions().latest:
            sol.addToClone(sol.getLast())

        if self.opts.symlinkMode:
            sol.symlinkCase(
                dName,
                followSymlinks=self.parser.getOptions().followSymlinks,
                maxLevel=self.opts.symlinkLevel,
                relPath=self.opts.symlinkRelative
            )
        else:
            sol.cloneCase(
                dName,
                followSymlinks=self.parser.getOptions().followSymlinks
            )

        self.addToCaseLog(dName,"Cloned to",dName)
Example #3
0
    def run(self):
        if len(self.parser.getArgs())>2:
            error("Too many arguments:",self.parser.getArgs()[2:],"can not be used")

        sName=self.parser.getArgs()[0]
        dName=self.parser.getArgs()[1]

        if path.exists(dName):
            if self.parser.getOptions().force:
                warning("Replacing",dName,"(--force option)")
            elif path.exists(path.join(dName,"system","controlDict")):
                error("Destination",dName,"already existing and a Foam-Case")
            elif path.isdir(dName):
                dName=path.join(dName,path.basename(sName))
                if path.exists(dName) and not self.parser.getOptions().force:
                    error(dName,"already existing")
        elif not path.exists(path.dirname(dName)):
            warning("Directory",path.dirname(dName),"does not exist. Creating")

        sol=SolutionDirectory(sName,
                              archive=None,
                              paraviewLink=False,
                              addLocalConfig=True,
                              parallel=self.opts.parallel)

        if sol.determineVCS()!=None and self.opts.vcs:
            if self.opts.chemkin or self.opts.additional or self.opts.latest:
                self.error("Using an unimplemented option together with VCS")

            vcsInter=getVCS(sol.determineVCS(),
                            path=sol.name)
            vcsInter.clone(dName)
            return

        if self.parser.getOptions().chemkin:
            sol.addToClone("chemkin")

        if self.parser.getOptions().dopyfoam:
            sol.addToClone("customRegexp")

        for a in self.parser.getOptions().additional:
            sol.addToClone(a)

        if self.parser.getOptions().latest:
            sol.addToClone(sol.getLast())

        if self.opts.symlinkMode:
            sol.symlinkCase(
                dName,
                followSymlinks=self.parser.getOptions().followSymlinks,
                maxLevel=self.opts.symlinkLevel,
                relPath=self.opts.symlinkRelative
            )
        else:
            sol.cloneCase(
                dName,
                followSymlinks=self.parser.getOptions().followSymlinks
            )

        self.addToCaseLog(dName,"Cloned to",dName)
Example #4
0
    def checkAndCommit(self, sol, msg=None):
        """
        @param sol: SolutionDirectory that should be commited
        @param msg: The commit message that should be used if none is specified by the user
        """

        if self.opts.commitToVCS or self.opts.commitMessage:
            if msg == None:
                msg = path.basename(sys.argv[0])

            if self.opts.commitMessage:
                msg = self.opts.commitMessage + " (" + msg + ")"
            vcs = sol.determineVCS()
            if vcs == None:
                self.warning("Case", sol.name, "is not under version control.",
                             "Can not commit with message:", msg)
                return

            vcsInter = getVCS(vcs, path=sol.name)
            vcsInter.commit(msg)
    def checkAndCommit(self,sol,msg=None):
        """
        :param sol: SolutionDirectory that should be commited
        :param msg: The commit message that should be used if none is specified by the user
        """

        if self.opts.commitToVCS or self.opts.commitMessage:
            if msg==None:
                msg=path.basename(sys.argv[0])
                
            if self.opts.commitMessage:
                msg=self.opts.commitMessage+" ("+msg+")"
            vcs=sol.determineVCS()
            if vcs==None:
                self.warning("Case",sol.name,"is not under version control.",
                             "Can not commit with message:",msg)
                return

            vcsInter=getVCS(vcs,
                            path=sol.name)
            vcsInter.commit(msg)
Example #6
0
    def run(self):
        sol=SolutionDirectory(self.parser.getArgs()[0])
        if not self.opts.init:
            vcs=sol.determineVCS()
            if vcs==None:
                self.error("not under version control")                
            if not vcs in self.vcsChoices:
                self.error("Unsupported VCS",vcs)
        else:
            vcs=self.opts.vcs

        vcsInter=getVCS(vcs,
                        path=sol.name,
                        init=self.opts.init)

        vcsInter.addPath(path.join(sol.name,"constant"),rules=ruleList)
        vcsInter.addPath(path.join(sol.name,"system"),rules=ruleList)
        if sol.initialDir()!=None:
            vcsInter.addPath(sol.initialDir(),rules=ruleList)
        else:
            self.warning("No initial-directory found")

        # special PyFoam-files
        for f in ["customRegexp","LocalConfigPyFoam"]:
            p=path.join(sol.name,f)
            if path.exists(p):
                vcsInter.addPath(p,rules=ruleList)

        # Add the usual files from the tutorials
        for g in ["Allrun*","Allclean*"]:
            for f in glob(path.join(sol.name,g)):
                vcsInter.addPath(f,rules=ruleList)
                
        for a in self.opts.additional:
            vcsInter.addPath(a,rules=ruleList)
            
        vcsInter.commit(self.opts.commitMessage)
Example #7
0
    def run(self):
        if not self.opts.actions:
            self.error("No action defined")

        dirs=[]
        if self.opts.openfoam and "WM_PROJECT_DIR" in environ:
            dirs.append(environ["WM_PROJECT_DIR"])
        dirs+=self.parser.getArgs()
        if self.opts.currentDir:
            dirs.append(path.curdir)

        fullDirs=[]
        for d in dirs:
            if path.isdir(d):
                fullDirs.append(path.abspath(d))

        info=dict(list(zip(fullDirs,[{} for i in range(len(fullDirs))])))

        for d in fullDirs:
            info[d]["writable"]=os.access(d,os.W_OK)

            info[d]["isFoam"]=(d==fullDirs[0] and self.opts.openfoam)

            info[d]["vcs"]=whichVCS(d)

            if path.exists(path.join(d,"Allwmake")):
                info[d]["make"]="Allwmake"
            elif path.exists(path.join(d,"Makefile")):
                info[d]["make"]="make"
            else:
                info[d]["make"]="wmake"

            if info[d]["vcs"]=="":
                info[d]["branch"]="unknown"
            else:
                vcs=getVCS(info[d]["vcs"],
                           d,
                           tolerant=True)
                if vcs:
                    try:
                        info[d]["branch"]=vcs.branchName()
                    except FatalErrorPyFoamException:
                        info[d]["branch"]="notImplemented"

                    try:
                        info[d]["revision"]=vcs.getRevision()
                    except FatalErrorPyFoamException:
                        info[d]["revision"]="notImplemented"
                else:
                    info[d]["branch"]="noVCS"
                    info[d]["revision"]="noVCS"

        for action in self.opts.actions:
            if action=="info":
                print_("Project directories:\n")
                for i,d in enumerate(fullDirs):
                    print_("%2d.  %s" % (i+1,d))
                    print_("    ",info[d])
                    print_()

                self.setData({'order' : fullDirs,
                              'info'  : info})
            elif action=="name":
                name=""
                if self.opts.openfoam:
                    name+="%s-%s_%s_%s_%s" % (environ["WM_PROJECT"],
                                              environ["WM_PROJECT_VERSION"],
                                              environ["WM_ARCH"],
                                              environ["WM_OPTIONS"],
                                              environ["WM_MPLIB"])
                else:
                    name+="%s_%s" % (uname()[0],
                                     uname()[-1])
                name += "_branch-%s" % info[fullDirs[-1]]["branch"]

                print_(name)
                self.setData({'name'   : name,
                              'info'   : info,
                              'order'  : fullDirs})
            elif action=="update":
                success=True
                for d in fullDirs:
                    if info[d]["writable"]:
                        print_("Attempting to update",d)
                        print_()
                        vcs=getVCS(info[d]["vcs"],
                                   d,
                                   tolerant=True)
                        if vcs:
                            try:
                                if not vcs.update(timeout=self.opts.timeout):
                                    success=False
                            except FatalErrorPyFoamException:
                                e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e'
                                print_("Problem:",e)
                                success=False
                        else:
                            print_("Not under version control ... skipping")
                            success=False
                    else:
                        print_(d,"not writable .... skipping update")

                    print_()
                if not success:
                    self.error("Problem during updating")
            elif action=="build":
                success=True
                oldDir=os.getcwd()

                for d in fullDirs:
                    if info[d]["writable"]:
                        print_("Attempting to build",d)
                        print_()
                        makeCommand={"make"    :["make"],
                                     "wmake"   :["wmake"],
                                     "Allwmake":["./Allwmake"]}[info[d]["make"]]

                        print_("Changing to",d,"and executing"," ".join(makeCommand))
                        print_()
                        os.chdir(d)
                        erg=subprocess.call(makeCommand)
                        if erg:
                            print_()
                            print_("Result of build command:",erg)
                            success=False
                    else:
                        print_(d,"not writable .... skipping build")

                    print_()

                os.chdir(oldDir)

                if not success:
                    self.error("Problem during building")

            else:
                self.error("Unimplemented action",action)
Example #8
0
    def run(self):
        if not self.opts.action:
            self.error("No action defined")

        dirs=[]
        if self.opts.openfoam and "WM_PROJECT_DIR" in environ:
            dirs.append(environ["WM_PROJECT_DIR"])
        dirs+=self.parser.getArgs()
        if self.opts.currentDir:
            dirs.append(path.curdir)

        fullDirs=[]
        for d in dirs:
            if path.isdir(d):
                fullDirs.append(path.abspath(d))

        info=dict(zip(fullDirs,[{} for i in range(len(fullDirs))]))

        for d in fullDirs:
            info[d]["writable"]=os.access(d,os.W_OK)

            info[d]["isFoam"]=(d==fullDirs[0] and self.opts.openfoam)
                
            info[d]["vcs"]=whichVCS(d)

            if path.exists(path.join(d,"Allwmake")):
                info[d]["make"]="Allwmake"
            elif path.exists(path.join(d,"Makefile")):
                info[d]["make"]="make"
            else:
                info[d]["make"]="wmake"

            if info[d]["vcs"]=="":
                info[d]["branch"]="unknown"
            else:
                vcs=getVCS(info[d]["vcs"],
                           d,
                           tolerant=True)
                if vcs:
                    try:
                        info[d]["branch"]=vcs.branchName()
                    except FatalErrorPyFoamException:
                        info[d]["branch"]="notImplemented"
                        
                    try:
                        info[d]["revision"]=vcs.getRevision()
                    except FatalErrorPyFoamException:
                        info[d]["revision"]="notImplemented"
                else:
                    info[d]["branch"]="noVCS"
                    info[d]["revision"]="noVCS"

        if self.opts.action=="info":
            print "Project directories:\n"
            for i,d in enumerate(fullDirs):
                print "%2d.  %s" % (i+1,d)
                print "    ",info[d]
                print

            self.setData({'order' : fullDirs,
                          'info'  : info})
        elif self.opts.action=="name":
            name=""
            if self.opts.openfoam:
                name+="%s-%s_%s_%s_%s" % (environ["WM_PROJECT"],
                                          environ["WM_PROJECT_VERSION"],
                                          environ["WM_ARCH"],
                                          environ["WM_OPTIONS"],
                                          environ["WM_MPLIB"])
            else:
                name+="%s_%s" % (os.uname()[0],
                                 os.uname()[-1])
            name += "_branch-%s" % info[fullDirs[-1]]["branch"]

            print name
            self.setData({'name'   : name,
                          'info'   : info,
                          'order'  : fullDirs})
        elif self.opts.action=="update":
            success=True
            for d in fullDirs:
                if info[d]["writable"]:
                    print "Attempting to update",d
                    print
                    vcs=getVCS(info[d]["vcs"],
                               d,
                               tolerant=True)
                    if vcs:
                        try:
                            if not vcs.update(timeout=self.opts.timeout):
                                success=False
                        except FatalErrorPyFoamException,e:
                            print "Problem:",e
                            success=False
                    else:
                        print "Not under version control ... skipping"
                        success=False
                else:
                    print d,"not writable .... skipping update"
                
                print
            if not success:
                self.error("Problem during updating")