def run(self): url = 'http://%s:5000/' % self.host print 'Welcome to ScreenBloom!' print 'Server running at: %s' % url if not self.stoprequest.isSet(): # Check For DLL error if not utility.dll_check(): url += 'dll-error' # Check if config file has been created yet elif os.path.isfile(utility.get_config_path()): print 'Config already exists' config = ConfigParser.RawConfigParser() config.read(utility.get_config_path()) utility.write_config('App State', 'running', '0') # Wait for 200 status code from server then load up interface while not utility.check_server(self.host): sleep(0.2) sb_controller.start() else: # Config file doesn't exist, open New User interface print 'Config does not exist yet!' url += 'new-user' webbrowser.open(url)
def start_server(self): try: http_server = HTTPServer(WSGIContainer(self.app)) http_server.listen(self.port) sleep(1) if not self.needs_update and not self.error and not self.new_user: # Autostart check if not self.args.silent: webbrowser.open(self.url) else: config = utility.get_config_dict() auto_start = config['autostart'] if auto_start: sb_controller.start() # New User / Error / Needs Update - skip autostart else: webbrowser.open(self.url) IOLoop.instance().start() # Handle port collision except socket.error: self.port += 1 self.start_server()
def restart_check(): global t try: if t.isAlive(): t.join() sb_controller.start() else: sb_controller.re_initialize() except NameError: sb_controller.re_initialize()
def restart_check(): global t try: if t.isAlive(): print '\nRestarting thread...' t.join() sb_controller.start() else: sb_controller.re_initialize() except NameError: # print '\nThread does not exist yet' sb_controller.re_initialize()
def start_screenbloom(): config = utility.get_config_dict() state = config['app_state'] sb_controller.get_screen_object().bulb_state = 'on' hue_interface.lights_on_off('On') if state: message = 'ScreenBloom already running' else: sb_controller.re_initialize() sb_controller.start() message = 'ScreenBloom Started!' data = {'message': message} return data
def start_screenbloom(): config = utility.get_config_dict() state = config['color_mode_enabled'] sb_controller.get_screen_object().bulb_state = 'on' hue_interface.lights_on_off('On') if state: message = 'ScreenBloom already running' else: utility.write_config('Configuration', 'color_mode_enabled', True) sb_controller.re_initialize() sb_controller.start() message = 'Color Mode Started!' data = {'message': message} return data
def start_screenbloom(): config = utility.get_config_dict() state = config['app_state'] sb_controller.get_screen_object().bulb_state = 'on' hue_interface.lights_on_off('On') if state: message = 'ScreenBloom already running' else: sb_controller.re_initialize() sb_controller.start() message = 'ScreenBloom Started!' data = { 'message': message } return data
def start_server(app, startup_thread): try: http_server = HTTPServer(WSGIContainer(app)) http_server.listen(startup_thread.port) if not startup_thread.args.silent: startup_thread.start() else: config = utility.get_config_dict() auto_start = config['autostart'] sb_controller.start() if auto_start: view_logic.start_screenbloom() IOLoop.instance().start() # Handle port collision except socket.error: startup_thread.port += 1 start_server(app, startup_thread)
def register_logic(ip, host): if not ip: print 'Hue IP not entered manually' # Attempting to grab IP from Philips uPNP app try: print 'Attempting to grab bridge IP...' requests.packages.urllib3.disable_warnings() url = 'https://www.meethue.com/api/nupnp' r = requests.get(url, verify=False).json() ip = str(r[0]['internalipaddress']) print 'Success! Hue IP: %s' % ip except Exception as e: utility.write_traceback() error_type = 'manual' error_description = 'Error grabbing Hue IP, redirecting to manual entry...' data = { 'success': False, 'error_type': error_type, 'error_description': error_description, 'host': host } return data try: print 'Attempting to register app with Hue bridge...' # Send post request to Hue bridge to register new username, return response as JSON result = register_device(ip) temp_result = result[0] result_type = '' for k, v in temp_result.items(): result_type = str(k) if result_type == 'error': error_type = result[0]['error']['type'] error_description = result[0]['error']['description'] data = { 'success': False, 'error_type': str(error_type), 'error_description': str(error_description) } return data else: print 'Success! Creating config file...' username = temp_result[result_type]['username'] create_config(ip, username) sb_controller.start() data = { 'success': True, 'message': 'Success!' } return data except requests.exceptions.ConnectionError: data = { 'success': False, 'error_type': 'Invalid URL', 'error_description': 'Something went wrong with the connection, please try again...' } return data except IOError: data = { 'success': False, 'error_type': 'permission', 'error_description': 'Permission denied, administrator rights needed..' } return data