def destroy(self, widget): postoffice.disconnect(['request-album-cover', 'request-images'], self) settings.save() from player import the_player if the_player: the_player.stop() gtk.main_quit()
def settings_repo_add(): repo = flask.request.form['repo'] if repo: settings.add_repo(repo) settings.save() return "Yes" return "No", 500
def settings_page(): context = {'flash': None} if request.method == "POST": for field, default in CONFIGURABLE_SETTINGS.items(): value = request.POST.get(field, default) if isinstance(default, bool): value = value == 'on' settings[field] = value try: settings.save() sh.sudo('systemctl', 'kill', '--signal=SIGUSR2', 'screenly-viewer.service') context['flash'] = { 'class': "success", 'message': "Settings were successfully saved." } except IOError as e: context['flash'] = {'class': "error", 'message': e} except sh.ErrorReturnCode_1 as e: context['flash'] = {'class': "error", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] return template('settings', **context)
def settings_page(): context = {'flash': None} if request.method == "POST": for field, default in CONFIGURABLE_SETTINGS.items(): value = request.form.get(field, default) if isinstance(default, bool): value = value == 'on' settings[field] = value try: settings.save() system('pkill -SIGHUP -f viewer.py') context['flash'] = { 'class': "success", 'message': "Settings were successfully saved." } except IOError as e: context['flash'] = {'class': "error", 'message': e} except OSError as e: context['flash'] = {'class': "error", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] return template('settings.html', **context)
def add_to_playlist(wnd, track): if not track: _show_banner(wnd, "Nothing to add") return dialog = ListDialog('Add to playlist', wnd) for name,_ in settings.playlists.iteritems(): dialog.listbox.append(name) dialog.listbox.append("New...") try: dialog.show_all() if dialog.run() == gtk.RESPONSE_OK: selected_playlist = dialog.selected if selected_playlist == "New...": dialog.hide() selected_playlist = create_new_playlist(wnd) if track and selected_playlist: if isinstance(track, (list, tuple)): for t in track: settings.add_to_playlist(selected_playlist, {'id':t.ID, 'data':t.get_data()}) else: settings.add_to_playlist(selected_playlist, {'id':track.ID, 'data':track.get_data()}) settings.save() _show_banner(wnd, "Added to playlist '%s'" % (selected_playlist)) finally: dialog.destroy()
def on_delete_pl(self, btn): note = hildon.hildon_note_new_confirmation(self, "Do you want to delete '%s' ?" % (self.playlist_name)) response = note.run() note.destroy() print response if response == gtk.RESPONSE_OK: settings.delete_playlist(self.playlist_name) settings.save() self.destroy()
def set_remote(): host = request.POST.get('host', settings['remote_host']) port = request.POST.get('port', settings['remote_port']) enabled = request.POST.get('enabled', settings['remote_enabled']) print("Master is "+str(host)+":"+str(port)+". Enabled: "+str(enabled)) settings['remote_host']=host settings['remote_port']=port settings['remote_enabled']=enabled settings.save()
def set_remote(): host = request.POST.get('host', settings['remote_host']) port = request.POST.get('port', settings['remote_port']) enabled = request.POST.get('enabled', settings['remote_enabled']) settings['remote_host']=host settings['remote_port']=port if enabled == '1': settings['remote_enabled']=True else: settings['remote_enabled']=False settings.save()
def main(): # Import config to load configurations try: config = settings.load('settings.ini') except FileNotFoundError as file_error: print('Run setup.py first.') raise # Placeholder for new chapters try: new_chapters = get_new_chapters(config['MANGA']['latest'], config['RSS']['url']) except KeyError as key_error: if key_error.args[0] in ('MANGA', 'latest'): new_chapters = get_newest_chapter(config['RSS']['url']) else: raise if new_chapters: try: push = pushbullet.Push(config['PUSHBULLET']['access_token']) push.delete(config['PUSHBULLET']['iden']) except KeyError as key_error: if key_error.args[0] == 'iden': pass elif key_error.args[0] == 'PUSHBULLET': print('Pusbullet section is missing. Run setup.py.') raise elif key_error.args[0] == 'access_token': print('Pushbullet access token is missing. Run setup.py.') raise else: raise config['MANGA']['latest'] = new_chapters[0]['id'] config['MANGA']['title'] = new_chapters[0]['title'] body = [] for index in range(len(new_chapters)): body.append(new_chapters[index - 1]['title'] + '\n') body.sort() body = ''.join(body) data = { 'iden': uuid.uuid4(), 'type': 'note', 'title': 'New chapters to read!', 'body': body } config['PUSHBULLET']['iden'] = push.create(data) settings.save(config, 'settings.ini')
def setUp(self): super(TestUsbAssets, self).setUp() self.mountpoint = '/tmp/USB' self.key_file = '%s/usb_assets_key.yaml' % self.mountpoint self.asset_file = '%s/image.png' % self.mountpoint self.cleanup_folder = '%s/cleanup_folder' % self.mountpoint self.cleanup_asset_file = '%s/image.png' % self.cleanup_folder settings['usb_assets_key'] = generate_perfect_paper_password(20, False) settings.save() key_data = {"screenly": {"key": settings['usb_assets_key']}} with open(self.key_file, 'w') as f: yaml.dump(key_data, f)
def on_exit(self): if self.next_screen is None: # We save the settings before we quit. settings.save() graphics.save() pygame.quit() sys.exit() elif self.next_screen is helpmenu.HelpMenu: # We start the help screen or the about screen and send them a reference to this instance, so they can return to it later. # We also setup the transitions, so when they return they transition in. self.transition.setup_odd_even_transition(self.main_menu, True, True, False, False) self.next_screen(self.window_surface, self.main_clock, self) elif not self.next_screen is None: # Else, we just start the next screen with the default parameters. self.next_screen(self.window_surface, self.main_clock) # Otherwise we simply let this scene end.
def setup(): rss = input('Enter RSS url: ') access_token = input('Enter Pushbullet access token: ') values = { 'RSS': { 'url': rss }, 'PUSHBULLET': { 'access_token': access_token } } config = configparser.ConfigParser() for v in values: config[v] = values[v] settings.save(config, 'settings.ini')
def on_settings(self, button): dialog = gtk.Dialog() dialog.set_title("Settings") dialog.add_button( gtk.STOCK_OK, gtk.RESPONSE_OK ) vbox = dialog.vbox hboxinner = gtk.HBox() hboxinner.pack_start(gtk.Label("Username:"******"jamendo.com username") if settings.user: entry.set_text(settings.user) hboxinner.pack_start(entry, True, True, 0) vbox.pack_start(hboxinner, True, True, 0) dialog.show_all() result = dialog.run() val = entry.get_text() dialog.destroy() if val and result == gtk.RESPONSE_OK: settings.user = val settings.save()
def setup(): longitude = input('Enter longitude: ') latitude = input('Enter latitude: ') access_token = input('Enter Pushbullet access token: ') values = { 'COORDINATES': { 'longitude': longitude, 'latitude': latitude }, 'PUSHBULLET': { 'access_token': access_token } } config = configparser.ConfigParser() for v in values: config[v] = values[v] settings.save(config, 'settings.ini')
def settings_page(): context = {'flash': None} if request.method == "POST": for field, default in DEFAULTS['viewer'].items(): value = request.POST.get(field, default) if isinstance(default, bool): value = value == 'on' settings[field] = value try: settings.save() context['flash'] = {'class': "success", 'message': "Settings were successfully saved."} except IOError as e: context['flash'] = {'class': "error", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] return template('settings', **context)
def settings_page(): context = {"flash": None} if request.method == "POST": for field, default in DEFAULTS["viewer"].items(): value = request.POST.get(field, default) if isinstance(default, bool): value = value == "on" settings[field] = value try: settings.save() context["flash"] = {"class": "success", "message": "Settings were successfully saved."} except IOError as e: context["flash"] = {"class": "error", "message": e} else: settings.load() for field, default in DEFAULTS["viewer"].items(): context[field] = settings[field] return template("settings", **context)
def settings_page(): context = {'flash': None} if request.method == "POST": for field, default in CONFIGURABLE_SETTINGS.items(): value = request.POST.get(field, default) if isinstance(default, bool): value = value == 'on' settings[field] = value try: settings.save() sh.sudo('systemctl', 'kill', '--signal=SIGUSR2', 'screenly-viewer.service') context['flash'] = {'class': "success", 'message': "Settings were successfully saved."} except IOError as e: context['flash'] = {'class': "error", 'message': e} except sh.ErrorReturnCode_1 as e: context['flash'] = {'class': "error", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] return template('settings', **context)
def settings_page(): context = {'flash': None} if request.method == "POST": try: # put some request variables in local variables to make easier to read current_pass = request.form.get('current-password', '') auth_backend = request.form.get('auth_backend', '') if auth_backend != settings['auth_backend'] and settings[ 'auth_backend']: if not current_pass: raise ValueError( "Must supply current password to change authentication method" ) if not settings.auth.check_password(current_pass): raise ValueError("Incorrect current password.") prev_auth_backend = settings['auth_backend'] if not current_pass and prev_auth_backend: current_pass_correct = None else: current_pass_correct = settings.auth_backends[ prev_auth_backend].check_password(current_pass) next_auth_backend = settings.auth_backends[auth_backend] next_auth_backend.update_settings(current_pass_correct) settings['auth_backend'] = auth_backend for field, default in CONFIGURABLE_SETTINGS.items(): value = request.form.get(field, default) if not value and field in [ 'default_duration', 'default_streaming_duration' ]: value = str(0) if isinstance(default, bool): value = value == 'on' settings[field] = value settings.save() publisher = ZmqPublisher.get_instance() publisher.send_to_viewer('reload') context['flash'] = { 'class': "success", 'message': "Settings were successfully saved." } except ValueError as e: context['flash'] = {'class': "danger", 'message': e} except IOError as e: context['flash'] = {'class': "danger", 'message': e} except OSError as e: context['flash'] = {'class': "danger", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] auth_backends = [] for backend in settings.auth_backends_list: if backend.template: html, ctx = backend.template context.update(ctx) else: html = None auth_backends.append({ 'name': backend.name, 'text': backend.display_name, 'template': html, 'selected': 'selected' if settings['auth_backend'] == backend.name else '' }) context.update({ 'user': settings['user'], 'need_current_password': bool(settings['auth_backend']), 'is_balena': is_balena_app(), 'auth_backend': settings['auth_backend'], 'auth_backends': auth_backends }) return template('settings.html', **context)
def settings_page(): context = {'flash': None} if request.method == "POST": try: # put some request variables in local variables to make easier to read current_pass = request.form.get('curpassword', '') new_pass = request.form.get('password', '') new_pass2 = request.form.get('password2', '') current_pass = '' if current_pass == '' else hashlib.sha256(current_pass).hexdigest() new_pass = '' if new_pass == '' else hashlib.sha256(new_pass).hexdigest() new_pass2 = '' if new_pass2 == '' else hashlib.sha256(new_pass2).hexdigest() new_user = request.form.get('user', '') use_auth = request.form.get('use_auth', '') == 'on' # Handle auth components if settings['password'] != '': # if password currently set, if new_user != settings['user']: # trying to change user # should have current password set. Optionally may change password. if current_pass == '': if not use_auth: raise ValueError("Must supply current password to disable authentication") raise ValueError("Must supply current password to change username") if current_pass != settings['password']: raise ValueError("Incorrect current password.") settings['user'] = new_user if new_pass != '' and use_auth: if current_pass == '': raise ValueError("Must supply current password to change password") if current_pass != settings['password']: raise ValueError("Incorrect current password.") if new_pass2 != new_pass: # changing password raise ValueError("New passwords do not match!") settings['password'] = new_pass if new_pass == '' and not use_auth and new_pass2 == '': # trying to disable authentication if current_pass == '': raise ValueError("Must supply current password to disable authentication") settings['password'] = '' else: # no current password if new_user != '': # setting username and password if new_pass != '' and new_pass != new_pass2: raise ValueError("New passwords do not match!") if new_pass == '': raise ValueError("Must provide password") settings['user'] = new_user settings['password'] = new_pass for field, default in CONFIGURABLE_SETTINGS.items(): value = request.form.get(field, default) # skip user and password as they should be handled already. if field == "user" or field == "password": continue if not value and field in ['default_duration', 'default_streaming_duration']: value = str(0) if isinstance(default, bool): value = value == 'on' settings[field] = value settings.save() publisher = ZmqPublisher.get_instance() publisher.send_to_viewer('reload') context['flash'] = {'class': "success", 'message': "Settings were successfully saved."} except ValueError as e: context['flash'] = {'class': "danger", 'message': e} except IOError as e: context['flash'] = {'class': "danger", 'message': e} except OSError as e: context['flash'] = {'class': "danger", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] context['user'] = settings['user'] context['password'] = "******" if settings['password'] != "" else "" context['is_balena_app'] = is_balena_app() if not settings['user'] or not settings['password']: context['use_auth'] = False else: context['use_auth'] = True return template('settings.html', **context)
def settings_handler(self,addr, tags, stuff, source): if stuff[0] == 'save': settings.save() else: settings.set(stuff[0],stuff[1])
def cleanup(self): self.killCurrentTrace() settings.save()
def main(): try: config = settings.load('settings.ini') except FileNotFoundError as file_error: print('Run setup.py first.') raise try: latitude = config['COORDINATES']['latitude'] longitude = config['COORDINATES']['longitude'] except KeyError as key_error: if key_error.args[0] in ('COORDINATES', 'latitude', 'longitude'): print('Run setup.py.') raise category = 'pmp3g' version = 2 url = f"https://opendata-download-metfcst.smhi.se/api/category/{category}/version/{version}/geotype/point/lon/{longitude}/lat/{latitude}/data.json" resp = requests.get(url).json() body = [] # day = weekday_name( datetime.strptime(resp['timeSeries'][1]['validTime'], '%Y-%m-%dT%H:%M:%SZ').weekday()) day = '' for index in range(12): date = resp['timeSeries'][index]['validTime'] parameters = resp['timeSeries'][index]['parameters'] air_temperature = next( (param for param in parameters if param['name'] == 't'), 'No data') wind_speed = next( (param for param in parameters if param['name'] == 'ws'), 'No data') weather = _Weather( next((param for param in parameters if param['name'] == 'Wsymb2'), 'No data')['values'][0]) if air_temperature['unit'] == 'Cel': degree_unit = u'\N{DEGREE SIGN}' else: degree_unit = air_temperature['unit'] date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ') clock = _Clock(date.hour, date.minute) if day != weekday_name(date.weekday()): body.append(f"{weekday_name(date.weekday())}:") day = weekday_name(date.weekday()) body.append( f"{clock.time} - {air_temperature['values'][0]}{degree_unit} - {wind_speed['values'][0]}{wind_speed['unit']} - {weather.forecast}" ) body = '\n'.join(body) try: push = pushbullet.Push(config['PUSHBULLET']['access_token']) push.delete(config['PUSHBULLET']['iden']) except KeyError as key_error: if key_error.args[0] == 'iden': pass elif key_error.args[0] == 'PUSHBULLET': print('Pusbullet section is missing. Run setup.py.') raise elif key_error.args[0] == 'access_token': print('Pushbullet access token is missing. Run setup.py.') raise else: raise data = { 'iden': uuid.uuid4(), 'type': 'note', 'title': 'Todays forecast', 'body': body } config['PUSHBULLET']['iden'] = push.create(data) settings.save(config, 'settings.ini')
except: pass if _i: _i = _i.lower() if is_add(_i): return None if handle_delete(_i): return None else: print('You must pass item number to delete profile (e.g. d 1).') return proc() while not settings.is_background and not correct: settings.get_environments(load_from_env=do_load_from_env) settings.save() is_adding = False print(f'ping timeout: {settings.g["ping_timeout"]}') if len(settings.profiles) > 0: print() print('[option] [arg]') print('Options:') print('a\t: add new profile') print('d\t: delete existing profile(d {index})') print() print('profiles:') print('- Enter profile number/option which is described:') print() if force_list_profile or len(settings.profiles) > 1: selected_number = None selected_profile = settings.g.get('selected_profile', -1)
def update(self, **kwargs): if not Purple.paused: if self.check_grid((32, 32)): # checks grid if not self.position == self.previous_pos: # update move achievement achievements.achievements["total_dist"].main_value += 32 # aheradrim if ( self.position[0] == -96 and not Purple.aheradrim and "secret" in maingame.maingame.levels.current().description ): achievements.achievements["aheradrim"].main_value = 1 Purple.aheradrim = True self.image = Images.aheradrim_image # collision with Paint other = Paint.all.check_same_pos(self) if other: achievement = achievements.achievements["paint_collected"] achievement.main_value += 1 maingame.maingame.audio.sfx_pickup.play() other.destroy() if len(Paint.all) == 0: Exit.all.get_sprite(0).enable() if not self.on_grid_update(): # if update was not handled by parent # handle it now # collision with Exit other = Exit.all.check_same_pos(self) if other: if other.check_enabled(): # LEVEL WON # first add to the list of won levels current_level_location = maingame.maingame.levels.current().source_tmx levels_won = settings.get("levels_won") if current_level_location not in levels_won: levels_won.append(current_level_location) # then increment unlocked if needed unlocked = settings.get("unlocked") if maingame.maingame.levels.current_index() == unlocked - 1: settings.set("unlocked", unlocked + 1) settings.save() # and save if maingame.maingame.levels.jump_next(): # reached the end if maingame.maingame.levels.current_directory_index() == 0: maingame.maingame.controller = controllers.EndGameController() # end game screen else: maingame.maingame.controller = controllers.LevelSelectionController() return # collision with Tutorial other = Tutorial.all.check_same_pos(self) if other and not other.inactive: dialogs.Message("Tutorial", Tutorial.messages[Tutorial.current]) Tutorial.current = min(Tutorial.current + 1, len(Tutorial.messages) - 1) other.destroy() # handle keyboard if self.speed == (0, 0) or not Ice.all.check_same_pos(self): # if we are not sliding if self.collided <= 0: # if it is not moving then set speed according to key pressed self.speed = tsoliasgame.vector2.multiply(Purple.spd, Purple.direction) else: self.speed = (0, 0) # anyway check if target position is occupied if self.check_collision_ahead(Wall.all) and not Purple.aheradrim: # collision with wall self.speed = (0, 0) # set speed to 0 else: other = self.check_collision_ahead(WoodenBox.all) # collision with wooden box if other: if tsoliasgame.vector2.get_length(self.speed) <= Purple.spd: self.speed = (0, 0) else: other.destroy() maingame.maingame.audio.sfx_break.play() else: # not on grid other = pygame.sprite.spritecollideany( self, Rock.all, tsoliasgame.Obj.collide_circle ) # check collision with rocks if other: other.speed = self.speed # if there is another rock or wall ahead of the collided rock if ( other.check_collision_ahead(Wall.all) or other.check_collision_ahead(Rock.all) or other.check_collision_ahead(WoodenBox.all) ): self.speed = (0, 0) # set the speed of everything to 0 and snap to grid self.snap_grid((32, 32)) other.speed = (0, 0) else: other.collided = True # the other.collided will prevent the rock from instantly setting its speed to 0 self.speed = tsoliasgame.vector2.multiply(-1, other.speed) # reverse self speed self.collided = int(maingame.maingame.get_fps() * 0.3) # and set self.collided so that we dont allow keypresses to work for ~500ms self.collided -= 1 # HANDLE ANIMATION self.on_update_end() if not self.paused and not Purple.aheradrim: # BLINK ANIMATION - ONLY IF NOT PAUSED if self.current_image == 0: if self.__blink <= 0: self.animation_enabled = True self.__blink = maingame.maingame.fps * 10 else: self.animation_enabled = False self.__blink -= 1 tsoliasgame.Obj.update( self, not Purple.paused or "secret" in maingame.maingame.levels.current().description and self.position[0] <= 256, )
def settings_page(): context = {'flash': None} if request.method == "POST": try: # put some request variables in local variables to make easier to read current_pass = request.form.get('curpassword', '') new_pass = request.form.get('password', '') new_pass2 = request.form.get('password2', '') current_pass = '' if current_pass == '' else hashlib.sha256( current_pass).hexdigest() new_pass = '' if new_pass == '' else hashlib.sha256( new_pass).hexdigest() new_pass2 = '' if new_pass2 == '' else hashlib.sha256( new_pass2).hexdigest() new_user = request.form.get('user', '') use_auth = request.form.get('use_auth', '') == 'on' # Handle auth components if settings['password'] != '': # if password currently set, if new_user != settings['user']: # trying to change user # should have current password set. Optionally may change password. if current_pass == '': if not use_auth: raise ValueError( "Must supply current password to disable authentication" ) raise ValueError( "Must supply current password to change username") if current_pass != settings['password']: raise ValueError("Incorrect current password.") settings['user'] = new_user if new_pass != '' and use_auth: if current_pass == '': raise ValueError( "Must supply current password to change password") if current_pass != settings['password']: raise ValueError("Incorrect current password.") if new_pass2 != new_pass: # changing password raise ValueError("New passwords do not match!") settings['password'] = new_pass if new_pass == '' and not use_auth and new_pass2 == '': # trying to disable authentication if current_pass == '': raise ValueError( "Must supply current password to disable authentication" ) settings['password'] = '' else: # no current password if new_user != '': # setting username and password if new_pass != '' and new_pass != new_pass2: raise ValueError("New passwords do not match!") if new_pass == '': raise ValueError("Must provide password") settings['user'] = new_user settings['password'] = new_pass for field, default in CONFIGURABLE_SETTINGS.items(): value = request.form.get(field, default) # skip user and password as they should be handled already. if field == "user" or field == "password": continue if isinstance(default, bool): value = value == 'on' settings[field] = value settings.save() publisher = ZmqPublisher.get_instance() publisher.send_to_viewer('reload') context['flash'] = { 'class': "success", 'message': "Settings were successfully saved." } except ValueError as e: context['flash'] = {'class': "danger", 'message': e} except IOError as e: context['flash'] = {'class': "danger", 'message': e} except OSError as e: context['flash'] = {'class': "danger", 'message': e} else: settings.load() for field, default in DEFAULTS['viewer'].items(): context[field] = settings[field] context['user'] = settings['user'] context['password'] = "******" if settings['password'] != "" else "" context['reset_button_state'] = "disabled" if path.isfile( path.join(HOME, DISABLE_MANAGE_NETWORK)) else "" if not settings['user'] or not settings['password']: context['use_auth'] = False else: context['use_auth'] = True return template('settings.html', **context)
def setup(): settings.setup(load_from_env=False) settings.save()