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)
def translate_path(self, path): """Translate a /-separated PATH to the local filename syntax. Stolen from SimpleHTTPSRequestHandler with a different base path Components that mean special things to the local file system (e.g. drive or directory names) are ignored. (XXX They should probably be diagnosed.) """ # abandon query parameters path = path.split('?', 1)[0] path = path.split('#', 1)[0] # Don't forget explicit trailing slash when normalizing. Issue17324 trailing_slash = path.rstrip().endswith('/') path = posixpath.normpath(urllib.unquote(path)) words = path.split('/') words = filter(None, words) if path.startswith('/dynamics'): path = os.path.join(get_data_path()) words = words[1:] else: path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'www') for word in words: drive, word = os.path.splitdrive(word) head, word = os.path.split(word) if word in (os.curdir, os.pardir): continue path = os.path.join(path, word) if trailing_slash: path += '/' return path
def __init__(self, without_sphero=False): self.sphero_file_path = os.path.join(get_data_path(), "sphero.hw") if not without_sphero: logger.debug("Connecting to sphero") try: self.sphero_list = yaml.load(open(self.sphero_file_path).read()) except IOError: logger.error("Couldn't connect to sphero: {} doesn't exist".format(self.sphero_file_path)) sys.exit(1) sphero_addr = None for sphero_name in self.sphero_list: with suppress(KeyError): if self.sphero_list[sphero_name]["active"]: self.sphero_name = sphero_name sphero_addr = self.sphero_list[sphero_name]["address"] try: self.sphero = kulka.Kulka(sphero_addr) except IOError: logger.error("Couldn't connect to sphero: {} address isn't paired".format(sphero_addr)) sys.exit(1) logger.debug("Connected to sphero") self.sphero.set_inactivity_timeout(3600) self.reset_default_color() else: logger.info("Using a false sphero") self.sphero_name = "fake" self.sphero_list = {self.sphero_name: {}} self.sphero = Mock() self._current_room = Home().start_room self.last_move = time() self.in_calibration = False
def __init__(self): """Create this Speech recognition object""" self._source_id = None self._enabled = False self.speech_recognition_file_path = os.path.join( get_data_path(), "speech.recognition") GLib.timeout_add_seconds(0.1, self.check_speech_recognition)
def __init__(self): """Build the house room is a map indexed by name to the room objects composing the house start_room is where sphero is at startup""" self.rooms = {} self.start_room = None self.facedetectdest_room = None logger.debug("Build home map") with open(os.path.join(get_data_path(), "home.map"), 'r') as f: home_map = yaml.load(f) self._populate_room_basic_infos(home_map) self._build_direct_paths() self._build_other_paths() self._simplify_all_room_paths() for room in self.rooms: logger.debug("======== {} ========".format(room)) logger.debug(self.rooms[room].paths)
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)
def __init__(self, without_sphero=False): self.sphero_file_path = os.path.join(get_data_path(), "sphero.hw") if not without_sphero: logger.debug("Connecting to sphero") try: self.sphero_list = yaml.load( open(self.sphero_file_path).read()) except IOError: logger.error( "Couldn't connect to sphero: {} doesn't exist".format( self.sphero_file_path)) sys.exit(1) sphero_addr = None for sphero_name in self.sphero_list: with suppress(KeyError): if self.sphero_list[sphero_name]["active"]: self.sphero_name = sphero_name sphero_addr = self.sphero_list[sphero_name]["address"] try: self.sphero = kulka.Kulka(sphero_addr) except IOError: logger.error( "Couldn't connect to sphero: {} address isn't paired". format(sphero_addr)) sys.exit(1) logger.debug("Connected to sphero") self.sphero.set_inactivity_timeout(3600) self.reset_default_color() else: logger.info("Using a false sphero") self.sphero_name = "fake" self.sphero_list = {self.sphero_name: {}} self.sphero = Mock() self._current_room = Home().start_room self.last_move = time() self.in_calibration = False
def __init__(self): """Create this Speech recognition object""" self._source_id = None self._enabled = False self.speech_recognition_file_path = os.path.join(get_data_path(), "speech.recognition") GLib.timeout_add_seconds(0.1, self.check_speech_recognition)
# # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import os import yaml import logging logger = logging.getLogger(__name__) from tools import get_data_path, suppress logger.debug("Opening settings file") settings = {} with suppress(IOError): with open(os.path.join(get_data_path(), "settings"), 'r') as f: settings = yaml.load(f)["facedetection"] WEBSERVER_PORT = int(settings.get("webserver-port", 8042)) SOCKET_PORT = WEBSERVER_PORT + 1 TIME_BETWEEN_SHOTS = int(settings.get("interval-shots", 10)) LAST_SCREENSHOT = "last_screen.png"
def __init__(self): """Save last screenshot at """ self.screenshot_path = os.path.join(get_data_path(), LAST_SCREENSHOT)
# This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import os import yaml import logging logger = logging.getLogger(__name__) from tools import get_data_path, suppress logger.debug("Opening settings file") settings = {} with suppress(IOError): with open(os.path.join(get_data_path(), "settings"), 'r') as f: settings = yaml.load(f)["facedetection"] WEBSERVER_PORT = int(settings.get("webserver-port", 8042)) SOCKET_PORT = WEBSERVER_PORT + 1 TIME_BETWEEN_SHOTS = int(settings.get("interval-shots", 10)) LAST_SCREENSHOT = "last_screen.png" LAST_FACES = "last_faces.png"