def download_app(app_id_or_slug): data = query_for_app(app_id_or_slug) # download the icon icon_file_type = data['icon_url'].split(".")[-1] icon_path = '/tmp/{}.{}'.format(app_id_or_slug, icon_file_type) rv, err = download_url(data['icon_url'], icon_path) if not rv: msg = "Unable to download the application ({})".format(err) raise AppDownloadError(msg) # Check if the app isn't rpi2 only if not is_model_2_b() and 'rpi2_only' in data and data['rpi2_only']: msg = "{} won't be downloaded ".format(data['title']) + \ "becuase it's Raspberry Pi 2 only" raise AppDownloadError(msg) # Cleanup the JSON file data['icon'] = data['slug'] del data['icon_url'] del data['likes'] del data['comments_count'] data['time_installed'] = int(time.time()) data['categories'] = map(lambda c: c.lower(), data['categories']) data['removable'] = True # write out the data data_path = '/tmp/{}.app'.format(app_id_or_slug) with open(data_path, 'w') as f: f.write(json.dumps(data)) return [data_path, icon_path]
def get_pi_key(): pi2 = is_model_2_b() key = "pi1" if pi2: key = "pi2" return key
def get_model_name(): if is_model_a(): model = "A" elif is_model_b(): model = "B" elif is_model_b_plus(): model = "B+" elif is_model_2_b(): model = "2" return "Raspberry Pi {}".format(model)
def update_progress(self, percent, phase_name, msg, sub_msg=''): # enabling flappy-judoka launch only after these phases (when a reboot is iminent) if phase_name in ['downloading', 'downloading-pip-pkgs', 'init', 'installing-urgent']: # killing the notification daemon in case there are frozen notifications at this point os.system('pkill -f kano-notifications-daemon') if is_model_2_b(): # enable flappy-judoka only for the RPI2 self.get_toplevel().connect('key-release-event', self._launch_game) self._pgl.show() percent_fraction = percent / 100. self._progress_bar.set_fraction(percent_fraction) idx = percent_fraction * (len(STAGE_TEXT) - 1) current_text = STAGE_TEXT[int(idx)] self._psa.set_markup(current_text) if self._progress_phase.get_text() != msg: self._progress_phase.set_text(msg) self._progress_subphase.set_text(sub_msg) self._percent_display.set_text( "Time flies - {}% already!".format(percent))
def check_clock_config_matches_chip(): """ Check if the clock setting in the current config is supported on the chip we have booted on. If not, try to restore from a backup file. If that is not possible, set to a default appropraite to this chip. """ # This will need updating if another board is made. curr_pi2 = is_model_2_b() clock_setting_match_pi2 = overclock.match_overclock_value(True) clock_setting_match_pi1 = overclock.match_overclock_value(False) if curr_pi2: if clock_setting_match_pi2 is not None: return False # config okay for pi2, do nothing elif clock_setting_match_pi1 is not None: # we are on a pi2 but the clock values match pi1 logger.info("No match in overclock settings: restoring pi2 default") swap_clock_configs(pi2_backup_config, pi1_backup_config, curr_pi2) else: logger.info("Restoring pi2 default clock settings") # we are on pi2 and current clock doesn't match either pi1 or pi2 overclock.set_default_overclock_values(curr_pi2) else: # exactly as above in reverse if clock_setting_match_pi1 is not None: return False # config okay for pi1, do nothing elif clock_setting_match_pi2 is not None: # we are on a pi1 but the clock values match pi2 swap_clock_configs(pi1_backup_config, pi2_backup_config, curr_pi2) else: # we are on pi1 and current clock doesn't match either pi1 or pi2 logger.info("No match in overclock settings: restoring pi1 default") overclock.set_default_overclock_values(curr_pi2) return True # we need to reboot if we get here
#!/usr/bin/env python # Storybook.py # # Copyright (C) 2014 Kano Computing Ltd # License: GNU GPL v2 http://www.gnu.org/licenses/gpl-2.0.txt # # Author: Caroline Clark <*****@*****.**> from gi.repository import Gtk, Pango, Gdk import time from kano.utils import is_model_2_b if is_model_2_b(): NEWLINE_SLEEP = 0.15 OTHER_SLEEP = 0.025 else: NEWLINE_SLEEP = 0.07 OTHER_SLEEP = 0.007 class Storybook(Gtk.TextView): ''' This class displays all the hints and description text for the user on the left side of the application. ''' def __init__(self, width=None, height=None): Gtk.TextView.__init__(self) self.__generate_tags()
#!/usr/bin/env python # Storybook.py # # Copyright (C) 2014 Kano Computing Ltd # License: GNU GPL v2 http://www.gnu.org/licenses/gpl-2.0.txt # # Author: Caroline Clark <*****@*****.**> from gi.repository import Gtk, Pango, Gdk import time from kano.utils import is_model_2_b if is_model_2_b(): NEWLINE_SLEEP = 0.15 OTHER_SLEEP = 0.025 else: NEWLINE_SLEEP = 0.07 OTHER_SLEEP = 0.007 class Storybook(Gtk.TextView): ''' This class displays all the hints and description text for the user on the left side of the application. ''' def __init__(self, width=None, height=None): Gtk.TextView.__init__(self) self.__generate_tags() # Remove the right click pop up