Exemplo n.º 1
0
    def _add_boot_config_options(self, extra_config):
        """
        Helper function to add a block of options (text) to the boot/config.txt

        Args:
            extra_config - unindedted multiline or not str as it would go into the .txt
        """

        config_path = '/boot/config.txt'
        use_transactions = False
        # if we can't use transactions, fall back to editting the file directly
        tmp_path = config_path

        try:
            try:
                # append uart config to config.txt
                from kano_settings.boot_config import _trans, \
                    end_config_transaction

                use_transactions = True
                tmp_path = '/tmp/config.tmp'
                _trans().copy_to(tmp_path)

            except ImportError:
                pass

            with open(tmp_path, 'a') as tmp_config:
                tmp_config.write(extra_config)

            if use_transactions:
                _trans().copy_from(tmp_path)
                end_config_transaction()
        except:
            logger.error("failed to update config")
Exemplo n.º 2
0
    def apply_changes(self, button, event):

        # If enter key is pressed or mouse button is clicked
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:

            # Check if there was a change to the Flip Screen state.
            if self.flip_preference_start != self.flip_preference_end:
                set_flip(self.flip_preference_end)
                end_config_transaction()
                common.need_reboot = True

            # Check if there was resolution change.
            if self.init_item != self.mode_index:
                # Set HDMI mode
                # Get mode:group string
                # Of the form "auto" or "cea:1" or "dmt:1" etc.
                parse_mode = self.mode.split(" ")[0]
                self.set_hdmi_mode_from_str(parse_mode)

                # Track the user's screen resolution
                track_data('screen-mode-changed', {
                    'mode': parse_mode
                })

                end_config_transaction()
                common.need_reboot = True

            self.win.go_to_home()
Exemplo n.º 3
0
def set_gfx_driver(enabled):
    if enabled:
        set_config_value('dtoverlay', 'vc4-kms-v3d')
        try:
            try:
                os.makedirs(os.path.dirname(fpturbo_conf_backup_path))
            except OSError as e:
                if e.strerror == "File exists":
                    pass
                else:
                    raise
            shutil.copyfile(fpturbo_conf_path, fpturbo_conf_backup_path)
            os.remove(fpturbo_conf_path)
        except Exception as e:
            logger.error("Error restoring fpturbo_config", exception=e)

    else:
        set_config_value('dtoverlay', None)
        if not os.path.exists(fpturbo_conf_path):
            try:
                shutil.copyfile(fpturbo_conf_backup_path, fpturbo_conf_path)
            except Exception as e:
                logger.error("Error restoring fpturbo_config", exception=e)
    end_config_transaction()
    set_setting('Use_GLX', enabled)
Exemplo n.º 4
0
def set_default_config():
    # restore factory defaults

    # setting the audio to analogue
    set_to_HDMI(False)

    set_config_value("hdmi_ignore_edid_audio", 1)
    set_config_value("hdmi_drive", None)

    # resetting HDMI settings
    set_config_value("disable_overscan", 1)
    set_config_value("overscan_left", 0)
    set_config_value("overscan_right", 0)
    set_config_value("overscan_top", 0)
    set_config_value("overscan_bottom", 0)
    set_config_value("hdmi_pixel_encoding", 2)
    set_config_value("hdmi_group", None)
    set_config_value("hdmi_mode", None)
    set_config_value("display_rotate", 0)
    set_config_comment("kano_screen_used", "xxx")

    # resetting overclocking settings
    set_default_overclock_values()

    # set the keyboard to default
    set_keyboard("en_US", "generic")

    end_config_transaction()
Exemplo n.º 5
0
    def _add_boot_config_options(self, extra_config):
        """
        Helper function to add a block of options (text) to the boot/config.txt

        Args:
            extra_config - unindedted multiline or not str as it would go into the .txt
        """

        config_path = '/boot/config.txt'
        use_transactions = False
        # if we can't use transactions, fall back to editting the file directly
        tmp_path = config_path

        try:
            try:
                # append uart config to config.txt
                from kano_settings.boot_config import _trans, \
                    end_config_transaction

                use_transactions = True
                tmp_path = '/tmp/config.tmp'
                _trans().copy_to(tmp_path)

            except ImportError:
                pass

            with open(tmp_path, 'a') as tmp_config:
                tmp_config.write(extra_config)

            if use_transactions:
                _trans().copy_from(tmp_path)
                end_config_transaction()
        except:
            logger.error("failed to update config")
