def run(self):
        response = self.dialog.run()
        if response == Gtk.ResponseType.APPLY:
            grub = {}
            params = []
            grub_path = "/etc/default/grub"
            # TODO: Write to a temp file ala mktemp
            temp_grub_path = "/tmp/foo.txt"

            fd = os.open(temp_grub_path, os.O_RDWR|os.O_CREAT)
            fo = os.fdopen(fd, "w+")
            if self.__disable_pat:
                params.append('nopat')
            if self.__disable_vesafb:
                params.append('vesafb.invalid=1')
            if self.__enable_debugging:
                # TODO: Enable debug for Xorg.0.log
                params.append('drm.debug=0xe')
#            if self.__disable_grub_graphics is not None:
#                if self.__disable_grub_graphics:
#                    grub['GRUB_GFXPAYLOAD_LINUX'] = 'text'
#                elif self.__grub_gfxpayload_linux != 'text':
#                    grub['GRUB_GFXPAYLOAD_LINUX'] = self.__grub_gfxpayload_linux
#                else:
#                    grub['GRUB_GFXPAYLOAD_LINUX'] = 'keep'

            grub['GRUB_CMDLINE_LINUX_DEFAULT'] = '"%s"' %(' '.join(params))

            if self.__disable_splash:
                config_update(grub_path, override_params=grub, merge_params=None, fileio=fo)
            else:
                config_update(grub_path, override_params=None, merge_params=grub, fileio=fo)

            fo.close()

            # Backup the old file
            try:
                bak_path = safe_backup(grub_path)
                if not bak_path:
                    # TODO: Display error message dialog
                    print "Error:  Could not backup file %s.  Changes not applied." %(grub_path)
                    return
            except IOError, err:
                # TODO: Display error message dialog
                print "Error:  Failure creating backup file for %s.  Changes not applied." %(grub_path)
                print err
                return

            # Move new file into place
            shutil.move(temp_grub_path, grub_path)

            # Finally, update grub
            self.update_grub()
