Example #1
0
 def __init__(self, logging):
     self.logger = newLogger("Core Messages")
     self._lock = loggingMutex("messages", logging=logging)
     self._db, plugin_type = get_db_connection(self.logger)
     
     if self._db is None:
         self._length = 0
         self._latest = None
         return
     
     if plugin_type != "SQLite Connection":
         self.logger.warning("Your standard connection is not of type SQLite." + \
             "Loading messages from another type is experimental.")
     
     if not self._db.existsTable("CORE_MESSAGE_VERSION"):
         self._db.execute("CREATE TABLE CORE_MESSAGE_VERSION(VERSION INTEGER)")
         self._db.execute("INSERT INTO CORE_MESSAGE_VERSION(VERSION) VALUES(?)", self._DB_VERSION_CURRENT)
                     
     if not self._db.existsTable("CORE_MESSAGES"):
         self._db.execute("CREATE TABLE CORE_MESSAGES(SENDER TEXT, TIME REAL, MESSAGE TEXT)")
         self._db.execute("CREATE INDEX CORE_MESSAGE_TIME_INDEX on CORE_MESSAGES(TIME ASC)")
         self._length = 0
         self._latest = None
         self.importOld(get_settings().get_legacy_messages_file())
     else:
         self._latest = self._getLatest()
         self._length = self._getNumMessages()    
Example #2
0
 def connect_to_db(self, changedDBConn=None):
     """
     connects to a database or changes the database connection type.
     """
     with self._specialized_db_connect_lock:
         if self._specialized_db_conn and changedDBConn and changedDBConn == self.options["db_connection"]:
             return
         if changedDBConn is None:
             changedDBConn = self.options[u"db_connection"]
         dbPlugin, plugin_type = get_db_connection(self.logger, changedDBConn)
         
         if dbPlugin == None:
             self.logger.warning("Plugin %s: DB  connection %s not available: Maybe DB Connections are not active yet?", type(self), self.options["db_connection"])
             return False
         
         if plugin_type in self._supported_dbms:
             self._specialized_db_conn = self._supported_dbms[plugin_type](dbPlugin, self.logger)
         elif "default" in self._supported_dbms:
             self._specialized_db_conn = self._supported_dbms["default"](dbPlugin, self.logger)
         else:
             self.logger.error("DB Conn of type %s is not supported by this plugin", plugin_type)
             self._specialized_db_conn = None
             return False
             
         self.logger.debug("Plugin %s uses DB Connection of type %s ", type(self), plugin_type)
                     
         return True
Example #3
0
    def sendSqlClicked(self, sql_stat):
        from PyQt4.QtGui import QMessageBox
        from lunchinator.table_models import TableModelBase
        
        self.specialized_db_conn().insert_command(sql_stat)
        
        if None==self.db_connection:        
            self.db_connection, _ = get_db_connection(self.logger, self.options["query_db_connection"])
                    
        try:
            header, res = self.db_connection.queryWithHeader(sql_stat)
        except Exception as e:
            QMessageBox.warning(self.resultTable,"Error in SQL statement",str(e))
#             self.logger.warning("SQL error:")
            return False
        
        columns = []
        for h in header:
            columns.append((h,self.empty))
        mod = TableModelBase(None, columns, self.logger)
        self.times_called = 0
        for i,r in enumerate(res):
            mod.appendContentRow(i, r)
            if i>1000:
                break
        self.resultTable.setModel(mod)
        for c in xrange(mod.columnCount()):
            self.resultTable.getTable().resizeColumnToContents(c)
        return True
Example #4
0
 def create_widget(self, parent):
     from stat_visualize.diagram import statTimelineTab, statSwarmTab
     from PyQt4.QtGui import QTabWidget,QLabel
     from PyQt4.QtCore import Qt
     
     connPlugin, plugin_type = get_db_connection(self.logger, self.options["db_connection"])
     
     w = QTabWidget(parent)
     w.addTab(statTimelineTab(parent, connPlugin, self.logger), "Timeline")
     w.addTab(statSwarmTab(parent, connPlugin, self.logger), "Swarm")
     return w
Example #5
0
 def do_SQL(self, cmd):
     if None==self.db_connection:
         self.db_connection, _ = get_db_connection(self.logger, self.options["query_db_connection"])
     try:
         header, res = self.db_connection.queryWithHeader(cmd)
         self.appendOutput(*header)
         self.appendSeparator()
         for r in res:
             self.appendOutput(*r)
         self.flushOutput()
     except Exception as e:
         print "Error in SQL statement",str(e)
 def __init__(self, delegate, logger):
     self._delegate = delegate
     self.logger = logger
     self._db, plugin_type = get_db_connection(self.logger)
     
     if self._db == None:
         self.logger.error("Unable to get database connection.")
         return
     
     if plugin_type != "SQLite Connection":
         self.logger.warning("Your standard connection is not of type SQLite. " + \
             "Using Remote Pictures with another type is experimental.")
     
     self._checkDBVersion()
Example #7
0
 def __init__(self):
     self.logger = newLogger("Peer Names")
     self._db, plugin_type = get_db_connection(self.logger)
     self._peerNameCache = {} # peer ID -> (peer name, custom name)
     
     if self._db is None:
         return
     
     if plugin_type != "SQLite Connection":
         self.logger.warning("Your standard connection is not of type SQLite." + \
             "Loading peer names from another type is experimental.")
     
     if not self._db.existsTable("CORE_PEER_NAME_VERSION"):
         self._db.execute("CREATE TABLE CORE_PEER_NAME_VERSION(VERSION INTEGER)")
         self._db.execute("INSERT INTO CORE_PEER_NAME_VERSION(VERSION) VALUES(?)", self._DB_VERSION_CURRENT)
                     
     if not self._db.existsTable("CORE_PEER_NAMES"):
         self._db.execute("CREATE TABLE CORE_PEER_NAMES(PEER_ID TEXT PRIMARY KEY NOT NULL, PEER_NAME TEXT NOT NULL, CUSTOM_NAME TEXT)")
         if self._db.existsTable("CORE_MESSAGE_PEER_NAMES"):
             # copy from message peer names
             self._db.execute("INSERT INTO CORE_PEER_NAMES SELECT PEER_ID, PEER_NAME, NULL FROM CORE_MESSAGE_PEER_NAMES")
             self._db.execute("DROP TABLE CORE_MESSAGE_PEER_NAMES")
 def __init__(self, logger):
     self.logger = logger
     self._db, plugin_type = get_db_connection(self.logger)
     
     if self._db == None:
         self.logger.error("Unable to get database connection.")
         return
     
     if plugin_type != "SQLite Connection":
         self.logger.warning("Your standard connection is not of type SQLite. " + \
             "Using Private Messages with another type is experimental.")
     
     if not self._db.existsTable("PRIVATE_MESSAGES_VERSION"):
         self._db.execute("CREATE TABLE PRIVATE_MESSAGES_VERSION(VERSION INTEGER)")
         self._db.execute("INSERT INTO PRIVATE_MESSAGES_VERSION(VERSION) VALUES(?)", self._DB_VERSION_CURRENT)
     
     if not self._db.existsTable("PRIVATE_MESSAGES"):
         self._db.execute(self._MESSAGES_TABLE_STATEMENT)
         self._db.execute("CREATE INDEX PRIVATE_MESSAGE_TIME_INDEX on PRIVATE_MESSAGES(TIME)")
         self._db.execute("CREATE INDEX PRIVATE_MESSAGE_PARTNER_INDEX on PRIVATE_MESSAGES(PARTNER)")
         
     self._checkDBVersion()