Exemplo n.º 6
0
def set_gfx_driver(enabled):
    if enabled:
        set_config_value('dtoverlay', 'vc4-kms-v3d')
        try:
            try:
                os.makedirs(os.path.dirname(fpturbo_conf_backup_path))
            except OSError as e:
                if e.strerror == "File exists":
                    pass
                else:
                    raise
            shutil.copyfile(fpturbo_conf_path, fpturbo_conf_backup_path)
            os.remove(fpturbo_conf_path)
        except Exception as e:
            logger.error("Error restoring fpturbo_config", exception=e)

    else:
        set_config_value('dtoverlay', None)
        if not os.path.exists(fpturbo_conf_path):
            try:
                shutil.copyfile(fpturbo_conf_backup_path, fpturbo_conf_path)
            except Exception as e:
                logger.error("Error restoring fpturbo_config", exception=e)
    end_config_transaction()
    set_setting('Use_GLX', enabled)
Exemplo n.º 7
0
def set_default_config():
    # restore factory defaults

    # setting the audio to analogue
    set_to_HDMI(False)

    set_config_value('hdmi_ignore_edid_audio', 1)
    set_config_value('hdmi_drive', None)

    # resetting HDMI settings
    set_config_value('disable_overscan', 1)
    set_config_value('overscan_left', 0)
    set_config_value('overscan_right', 0)
    set_config_value('overscan_top', 0)
    set_config_value('overscan_bottom', 0)
    set_config_value('hdmi_pixel_encoding', 2)
    set_config_value('hdmi_group', None)
    set_config_value('hdmi_mode', None)
    set_config_value('display_rotate', 0)

    # resetting overclocking settings
    set_default_overclock_values()

    # set the keyboard to default
    set_keyboard('en_US', 'generic')

    end_config_transaction()
Exemplo n.º 8
0
    def apply_changes(self, button, event):

        # If enter key is pressed or mouse button is clicked
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:

            # Check if there was a change to the Flip Screen state.
            if self.flip_preference_start != self.flip_preference_end:
                set_flip(self.flip_preference_end)
                end_config_transaction()
                common.need_reboot = True

            # Check if there was resolution change.
            if self.init_item != self.mode_index:
                # Set HDMI mode
                # Get mode:group string
                # Of the form "auto" or "cea:1" or "dmt:1" etc.
                parse_mode = self.mode.split(" ")[0]
                self.set_hdmi_mode_from_str(parse_mode)

                # Track the user's screen resolution
                track_data('screen-mode-changed', {'mode': parse_mode})

                end_config_transaction()
                common.need_reboot = True

            self.win.go_to_home()
Exemplo n.º 9
0
 def enable_audio_device():
     from kano_settings.boot_config import set_config_value
     set_config_value("dtparam=audio", "on")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaction not present - update to kano-settings failed?")
Exemplo n.º 10
0
def is_overscan():
    # This completes a transaction to avoid kano-video holding the lock
    top = get_screen_value('overscan_top')
    bottom = get_screen_value('overscan_bottom')
    left = get_screen_value('overscan_left')
    right = get_screen_value('overscan_right')
    end_config_transaction()
    return (top or bottom or left or right)
Exemplo n.º 11
0
 def disable_audio_dither():
     from kano_settings.boot_config import set_config_value
     set_config_value("disable_audio_dither", "1")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaction not present")
Exemplo n.º 12
0
 def disable_audio_dither():
     from kano_settings.boot_config import set_config_value
     set_config_value("disable_audio_dither", "1")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaction not present")
Exemplo n.º 13
0
def is_overscan():
    # This completes a transaction to avoid kano-video holding the lock
    top = get_screen_value('overscan_top')
    bottom = get_screen_value('overscan_bottom')
    left = get_screen_value('overscan_left')
    right = get_screen_value('overscan_right')
    end_config_transaction()
    return (top or bottom or left or right)