Example #2
0
    def on_apply(self, widget):
        overrides = {}
        merges = {}
        cmdline_default_params = self.kparams
        fd, temp_grub_path = tempfile.mkstemp(text=True)
        os.chmod(temp_grub_path, stat.S_IWUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
        fo = os.fdopen(fd, "w+")
        if self.__disable_splash:
            if 'quiet' in cmdline_default_params:
                del cmdline_default_params['quiet']
            if 'splash' in cmdline_default_params:
                del cmdline_default_params['splash']
        else:
            cmdline_default_params['quiet'] = None
            cmdline_default_params['splash'] = None
        if self.__disable_pat:
            cmdline_default_params['nopat'] = None
        elif 'nopat' in cmdline_default_params:
            del cmdline_default_params['nopat']
        if self.__disable_vesafb:
            cmdline_default_params['vesafb.invalid'] = 1
        elif 'vesafb.invalid' in cmdline_default_params:
            del cmdline_default_params['vesafb.invalid']
        if self.__enable_debugging:
            # TODO: Enable debug for Xorg.0.log
            cmdline_default_params['drm.debug'] = '0xe'
            cmdline_default_params['plymouth:debug'] = None
        elif 'drm.debug' in cmdline_default_params:
            del cmdline_default_params['drm.debug']
        if self.__disable_grub_graphics is not None:
            # NOTE: Where text graphics works, this can be handled by blacklisting in grub.
            #       Should offer to file a request for this against grub maybe.
            if self.__disable_grub_graphics:
                overrides['GRUB_GFXPAYLOAD_LINUX'] = 'text'
            elif self.__grub_gfxpayload_linux != 'text':
                overrides['GRUB_GFXPAYLOAD_LINUX'] = self.__grub_gfxpayload_linux
            else:
                overrides['GRUB_GFXPAYLOAD_LINUX'] = 'keep'

        kparams = []
        for k,v in cmdline_default_params.items():
            if v is None:
                kparams.append(k)
            else:
                kparams.append("%s=%s" %(k, v))
        overrides['GRUB_CMDLINE_LINUX_DEFAULT'] = '"%s"' %(' '.join(kparams))

        assert(os.path.exists(self.__grub_config_filename))
        config_update(self.__grub_config_filename, override_params=overrides, merge_params=merges, fileio=fo)

        fo.close()

        # Backup the old file
        try:
            bak_path = safe_backup(self.__grub_config_filename)
            if not bak_path:
                # TODO: Display error message dialog
                print "Error:  Could not backup file %s.  Changes not applied." %(
                    self.__grub_config_filename)
                return
        except IOError, err:
            # TODO: Display error message dialog
            print "Error:  Failure creating backup file for %s.  Changes not applied." %(
                self.__grub_config_filename)
            print err
            return
Example #3
0
    def on_apply(self, widget):
        overrides = {}
        merges = {}
        cmdline_default_params = self.kparams
        fd, temp_grub_path = tempfile.mkstemp(text=True)
        os.chmod(temp_grub_path, stat.S_IWUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
        fo = os.fdopen(fd, "w+")
        if self.__disable_splash:
            if 'quiet' in cmdline_default_params:
                del cmdline_default_params['quiet']
            if 'splash' in cmdline_default_params:
                del cmdline_default_params['splash']
        else:
            cmdline_default_params['quiet'] = None
            cmdline_default_params['splash'] = None
        if self.__disable_pat:
            cmdline_default_params['nopat'] = None
        elif 'nopat' in cmdline_default_params:
            del cmdline_default_params['nopat']
        if self.__disable_vesafb:
            cmdline_default_params['vesafb.invalid'] = 1
        elif 'vesafb.invalid' in cmdline_default_params:
            del cmdline_default_params['vesafb.invalid']
        if self.__enable_debugging:
            # TODO: Enable debug for Xorg.0.log
            cmdline_default_params['drm.debug'] = '0xe'
            cmdline_default_params['plymouth:debug'] = None
        elif 'drm.debug' in cmdline_default_params:
            del cmdline_default_params['drm.debug']
        if self.__disable_grub_graphics is not None:
            # NOTE: Where text graphics works, this can be handled by blacklisting in grub.
            #       Should offer to file a request for this against grub maybe.
            if self.__disable_grub_graphics:
                overrides['GRUB_GFXPAYLOAD_LINUX'] = 'text'
            elif self.__grub_gfxpayload_linux != 'text':
                overrides['GRUB_GFXPAYLOAD_LINUX'] = self.__grub_gfxpayload_linux
            else:
                overrides['GRUB_GFXPAYLOAD_LINUX'] = 'keep'

        kparams = []
        for k,v in cmdline_default_params.items():
            if not k:
                continue
            elif v is None:
                kparams.append(k)
            else:
                kparams.append("%s=%s" %(k, v))
        overrides['GRUB_CMDLINE_LINUX_DEFAULT'] = '"%s"' %(' '.join(kparams))

        assert(os.path.exists(self.__grub_config_filename))
        config_update(self.__grub_config_filename, override_params=overrides, merge_params=merges, fileio=fo)

        fo.close()

        # Backup the old file
        try:
            bak_path = safe_backup(self.__grub_config_filename)
            if not bak_path:
                # TODO: Display error message dialog
                print("Error:  Could not backup file %s.  Changes not applied." %(
                    self.__grub_config_filename))
                return
        except IOError as err:
            # TODO: Display error message dialog
            print("Error:  Failure creating backup file for %s.  Changes not applied." %(
                self.__grub_config_filename))
            print(err)
            return

        # Move new file into place
        shutil.move(temp_grub_path, self.__grub_config_filename)
        os.chmod(self.__grub_config_filename, stat.S_IWUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)

        # Finally, update grub
        # TODO: Only do this if we change any of the grub parameters
        self.update_grub()