Ejemplo n.º 1
0
    def __init__(self):

        db_path = os.path.join(get_data_path(), 'faces_detect.sqlite')

        # Introduce a bug on purpose in newer version, removing the database content

        # On older ubuntu core version, SNAP_VERSION is the sideloaded one, so we don't rely on that for now
        #if os.getenv("SNAP_VERSION", "0.1") != "0.1":
        #    num_faces = -10
        file_path = os.path.join(os.getenv("SNAP_APP_PATH"), "meta",
                                 "package.yaml")
        with suppress(OSError):
            with open(file_path, 'rt') as f:
                if yaml.load(f.read())["version"] != 0.1:
                    os.remove(db_path)

        self._conn = sqlite3.connect(db_path)
        c = self._conn.cursor()
        with suppress(sqlite3.OperationalError):
            c.execute(
                "CREATE TABLE FacesDetect(Timestamp DATETIME, Number INTEGER);"
            )
            self._conn.commit()
        c.execute("SELECT * FROM FacesDetect ORDER BY Timestamp")
        self.face_detect_data = c.fetchall()
        logger.debug("Found {}".format(self.face_detect_data))
        WebClientsCommands.sendFacesDetectAll(self.face_detect_data)
Ejemplo n.º 2
0
    def __init__(self):

        db_path = os.path.join(get_data_path(), 'faces_detect.sqlite')

        # Introduce a bug on purpose in newer version, removing the database content

        # On older ubuntu core version, SNAP_VERSION is the sideloaded one, so we don't rely on that for now
        #if os.getenv("SNAP_VERSION", "0.1") != "0.1":
        #    num_faces = -10
        file_path = os.path.join(os.getenv("SNAP"), "meta", "snap.yaml")
        with suppress(OSError):
            with open(file_path, 'rt') as f:
                if yaml.load(f.read())["version"] != 0.1:
                    os.remove(db_path)

        self._conn = sqlite3.connect(db_path)
        c = self._conn.cursor()
        with suppress(sqlite3.OperationalError):
            c.execute("CREATE TABLE FacesDetect(Timestamp DATETIME, Number INTEGER);")
            self._conn.commit()
        c.execute("SELECT * FROM FacesDetect ORDER BY Timestamp")
        self.face_detect_data = c.fetchall()
        logger.debug("Found {}".format(self.face_detect_data))
        WebClientsCommands.sendFacesDetectAll(self.face_detect_data)