Exemplo n.º 14
0
 def _bootconfig_set_value_helper(self, setting, value):
     # Set a value in boot config; include compatibility with old API
     from kano_settings.boot_config import set_config_value
     set_config_value(setting, value)
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error("end_config_transaciton not present - update to kano-settings failed?")
Exemplo n.º 15
0
        def test_close(configs):
            boot_config.end_config_transaction()
            configs['current'] = read_config()

            print "testing close"

            # all written items should now be present
            self.assertTrue(compare(configs['current'], configs['written']))
            self.assertTrue(boot_config._trans().state == 0)
            self.assertTrue(not is_locked())
        def test_close(configs):
            boot_config.end_config_transaction()
            configs['current'] = read_config()

            print "testing close"

            # all written items should now be present
            self.assertTrue(compare(configs['current'], configs['written']))
            self.assertTrue(boot_config._trans().state == 0)
            self.assertTrue(not is_locked())
Exemplo n.º 17
0
 def enable_audio_device():
     from kano_settings.boot_config import set_config_value
     set_config_value("dtparam=audio", "on")
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error(
             "end_config_transaction not present - update to kano-settings failed?"
         )
def main():
    """TODO"""

    if os.getuid() != 0:
        return 10

    logger.info('Reverting Safe Mode config.txt configuration')

    config_copy_from(CONFIG_TXT_BACKUP_PATH)
    os.remove(CONFIG_TXT_BACKUP_PATH)
    end_config_transaction()
def main():
    """TODO"""

    if os.getuid() != 0:
        return 10

    logger.warn("Applying Safe Mode config.txt settings")

    config_copy_to(CONFIG_TXT_BACKUP_PATH)
    set_safe_mode_config()
    end_config_transaction()
Exemplo n.º 20
0
 def _bootconfig_set_value_helper(self, setting, value):
     # Set a value in boot config; include compatibility with old API
     from kano_settings.boot_config import set_config_value
     set_config_value(setting, value)
     try:
         from kano_settings.boot_config import end_config_transaction
         end_config_transaction()
     except ImportError:
         logger.error(
             "end_config_transaciton not present - update to kano-settings failed?"
         )
Exemplo n.º 21
0
    def set_overclock(self, widget, event):
        # If enter key is pressed or mouse button is clicked
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:

            # Mode has no changed
            if self.initial_button == self.selected_button:
                self.win.go_to_home()
                return

            config = self._board_clocking['modes'][self.selected_button]
            change_overclock = True

            if is_dangerous_overclock_value(config):

                kdialog = KanoDialog(
                    title_text=_("Warning"),
                    description_text=(
                        _("For a small percentage of users, this setting makes " \
                          "the Pi behave unpredictably. Do you want to " \
                          "continue?")
                    ),
                    button_dict=[
                        {
                            'label': _("NO"),
                            'color': 'red',
                            'return_value': False
                        },
                        {
                            'label': _("YES"),
                            'color': 'green',
                            'return_value': True
                        }
                    ],
                    parent_window=self.win
                )
                change_overclock = kdialog.run()

            if change_overclock:
                change_overclock_value(config)

                # Tell user to reboot to see changes
                end_config_transaction()
                common.need_reboot = True

                self.win.go_to_home()
Exemplo n.º 22
0
    def set_overclock(self, widget, event):
        # If enter key is pressed or mouse button is clicked
        if not hasattr(event, 'keyval') or event.keyval == Gdk.KEY_Return:

            # Mode has no changed
            if self.initial_button == self.selected_button:
                self.win.go_to_home()
                return

            config = self._board_clocking['modes'][self.selected_button]
            change_overclock = True

            if is_dangerous_overclock_value(config):

                kdialog = KanoDialog(
                    title_text=_("Warning"),
                    description_text=(
                        _("For a small percentage of users, this setting makes " \
                          "the Pi behave unpredictably. Do you want to " \
                          "continue?")
                    ),
                    button_dict=[
                        {
                            'label': _("NO"),
                            'color': 'red',
                            'return_value': False
                        },
                        {
                            'label': _("YES"),
                            'color': 'green',
                            'return_value': True
                        }
                    ],
                    parent_window=self.win
                )
                change_overclock = kdialog.run()

            if change_overclock:
                change_overclock_value(config)

                # Tell user to reboot to see changes
                end_config_transaction()
                common.need_reboot = True

                self.win.go_to_home()
