def app(): with rw_fs.Storage(restart_player=False): hardware.platfrom.fix_file_permissions(config.Config().storage_path()) xmain.start() wallpaper.Wallpaper().load() if config.Config().enable_clockd(): threads.run_in_thread(clockd.Clockd().run) # threads.run_in_thread(networkd.Networkd().run) # threads.run_in_thread(hdmihotplug.HdmiHotplug(onchange_callback=resolution_changed).run) player = playercontroller.PlayerController() player.start_playlist() proto = protocoldispatcher.ProtocolDispatcher() threads.run_in_thread(webui.start, ['0.0.0.0', 8080]) while True: track = player.current_track_name() pos = player.current_track_posiotion() proto.send('now_playing', track=track, percent_position=pos) watchdog.Watchdog().feed() time.sleep(20)
def _save_playlist_file(self): playlst = self._data.get('playlist') if playlst is None: # old server without 'playlist' key return localpath = self._playlist_file_path() jsondata = json.dumps(playlst) with rw_fs.Storage(): with open(localpath, 'w') as f: f.write(jsondata)
def _run_sync(self, *args): try: log.info('running message queue sync') with rw_fs.Storage(restart_player=False): self._queue.sync() except: log.exception('error running message queue sync') finally: with self._wait_condition: self._wait_condition.notify_all()
def _download(self, url, localpath, seq): try: log.info('starting software update download from %s to %s', url, localpath) with rw_fs.Storage(): if os.path.isfile(localpath): os.remove(localpath) httpclient.download_file(url, localpath) self_update.SelfUpdate().downloaded(localpath, seq) except: log.exception('error downloading software update')
def run(self): try: with rw_fs.Storage(): self._run() log.info(self._success_message) self._onfinish(True, self._sequence, self._success_message) except WorkerTerminated: log.warn('terminated') except: log.error("{msg}\n{ex}".format(msg=self._error_message, ex=traceback.format_exc())) self._onfinish(False, self._sequence, self._error_message)
def start_playlist(self): mediafiles_fullpath = files.mediafiles_path() if not os.path.exists(mediafiles_fullpath): with rw_fs.Storage(restart_player=False): files.mkdir(mediafiles_fullpath) playlist_fullpath = loader.Loader().filepath() if not os.path.exists(playlist_fullpath): log.error("playlist file '{f}' does not exists".format( f=playlist_fullpath)) return protocoldispatcher.ProtocolDispatcher().send( 'playlist_begin', files=loader.Loader(playlist_fullpath).list_all_files()) self._scheduler.set_playlist(playlist.Playlist())
def remove(self): if os.path.exists(self._path): with rw_fs.Storage(): os.remove(self._path)
def write(self, data): with rw_fs.Storage(): with open(self._path, 'w') as f: f.write(data)
def _remove_file(self, file): with rw_fs.Storage(): try: os.remove(file) except FileNotFoundError: pass
def _download_file(self, url, localpath): with rw_fs.Storage(): if os.path.isfile(localpath): os.remove(localpath) httpclient.download_file(files.full_url_by_relative(url), localpath)
def _arvive(self, directory): with rw_fs.Storage(): dst = self._generate_destination_filepath() + '.tar.gz' with tarfile.open(dst, mode='w:gz') as archive: archive.add(directory) return dst