Пример #1
0
    def kh_dbLoadRecords(self, arg0, tokens, ref):
        local_macros = macros.Macros(**self.env.db)
        full_line = reconstruct_line(tokens).strip()
        tokenLog = TokenLog()
        tokenLog.tokenList = tokens
        tokenLog.token_pointer = 1
        args = parse_bracketed_macro_definitions(tokenLog)
        nargs = len(args)
        if nargs not in (1, 2, 3,):
            msg = str(ref) + full_line
            raise UnhandledTokenPattern, msg
        utils.logMessage(arg0 + full_line, utils.LOGGING_DETAIL__NOISY)

        dbFileName = local_macros.replace(utils.strip_quotes(args[0]))

        if nargs in (2, 3,):    # accumulate additional macro definitions
            local_macros = self.parse_macro_args(args[1], ref, tokens, local_macros)

        if nargs in (3,):
            path = args[2]
            # msg = str(ref) + full_line
            if self.symbols.exists(path):   # substitute from symbol table
                path = self.symbols.get(path).value
            if os.path.exists(path):
                dbFileName = os.path.join(path, dbFileName)

        try:
            obj = database.Database(self, dbFileName, ref, **local_macros.db)
            self.database_list.append(obj)
            self.kh_shell_command(arg0, tokens, ref)
        except text_file.FileNotFound, _exc:
            msg = 'Could not find database file: ' + dbFileName
            utils.detailedExceptionLog(msg)
            return
Пример #2
0
    def _parse_record(self, tokenLog):
        tok = tokenLog.nextActionable()
        ref = self._make_ref(tok)
        rtype, rname = tokenLog.tokens_to_list()
        # just parsing, no need for macros now
        record_object = record.Record(self, rtype, rname, ref)
        self.record_list.append(record_object)

        tok = tokenLog.nextActionable()
        if token_key(tok) == 'OP {':
            tok = tokenLog.nextActionable()
            # get record's field definitions
            while token_key(tok) != 'OP }':
                ref = self._make_ref(tok, tok['tokStr'])
                tk = token_key(tok)
                if tk == 'NAME field':
                    tok = tokenLog.nextActionable()
                    ref = self._make_ref(tok)
                    field, value = parse_bracketed_macro_definitions(tokenLog)
                    record_object.addFieldPattern(field, value.strip('"'), self, ref)
                    #tok = tokenLog.previous()   # backup before advancing below
                elif tk == 'NAME alias':
                    self._parse_alias(tokenLog, record_object, ref)
                elif tk == 'NAME info':
                    self._parse_info(tokenLog, record_object, ref)
                else:
                    tok = tokenLog.getCurrentToken()
                    msg = str(ref)
                    msg += ' unexpected content: |%s|' % str(tok['tokStr'])
                    msg += ' in file: ' + str(ref)
                    raise RuntimeError(msg)
                tok = tokenLog.nextActionable()
Пример #3
0
 def _parse_globals_statement(self, tokenLog):
     '''
     support the *globals* statement in a template file
     
     This statement was new starting with EPICS base 3.15
     
     example::
     
         global { P=12ida1:,SCANREC=12ida1:scan1 }
     
     '''
     ref = self._make_ref(tokenLog.getCurrentToken(), 'global macros')
     # TODO: How to remember where the globals were defined?
     tok = tokenLog.nextActionable()
     if token_key(tok) == 'OP {':
         kv = parse_bracketed_macro_definitions(tokenLog)
         ref = self._make_ref(tok, kv)
         # TODO: Do something with ref
         self.macros.setMany(**kv)
     else:
         msg = '(%s,%d,%d) ' % (self.filename, tok['start'][0], tok['start'][1])
         msg += 'missing "{" in globals statement'
         raise DatabaseTemplateException(msg)