def __init__(self): self.dbLock = False conf = config.getSub("storage") self.capacity = conf.get("capacity", cast = config.positiveInt, default = 2048) self.vacPercent = conf.get("vacuum_percent", cast = config.positivePercent, default = 20.0) / 100 self.timeout = conf.get("timeout", cast = config.positiveFloat, default = 10.0) try: conn = sqlite3.connect(self.dbFile()) with conn: conn.execute("CREATE TABLE IF NOT EXISTS packets (timestamp INT8, data BLOB)") self.vaccum() except Exception: log.critical("Failed to initialize database", exc_info = 1) sys.exit(1) self.connections = {} self.connectionId = genConnId() log.info("Database initialized")
import threading, logging import bt_pb2 from config import genConnId log = logging.getLogger("btserver") connections = {} connectionId = genConnId() def getConnections(): return connections.values() class InvalidRequest(Exception): pass class InternalError(Exception): pass class Connection(threading.Thread): def __init__(self, sock, btserver): threading.Thread.__init__(self) self.connId = connectionId.next() connections[self.connId] = self self.sock = sock self.storage = btserver.storage self.delSent = btserver.delSent self.batch = btserver.batch self.running = True