def record_user_interaction(instance, base_name): ''' This is to store some of the user actions, so we can determine if the user does the optional side quests. Args: The class instance. base_name (str): a string for the identity of the command. ''' class_instance = instance.__class__.__name__ challenge_number = instance.challenge_number profile_var_name = "{} {} {}".format(base_name, challenge_number, class_instance) # First, try loading the profile variable name # If the value is None, then make it True and increment the total. already_done = load_app_state_variable("linux-story", profile_var_name) # If the command has not been done yet in this class, then increment the # total if not already_done: save_app_state_variable("linux-story", profile_var_name, True) total_name = "{} total".format(base_name) increment_app_state_variable("linux-story", total_name, 1)
def _show_icon_tutorial(self): try: from kano_profile.apps import save_app_state_variable, load_app_state_variable if load_app_state_variable('kano-apps', 'icon-tutorial-shown'): return else: save_app_state_variable('kano-apps', 'icon-tutorial-shown', True) except ImportError: # ignore problems importing kano_profile, as we don't want it to # be a dependency pass kdialog = KanoDialog( _("Add more apps to the desktop"), _("Click the '+' button to the right of the app name to " "make it appear on the desktop. You can remove it again " "by clicking on 'x'."), {_("OK, GOT IT"): { "return_value": 0, "color": "green" }}, parent_window=self) kdialog.set_action_background("grey") kdialog.title.description.set_max_width_chars(40) kdialog.run()
def record_user_interaction(instance, base_name): ''' This is to store some of the user actions, so we can determine if the user does the optional side quests. Args: The class instance. base_name (str): a string for the identity of the command. ''' class_instance = instance.__class__.__name__ challenge_number = instance.challenge_number profile_var_name = "{} {} {}".format( base_name, challenge_number, class_instance ) # First, try loading the profile variable name # If the value is None, then make it True and increment the total. already_done = load_app_state_variable("linux-story", profile_var_name) # If the command has not been done yet in this class, then increment the # total if not already_done: save_app_state_variable("linux-story", profile_var_name, True) total_name = "{} total".format(base_name) increment_app_state_variable("linux-story", total_name, 1)
def _show_icon_tutorial(self): try: from kano_profile.apps import save_app_state_variable, load_app_state_variable if load_app_state_variable('kano-apps', 'icon-tutorial-shown'): return else: save_app_state_variable('kano-apps', 'icon-tutorial-shown', True) except ImportError: # ignore problems importing kano_profile, as we don't want it to # be a dependency pass kdialog = KanoDialog( _("Add more apps to the desktop"), _( "Click the '+' button to the right of the app name to " "make it appear on the desktop. You can remove it again " "by clicking on 'x'." ), { _("OK, GOT IT"): { "return_value": 0, "color": "green" } }, parent_window=self ) kdialog.set_action_background("grey") kdialog.title.description.set_max_width_chars(40) kdialog.run()
def check_command(self, line): checked_diary = load_app_state_variable("linux-story", "checked_mums_diary") if line == 'cat .safe/mums-diary' and not checked_diary: self.send_hint(_("\n{{rb:You read your Mum\'s diary!}} {{ob:Your nosiness has been recorded.}}")) save_app_state_variable("linux-story", "checked_mums_diary", True) return False return StepTemplateMv.check_command(self, line)
def check_command(self, line): if line == self.commands[0]: save_app_state_variable('linux-story', 'outfit', 'skirt') elif line == self.commands[1]: save_app_state_variable('linux-story', 'outfit', 'trousers') elif not self.checked_outside_wardrobe and (line == "cat trousers" or line == "cat skirt"): self.send_hint(_("\n{{rb:You need to look in your}} {{bb:wardrobe}} {{rb:for that item.}}")) self.checked_outside_wardrobe = True return StepCat.check_command(self, line)
def check_command(self, line): checked_diary = load_app_state_variable("linux-story", "checked_mums_diary") if line == 'cat .safe/mums-diary' and not checked_diary: self.send_hint( _("\n{{rb:You read your Mum\'s diary!}} {{ob:Your nosiness has been recorded.}}" )) save_app_state_variable("linux-story", "checked_mums_diary", True) return False return StepTemplateMv.check_command(self, line)
def cache_data(category, value): if category in [ "username", "email", "secondary_email", "birthday_day", "birthday_month", "birthday_year", "marketing_enabled", ]: save_app_state_variable("kano-avatar-registration", category, value)
def __get_xp(challenge): level = load_app_state_variable("linux-story", "level") if level is None: save_app_state_variable("linux-story", "level", 0) return "" if challenge > level + 1: xp = get_app_xp_for_challenge("linux-story", str(challenge)) if xp > 0: return _("{{gb:Congratulations, you earned %d XP!}}\n\n") % xp return ""
def save_hardware_info(): """Saves hardware information related to the Raspberry Pi / Kano Kit""" from kano.logging import logger from kano.utils import get_cpu_id, get_mac_address, detect_kano_keyboard logger.info('save_hardware_info') state = { 'cpu_id': get_cpu_id(), 'mac_address': get_mac_address(), 'kano_keyboard': detect_kano_keyboard(), } save_app_state_variable('kano-tracker', 'hardware_info', state)
def check_command(self, line): if line == self.commands[0]: save_app_state_variable('linux-story', 'outfit', 'skirt') elif line == self.commands[1]: save_app_state_variable('linux-story', 'outfit', 'trousers') elif not self.checked_outside_wardrobe and (line == "cat trousers" or line == "cat skirt"): self.send_hint( _("\n{{rb:You need to look in your}} {{bb:wardrobe}} {{rb:for that item.}}" )) self.checked_outside_wardrobe = True return StepCat.check_command(self, line)
def check_command(self): checked_diary = load_app_state_variable( "linux-story", "checked_mums_diary" ) # Check to see if the kid reads his/her Mum's journal if self.last_user_input == 'cat .safe/mums-diary' and \ not checked_diary: self.send_hint( _("\n{{rb:You read your Mum\'s diary!}} {{ob:Your nosiness has been recorded.}}") ) save_app_state_variable("linux-story", "checked_mums_diary", True) return False return StepTemplateMv.check_command(self)
def save_hardware_info(): """Saves hardware information related to the Raspberry Pi / Kano Kit""" from kano.logging import logger from kano.utils.hardware import get_cpu_id, get_mac_address, \ detect_kano_keyboard logger.info('save_hardware_info') state = { 'cpu_id': get_cpu_id(), 'mac_address': get_mac_address(), 'kano_keyboard': detect_kano_keyboard(), } save_app_state_variable('kano-tracker', 'hardware_info', state)
def check_command(self): checked_diary = load_app_state_variable( "linux-story", "checked_mums_diary" ) # Check to see if the kid reads his/her Mum's journal if self.last_user_input == 'cat .cassaforte/diario-della-mamma' and \ not checked_diary: self.send_hint( "\n{{rb:Hai letto il diario della mamma!}} " "{{ob:Hai fatto rumore, ti hanno sentito.}}" ) save_app_state_variable("linux-story", "checked_mums_diary", True) return False return StepTemplateMv.check_command(self)
def check_command(self): checked_diary = load_app_state_variable( "linux-story", "checked_mums_diary" ) # Check to see if the kid reads his/her Mum's journal if self.last_user_input == 'cat .safe/mums-diary' and \ not checked_diary: self.send_hint( "\n{{rb:You read your Mum\'s diary!}} " "{{ob:Your nosiness has been recorded.}}" ) save_app_state_variable("linux-story", "checked_mums_diary", True) return False return StepTemplateMv.check_command(self)
def check_command(self): if self.last_user_input == self.commands[0]: save_app_state_variable('linux-story', 'outfit', 'skirt') elif self.last_user_input == self.commands[1]: save_app_state_variable('linux-story', 'outfit', 'trousers') elif not self.checked_outside_wardrobe and \ (self.last_user_input == "cat trousers" or self.last_user_input == "cat skirt"): self.send_text( "\n{{rb:You need to look in your}} {{lb:wardrobe}} " "{{rb:for that item.}}" ) self.checked_outside_wardrobe = True return StepCat.check_command(self)
def save_kano_version(): """Saves a dict of os-version: time values, to keep track of the users update process""" updates = load_app_state_variable('kano-tracker', 'versions') if not updates: updates = dict() version_now = read_file_contents('/etc/kanux_version') if not version_now: return version_now = version_now.replace('.', '_') time_now = datetime.datetime.utcnow().isoformat() updates[version_now] = time_now save_app_state_variable('kano-tracker', 'versions', updates)
def save_kano_version(): """Saves a dict of os-version: time values, to keep track of the users update process""" updates = load_app_state_variable('kano-tracker', 'versions') if not updates: updates = dict() version_now = read_file_contents('/etc/kanux_version') if not version_now: return version_now = version_now.replace('.', '_') time_now = datetime.datetime.utcnow().isoformat() updates[version_now] = time_now save_app_state_variable('kano-tracker', 'versions', updates)
def _show_icon_tutorial(self): if load_app_state_variable('kano-apps', 'icon-tutorial-shown'): return else: save_app_state_variable('kano-apps', 'icon-tutorial-shown', True) kdialog = KanoDialog( _("Add more apps to the desktop"), _("Click the '+' button to the right of the app name to " "make it appear on the desktop. You can remove it again " "by clicking on 'x'."), {_("OK, GOT IT"): { "return_value": 0, "color": "green" }}, parent_window=self) kdialog.set_action_background("grey") kdialog.title.description.set_max_width_chars(40) kdialog.run()
def _show_icon_tutorial(self): if load_app_state_variable('kano-apps', 'icon-tutorial-shown'): return else: save_app_state_variable('kano-apps', 'icon-tutorial-shown', True) kdialog = KanoDialog( "Add more apps to the desktop", "Click the '+' button to the right of the app name to " "make it appear on the desktop. You can remove it again " "by clicking on 'x'.", { "OK, GOT IT": { "return_value": 0, "color": "green" } }, parent_window=self ) kdialog.set_action_background("grey") kdialog.title.description.set_max_width_chars(40) kdialog.run()
def cache_data(category, value): if category in ['username', 'email']: save_app_state_variable('kano-avatar-registration', category, value)
def add_runtime_to_app(app, runtime): """ Saves the tracking data for a given application. Appends a time period to a given app's runtime stats and raises starts by one. Apart from the total values, it also updates the weekly stats. This function uses advisory file locks (see flock(2)) to avoid races between different applications saving their tracking data at the same time. :param app: The name of the application. :type app: str :param runtime: For how long was the app running. :type runtime: number """ if not app or app == 'kano-tracker': return if not is_number(runtime): return runtime = float(runtime) app = app.replace('.', '_') # Make sure no one else is accessing this file app_state_file = get_app_state_file('kano-tracker') try: tracker_store = open_locked(app_state_file, 'r') except IOError as e: logger.error("Error opening app state file {}".format(e)) else: app_stats = load_app_state_variable('kano-tracker', 'app_stats') if not app_stats: app_stats = dict() try: app_stats[app]['starts'] += 1 app_stats[app]['runtime'] += runtime except Exception: app_stats[app] = { 'starts': 1, 'runtime': runtime, } # Record usage data on per-week basis if 'weekly' not in app_stats[app]: app_stats[app]['weekly'] = {} week = str(get_nearest_previous_monday()) if week not in app_stats[app]['weekly']: app_stats[app]['weekly'][week] = { 'starts': 0, 'runtime': 0 } app_stats[app]['weekly'][week]['starts'] += 1 app_stats[app]['weekly'][week]['runtime'] += runtime save_app_state_variable('kano-tracker', 'app_stats', app_stats) # Close the lock tracker_store.close()
def add_runtime_to_app(app, runtime): """ Saves the tracking data for a given application. Appends a time period to a given app's runtime stats and raises starts by one. Apart from the total values, it also updates the weekly stats. This function uses advisory file locks (see flock(2)) to avoid races between different applications saving their tracking data at the same time. :param app: The name of the application. :type app: str :param runtime: For how long was the app running. :type runtime: number """ if not app or app == 'kano-tracker': return if not is_number(runtime): return runtime = float(runtime) app = app.replace('.', '_') # Make sure no one else is accessing this file app_state_file = get_app_state_file('kano-tracker') try: tracker_store = open_locked(app_state_file, "r") except IOError as e: logger.error('Error opening app state file {}'.format(e)) else: app_stats = load_app_state_variable('kano-tracker', 'app_stats') if not app_stats: app_stats = dict() try: app_stats[app]['starts'] += 1 app_stats[app]['runtime'] += runtime except Exception: app_stats[app] = { 'starts': 1, 'runtime': runtime, } # Record usage data on per-week basis if 'weekly' not in app_stats[app]: app_stats[app]['weekly'] = {} week = str(_get_nearest_previous_monday()) if week not in app_stats[app]['weekly']: app_stats[app]['weekly'][week] = { 'starts': 0, 'runtime': 0 } app_stats[app]['weekly'][week]['starts'] += 1 app_stats[app]['weekly'][week]['runtime'] += runtime save_app_state_variable('kano-tracker', 'app_stats', app_stats) # Close the lock tracker_store.close()