def __handle_date_progression(self): tasks = self.periodic_task_generator.get_tasks() for task_id, task in enumerate(tasks): saved_value = SharedPreferences().get(self.__generate_preference_string(task.name)) if saved_value is not None: if task.type is TaskType.event: if datetime.datetime.strptime(saved_value[:], '%Y-%m-%d').date().year < DateHelper.get_today_short().year: SharedPreferences().clear_key(self.__generate_preference_string(task.name)) else: if task.date_to_finish > datetime.datetime.strptime(saved_value[:], '%Y-%m-%d').date(): SharedPreferences().clear_key(self.__generate_preference_string(task.name))
def test_save_and_load(self): s = SharedPreferences(self.preferences_location) self.assertEqual(s.get('important_data'), None) self.assertEqual(s.get('different_important_data'), None) s.put('important_data', 'secret_value') s.put('different_data', 'different_secret_value') self.assertEqual(s.get('important_data'), 'secret_value') self.assertEqual(s.get('different_data'), 'different_secret_value')
def __load_recipe(self): for i in range(0, 5): saved_value = SharedPreferences().get(self.meal_string + str(i)) if saved_value is None: self.meal.append(None) else: self.meal.append(int(saved_value))
def __command_set(self, args): if args is None: return MumjolandiaResponseObject( status=MumjolandiaReturnValue.game_set_wrong_id, arguments=[]) found_game_id = None try: arg_as_int = int(args[0]) except ValueError: arg_as_int = None if arg_as_int is not None: for g in self.games: if arg_as_int == g.game_id: found_game_id = g.game_id break else: for g in self.games: if args[0] == g.name: found_game_id = g.game_id break if found_game_id is None: return MumjolandiaResponseObject( status=MumjolandiaReturnValue.game_set_wrong_id, arguments=[]) else: SharedPreferences().put('current_game_id', found_game_id) self.current_game_id = found_game_id return MumjolandiaResponseObject( status=MumjolandiaReturnValue.game_set_ok, arguments=[])
def __init__(self): super().__init__() self.start_date_string = 'pompejanka_start_date' self.start_date = SharedPreferences().get(self.start_date_string) if self.start_date is not None: self.start_date = datetime.strptime(self.start_date, "%Y-%m-%d").date() self.__init()
def __init__(self, file_location=ConfigLoader.get_mumjolandia_location() + 'data/games.db'): super().__init__() self.game_file_location = file_location self.games_loader = GameDbAdapter(self.game_file_location) self.games = None self.current_game_id = SharedPreferences().get('current_game_id') self.__init()
def __create_password_validation_string(self, password): self.password_validation_string = PydesWrapper().encrypt( password, self.password_validation_magic_word) if self.password_validation_string is not None: SharedPreferences().put( self.password_validation_string_pickle_name, self.password_validation_string) return True return False
def set_undone(self, task_id): return_value = None self.__handle_date_progression() tasks = self.periodic_task_generator.get_tasks() try: if 0 <= task_id < len(tasks): return_value = SharedPreferences().clear_key(self.__generate_preference_string(tasks[task_id].name)) except TypeError: # len(tasks) is Null pass return return_value
def __init__(self, file_location='data/passwords.pickle'): super().__init__() self.file_location = file_location self.passwords_encrypted = None self.password_loader = ObjectLoaderPickle(self.file_location) self.password_validation_string_pickle_name = 'password_validation_string' self.password_validation_string = SharedPreferences().get( self.password_validation_string_pickle_name) self.password_validation_magic_word = 'R U S Z A N I E' self.main_password = None self.__init()
def is_done(self, task_id): return_value = False self.__handle_date_progression() tasks = self.periodic_task_generator.get_tasks() try: if 0 <= task_id < len(tasks): if SharedPreferences().get(self.__generate_preference_string(tasks[task_id].name)): return_value = True except TypeError: # len(tasks) is Null pass return return_value
def __command_set(self, args): if args is None: return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Parameter not provided']) if int(args[0]) > 0: return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Value has to be <= 0']) self.start_date = DateHelper.get_today_short(args[0]) SharedPreferences().put(self.start_date_string, str(self.start_date)) return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Set to: ' + str(DateHelper.get_today_short(args[0]))])
def test_clear_key(self): key1 = 'delete_me' key2 = 'delete_me_not' data1 = 'some_data1' data2 = 'some_data2' s = SharedPreferences(self.preferences_location) s.put(key1, data1) s.put(key2, data2) self.assertEqual(s.get(key1), data1) self.assertEqual(s.get(key2), data2) s.clear_key(key1) self.assertEqual(s.get(key1), None) self.assertEqual(s.get(key2), data2)
def test_clear_with_starting_pattern(self): start_string = 'find_me' non_start_string_first = 'ind_me' non_start_string_second = 'find_m' key1 = start_string + 'some_data' key2 = start_string + '_different_data' key3 = non_start_string_first + '_some_data' key4 = non_start_string_second + 'some_data' data1 = 'some_data1' data2 = 'some_data2' data3 = 'some_data3' data4 = 'some_data4' s = SharedPreferences(self.preferences_location) s.put(key1, data1) s.put(key2, data2) s.put(key3, data3) s.put(key4, data4) self.assertEqual(s.get(key1), data1) self.assertEqual(s.get(key2), data2) self.assertEqual(s.get(key3), data3) self.assertEqual(s.get(key4), data4) s.clear_starting_pattern(start_string) self.assertEqual(s.get(key1), None) self.assertEqual(s.get(key2), None) self.assertEqual(s.get(key3), data3) self.assertEqual(s.get(key4), data4)
def __command_clear(self, args): self.start_date = None SharedPreferences().clear_key(self.start_date_string) return MumjolandiaResponseObject( status=MumjolandiaReturnValue.pompejanka_message, arguments=['Clear ok'])
def reset(self): SharedPreferences().clear_starting_pattern(self.tasks_prefix)
def __command_preferences(self, args): return MumjolandiaResponseObject( status=MumjolandiaReturnValue.utils_shared_preferences_get, arguments=[SharedPreferences().get_all()])
def test_overwrite_data(self): s = SharedPreferences(self.preferences_location) self.assertEqual(s.get('important_data'), None) s.put('important_data', 'secret_value') s.put('important_data', 'different_value') self.assertEqual(s.get('important_data'), 'different_value')
def test_other_instance(self): s1 = SharedPreferences(self.preferences_location) self.assertEqual(s1.get('important_data'), None) s1.put('important_data', 'secret_value') s2 = SharedPreferences(self.preferences_location) self.assertEqual(s2.get('important_data'), 'secret_value')
def test_load_non_existing_data(self): s = SharedPreferences(self.preferences_location) self.assertEqual(s.get('non_existing_data'), None)
def __save_recipe(self): for i in range(0, 4): if self.meal[i] is None: SharedPreferences().clear_key(self.meal_string + str(i)) else: SharedPreferences().put(self.meal_string + str(i), str(self.meal[i]))