Esempio n. 1
0
    def testParse(self):
        t_str = 'DUMMY TYPE=CHAR SET=DUMMY DEFAULT=DUMMY\n'
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(t_str)
        paramDefs = paramObj.paramDict
Esempio n. 2
0
    def testParse3(self):
        t_str = '''PARTMODE TYPE=NUMBER FORMAT=%8.10f DEFAULT=-8 NOP=NOP\n'''
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(t_str)
        paramDefs = paramObj.paramDict
        ex = paramDefs['PARTMODE']
        self.assertEqual('%8.10f', ex.getParamDefForParamMap()['FORMAT'])
Esempio n. 3
0
    def testParse2(self):
        t_str = '''BINMODE TYPE=NUMBER FORMAT=%-5.5d  MIN=-10  DEFAULT=9 NOP=NOP\n'''
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(t_str)
        paramDefs = paramObj.paramDict
        ex = paramDefs['BINMODE']
        self.assertEqual('%-5.5d', ex.getParamDefForParamMap()['FORMAT'])
Esempio n. 4
0
    def testParse1(self):
        t_str = '''GAIN TYPE=NUMBER FORMAT=%ld DEFAULT=-7 NOP=NOP\n'''
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(t_str)
        paramDefs = paramObj.paramDict
        ex = paramDefs['GAIN']
        self.assertEqual('%ld', ex.getParamDefForParamMap()['FORMAT'])
Esempio n. 5
0
    def testFuncRef(self):
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(FuncRefTestCase.funcref_sample)
        paramDefs = paramObj.paramDict
        f1 = paramDefs['FRAME1'].getParamDefForParamMap()
        self.assertEquals('&GET_F_NO[SPCAM A]', f1['DEFAULT'])
        self.assertEquals('NOP', f1['NOP'])
Esempio n. 6
0
    def testParse(self):
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(QuatedListTestCase.t_str)
        paramDefs = paramObj.paramDict
        ex = paramDefs['SELECT']
        logger.debug(repr(ex.getParamDefForParamMap()['SET']))

        self.assertEqual('NOP', ex.getParamDefForParamMap()['DEFAULT'])
        self.assertEqual('NOP', ex.getParamDefForParamMap()['NOP'])
Esempio n. 7
0
    def __init__(self, logger):
        self.logger = logger
        self.parser = CommandParser.CommandParser()

        self.para_lexer = para_lexer.paraScanner(logger=logger, debug=0)
        self.para_parser = paraParser(self.para_lexer, logger=logger,
                                      debug=0)

        self.para = Bunch.threadSafeBunch()
        self.userRegMap = Bunch.threadSafeBunch()
        self.systemRegMap = Bunch.threadSafeBunch()
        self.commandRegMap = Bunch.threadSafeBunch()
Esempio n. 8
0
    def testParse2(self):
        # NOP in the SET should have been deleted
        t_str = '''
        UNIT   TYPE=CHAR DEFAULT=NOP NOP=NOP SET=ALL,CAMVME,SPGVME,UNA3,TC1,TC2,TC3,UNA7,ARYELEC,TM1,TM2,CAM_MTR,SPG_MTR,VAC1,UTSTRIP,UNB8,NOP
        '''
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(t_str)
        paramDefs = paramObj.paramDict
        logger.debug(repr(paramDefs))
        ex = paramDefs['UNIT']
        self.assertEqual('NOP', ex.getParamDefForParamMap()['DEFAULT'])
        self.assertEqual('NOP', ex.getParamDefForParamMap()['NOP'])
        self.assert_(not (
            ex.getParamDefForParamMap()['SET']).__contains__('NOP'))
Esempio n. 9
0
    def testParse1(self):
        t_str = '''
        UNIT   TYPE=CHAR DEFAULT=NOP NOP=NOP SET=ALL,CAMVME,SPGVME,UNA3,TC1,TC2,TC3,UNA7,ARYELEC,TM1,TM2,CAM_MTR,SPG_MTR,VAC1,UTSTRIP,UNB8
        CMD    TYPE=CHAR DEFAULT=NOP NOP=NOP SET=ON,OFF,STATUS
        '''
        lexer = para_lexer.paraScanner(logger=logger, debug=0)
        parser = paraParser(lexer, logger=logger, debug=0)

        paramObj = parser.parse_buf(t_str)
        paramDefs = paramObj.paramDict
        logger.debug(repr(paramDefs))
        ex = paramDefs['UNIT']
        self.assertEqual('NOP', ex.getParamDefForParamMap()['DEFAULT'])
        self.assertEqual('NOP', ex.getParamDefForParamMap()['NOP'])

        ex = paramDefs['CMD']
        self.assertEqual('NOP', ex.getParamDefForParamMap()['DEFAULT'])
        self.assertEqual('NOP', ex.getParamDefForParamMap()['NOP'])
Esempio n. 10
0
    def setUp(self):
        self.lexer = para_lexer.paraScanner(logger=logger, debug=0)
        self.parser = paraParser(self.lexer, logger=logger, debug=0)

        self.paramObj = self.parser.parse_buf(test_str1)
        self.validator = ParameterHandler(self.paramObj)
Esempio n. 11
0
def main(options, args):

    import os

    # TODO: configure the logger
    logger = logging.getLogger('para.ParameterHandler')
    logger.addHandler(logging.StreamHandler())
    logger.setLevel(logging.WARN)

    lexer = para_lexer.paraScanner(logger=logger, debug=0)
    parser = paraParser(lexer, logger=logger, debug=0)

    if len(args) > 0:
        for filename in args:
            in_f = open(filename, 'r')
            buf = in_f.read()
            in_f.close()

            print(filename, ":")
            if options.scan:
                res = lexer.tokenize(buf)
                print(res)
            else:
                res = parser.parse(buf)
                print(res)

    elif options.tsctest:
        #? rootLogger = logging.getLogger()
        pattern = re.compile(r'^(\w+)\.para$')
        currentDir = os.path.split(__file__)[0]
        TSCdir = os.path.join(currentDir, "../SkPara/cmd/TSC")
        have = os.listdir(TSCdir)

        for fname in have:
            if not pattern.match(fname):
                continue

            objectName = pattern.match(fname).group(1)
            # parser = yacc.yacc(debug=0)
            buf = ''
            print("#", "-" * 30, fname)
            fh = open(os.path.join(TSCdir, fname), "r")
            fw = open(os.path.join(currentDir, "%s.cmd" % objectName), "w")
            for cline in fh:
                buf = buf + cline
            buf = buf + '\n'
            l2 = parser.mk_paramObj(fname, buf)
            print(l2)
            v = ParameterHandler(l2)

            listOfSets = []
            listOfParamNames = []
            for aKey in l2:
                listOfParamNames.append(aKey)
                listOfSets.append(l2[aKey].getAllParamValueList())

            combinationList = combination(listOfSets)

            for aList in combinationList:
                parameterMap = {}
                for i in range(len(listOfParamNames)):
                    parameterMap[listOfParamNames[i]] = aList[i]
                try:
                    parameterMap = v.populate(parameterMap, {}, {}, {}, {}, {})
                    v.validate(parameterMap)
                    printList = 'EXEC TSC %s' % objectName
                    for i in list(parameterMap.keys()):
                        printList = printList + (" %s=%s " %
                                                 (i, parameterMap[i]))
                    fw.write(printList + "\n")
                except (ParameterValidationException,
                        InconsistentParameterDefinitionException) as e:
                    pass
            fw.close()