コード例 #1
0
    def open_existing(self, file_name):
        """Open an existing `.a2ldb` database.

        Parameters
        ----------
        file_name: str
            Name of your database file, resulting from :meth:`import_a2l`.
            Extension `.a2ldb` not needed.

        Returns
        -------
        SQLAlchemy session object.

        Raises
        ------
        OSError
            If database already exists.
        """
        self.in_memory = False
        self._set_path_components(file_name)
        if not path.exists(self._dbfn):
            raise OSError("file '{}' does not exists.".format(self._dbfn))
        else:
            self.db = model.A2LDatabase(self._dbfn)
            self.session = self.db.session
            res = self.session.query(model.MetaData).first()
            if res:
                return self.session
            else:
                raise InvalidA2LDatabase(
                    "Database seems to be corrupted. No meta-data found.")
コード例 #2
0
ファイル: parserlib.py プロジェクト: anekename/pyA2L
 def parse(self, input, trace=False):
     if self.useDatabase:
         self.db = model.A2LDatabase(self.fnbase, debug=self.debug)
     lexer = self.lexerClass(input)
     lexer.removeErrorListeners()
     lexer.addErrorListener(MyErrorListener())
     tokenStream = antlr4.CommonTokenStream(lexer)
     #        tokenStream = BufferedTokenStream(lexer)
     parser = self.parserClass(tokenStream)
     parser.setTrace(trace)
     parser.removeErrorListeners()
     parser.addErrorListener(MyErrorListener())
     meth = getattr(parser, self.startSymbol)
     self._syntaxErrors = parser._syntaxErrors
     tree = meth()
     if self.listener:
         if self.useDatabase:
             self.listener.db = self.db
         listener = self.listener()
         walker = antlr4.ParseTreeWalker()
         result = walker.walk(listener, tree)
     if self.useDatabase:
         self.db.session.commit()
         return self.db
     else:
         return listener
コード例 #3
0
 def open_existing(self, file_name):
     """
     """
     self._set_path_components(file_name)
     if not path.exists(self._dbfn):
         return None
     else:
         self.db = model.A2LDatabase(self._dbfn)
         self.session = self.db.session
         res = self.session.query(model.MetaData).first()
         if res:
             return self.session
         else:
             return None