def html(env): option_elems = '' for mike in avail_mikes(): option_elems += '<option value="%s">%s</option>' % (mike, mike) html = bytes(HTML_TEMPLATE % option_elems, encoding='utf-8') header = [('Content-Type', 'text/html'), ('Content-Lentgh', str(len(html)))] return header, html
def record(self, eventid, duration): storage = os.path.join(self.datadir, eventid) if os.path.exists(storage): shutil.rmtree(storage) os.makedirs(storage) self.storage = storage mike_threads = [] devices = self.setting['devices'] if self.setting.get('devices') else avail_mikes() for dev in devices: th = Thread(target=self.rec_sound, args=(duration, dev)) th.start() mike_threads.append(th) for th in mike_threads: th.join()
def available(env): available_features = [] if avail_cameras(): available_features.append(('camera', ALL_FEATURES['camera'])) if avail_mikes(): available_features.append(('mike', ALL_FEATURES['mike'])) try: import RPi.GPIO available_features.append(('gpio', ALL_FEATURES['gpio'])) except: pass available_features.append(('gcm', ALL_FEATURES['gcm'])) res = bytes(dumps(available_features), 'utf-8') header = [('Content-Type', 'application/json'), ('Content-Length', str(len(res)))] return header, res
def devicelist(env): devices = json.dumps(avail_mikes()) content = bytes(devices, 'utf-8') header = [('Content-Type', 'application/json'), ('Content-Lentgh', str(len(content)))] return header, content