Example #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
Example #2
0
 def parse(self):
     '''interpret records for PV declarations'''
     tokenLog = TokenLog()
     tokenLog.processFile(self.filename_expanded)
     tok = tokenLog.nextActionable()
     actions = {
                #'NAME alias': self._parse_alias,
                #'NAME info': self._parse_info,
                'NAME grecord': self._parse_record,
                'NAME record': self._parse_record,
                }
     while tok is not None:
         tk = token_key(tok)
         if tk in actions:
             actions[tk](tokenLog)
         tok = tokenLog.nextActionable()
Example #3
0
 def parse(self):
     '''
     interpret the template file for database declarations
     
     The Python tokenizer makes simple work of parsing database files.
     The TokenLog class interprets the contents according to a few simple terms
     such as NAME, OP, COMMENT, NEWLINE.
     '''
     tokenLog = TokenLog()
     tokenLog.processFile(self.filename_expanded)
     tok = tokenLog.nextActionable()
     actions = {
                'NAME file': self._parse_file_statement,
                'NAME global': self._parse_globals_statement,
                }
     while tok is not None:
         tk = token_key(tok)
         if tk in actions:
             actions[tk](tokenLog)
         tok = tokenLog.nextActionable()
Example #4
0
 def parse(self):
     '''analyze this command file'''
     tokenLog = TokenLog()
     tokenLog.processFile(self.filename_absolute)
     lines = tokenLog.lineAnalysis()
     del lines['numbers']
     for _lineNumber, line in sorted(lines.items()):
         isNamePattern = line['pattern'].startswith( 'NAME' )
         tk = token_key(line['tokens'][0])
         if isNamePattern or tk == 'OP <':
             arg0 = line['tokens'][0]['tokStr']
             ref = self._make_ref(line['tokens'][0], arg0)
             if line['tokens'][1]['tokStr'] == '=':
                 # this is a symbol assignment
                 handler = self.kh_symbol
                 handler(arg0, line['tokens'], ref)
             elif arg0 in self.knownHandlers:
                 # command arg0 has a known handler, call it
                 handler = self.knownHandlers[arg0]
                 handler(arg0, line['tokens'], ref)
             else:
                 self.kh_shell_command(arg0, line['tokens'], ref)