Esempio n. 1
0
    def run(self):
        if self.pathInfo():
            return
        
        if len(self.parser.getArgs())<1:
            error("No description file given")

        fName=self.searchDescriptionFile(self.parser.getArgs()[0])
        
        desc=CaseBuilderFile(fName)

        print "Read case description",desc.name()

        stopIt=False
        
        if self.opts.long:
            self.opts.short=True
            self.opts.args=True
            self.opts.bounds=True
            self.opts.help=True
            
        if self.opts.short:
            print
            print "Description:      ",desc.description()
            print "Template:         ",desc.templatePath()
            print "Initial Condition:",desc.initialDir()
            stopIt=True
            
        if self.opts.help:
            self.printTitle("Help")
            print desc.helpText()
            stopIt=True
            
        if self.opts.args:
            args=desc.arguments()
            mLen=apply(max,map(len,args))
            aDesc=desc.argumentDescriptions()
            format="%%%ds : %%s" % mLen
            
            self.printTitle("Arguments")
            for a in args:
                print format % (a,aDesc[a])
            stopIt=True

        if self.opts.bounds:
            bounds=desc.boundaries()
            mLen=apply(max,map(len,bounds))
            bDesc=desc.boundaryDescriptions()
            bPat=desc.boundaryPatternDict()
            format="%%%ds : %%s \n\tPattern: '%%s'" % mLen
            
            self.printTitle("Boundaries")
            for i,a in enumerate(bounds):
                print format % (a,bDesc[a],bPat[a])
            stopIt=True

        if stopIt:
            print
            print "Not doing anything"
            return
        
        args=desc.arguments()

        if len(self.parser.getArgs())<2:
            error("Missing a casename:",self.buildUsage(args))

        cName=self.parser.getArgs()[1]
        if len(self.parser.getArgs())!=len(args)+2:
            error("Wrong number of arguments:",self.buildUsage(args))

        aDict={}
        for i,a in enumerate(args):
            tmp=self.parser.getArgs()[2+i]
            if (tmp[0]=='"' or tmp[0]=="'") and tmp[0]==tmp[-1]:
                tmp=tmp[1:-1]
            aDict[a]=tmp

        if path.exists(cName):
            if self.opts.force:
                shutil.rmtree(cName)
            else:
                error("Case directory",cName,"already exists")
                
        print "Building case",cName

        msg=desc.verifyArguments(aDict)
        if msg:
            error("Error verifying arguments:",msg)
            
        desc.buildCase(cName,aDict)