Exemplo n.º 23
0
def set_to_HDMI(HDMI, force=False):
    '''
    Set audio output to HDMI if supported by the display,
    otherwise set it to Analogue output.

    Returns 'HDMI' or 'Analogue', whichever was applied.
    '''

    if not is_hdmi_audio_supported() and not force:
        HDMI = False

    # 1 analog
    # 2 hdmi

    # These are the changes we'll apply if they have changed from what they were
    if HDMI:
        amixer_cmd = hdmi_cmd
        set_config_value('hdmi_ignore_edid_audio', None)
        set_config_value('hdmi_drive', 2)
        config = _("HDMI")
    else:
        amixer_cmd = analogue_cmd
        set_config_value('hdmi_ignore_edid_audio', 1)
        set_config_value('hdmi_drive', None)
        config = _("Analogue")

    end_config_transaction()

    # Set audio path in amixer
    o, e, rc = run_cmd(amixer_cmd)
    if rc:
        logger.warn("error from amixer: {} {} {}".format(o, e, rc))

    # trigger alsa-store to store the path in /var/lib/alsa/asound.state
    o, e, rc = run_cmd(store_cmd)
    if rc:
        logger.warn("error from alsa-store: {} {} {}".format(o, e, rc))

    set_setting('Audio', config)
    return config
Exemplo n.º 24
0
    def beta_310_to_beta_320(self):
        config_path = '/boot/config.txt'
        use_transactions = False
        # if we can't use transactions, fall back to editting the file directly
        tmp_path = config_path

        try:
            try:
                # append uart config to config.txt
                from kano_settings.boot_config import _trans, \
                    end_config_transaction

                use_transactions = True
                tmp_path = '/tmp/config.tmp'
                _trans().copy_to(tmp_path)

            except ImportError:
                pass

            from textwrap import dedent
            extra_config = dedent("""
            [pi3]
            # for light board
            enable_uart=1
            [all]
            """)

            with open(tmp_path, 'a') as tmp_config:
                tmp_config.write(extra_config)

            if use_transactions:
                _trans().copy_from(tmp_path)

                end_config_transaction()
        except:
            logger.error("failed to update config")
Exemplo n.º 25
0
    def beta_310_to_beta_320(self):
        config_path = '/boot/config.txt'
        use_transactions = False
        # if we can't use transactions, fall back to editting the file directly
        tmp_path = config_path

        try:
            try:
                # append uart config to config.txt
                from kano_settings.boot_config import _trans, \
                    end_config_transaction

                use_transactions = True
                tmp_path = '/tmp/config.tmp'
                _trans().copy_to(tmp_path)

            except ImportError:
                pass

            from textwrap import dedent
            extra_config = dedent("""
            [pi3]
            # for light board
            enable_uart=1
            [all]
            """)

            with open(tmp_path, 'a') as tmp_config:
                tmp_config.write(extra_config)

            if use_transactions:
                _trans().copy_from(tmp_path)

                end_config_transaction()
        except:
            logger.error("failed to update config")
Exemplo n.º 26
0
 def flip(self, button):
     set_flip(button.get_active())
     self.kano_button.set_sensitive(True)
     end_config_transaction()
     common.need_reboot = True
Exemplo n.º 27
0
 def flip(self, button):
     set_flip(button.get_active())
     self.kano_button.set_sensitive(True)
     end_config_transaction()
     common.need_reboot = True
Exemplo n.º 28
0
def write_overscan_values(overscan_values):
    set_screen_value('overscan_top', overscan_values['top'])
    set_screen_value('overscan_bottom', overscan_values['bottom'])
    set_screen_value('overscan_left', overscan_values['left'])
    set_screen_value('overscan_right', overscan_values['right'])
    end_config_transaction()
Exemplo n.º 29
0
def write_overscan_values(overscan_values):
    set_screen_value('overscan_top', overscan_values['top'])
    set_screen_value('overscan_bottom', overscan_values['bottom'])
    set_screen_value('overscan_left', overscan_values['left'])
    set_screen_value('overscan_right', overscan_values['right'])
    end_config_transaction()