From 43a8b706b13537cce4562a383a95a3a04f84e01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 14 Feb 2017 12:36:45 +0100 Subject: [PATCH 1/4] plugin_bootloader: Rename _grub2_cfg_file attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename the _grub2_cfg_file attribute to _grub2_cfg_file_name. This is to avoid the following pylint error message: An attribute defined in tuned.plugins.plugin_bootloader line 30 hides this method. The fact that the method was hidden didn't present itself in any way during execution, because the method had been saved in a collection (and accessed only from the collection after that) prior to becoming hidden. Signed-off-by: Ondřej Lysoněk --- tuned/plugins/plugin_bootloader.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tuned/plugins/plugin_bootloader.py b/tuned/plugins/plugin_bootloader.py index 8e2ae91..fc76063 100644 --- a/tuned/plugins/plugin_bootloader.py +++ b/tuned/plugins/plugin_bootloader.py @@ -27,7 +27,7 @@ class BootloaderPlugin(base.Plugin): def _instance_init(self, instance): instance._has_dynamic_tuning = False instance._has_static_tuning = True - self._grub2_cfg_file = self._get_grub2_cfg_file() + self._grub2_cfg_file_name = self._get_grub2_cfg_file() def _instance_cleanup(self, instance): pass @@ -82,7 +82,7 @@ class BootloaderPlugin(base.Plugin): def _remove_grub2_tuning(self): self._patch_bootcmdline("") - self._cmd.replace_in_file(self._grub2_cfg_file, r"\b(set\s+" + consts.GRUB2_TUNED_VAR + r"\s*=).*$", r"\1" + "\"\"") + self._cmd.replace_in_file(self._grub2_cfg_file_name, r"\b(set\s+" + consts.GRUB2_TUNED_VAR + r"\s*=).*$", r"\1" + "\"\"") def _instance_unapply_static(self, instance, profile_switch = False): if profile_switch: @@ -121,18 +121,18 @@ class BootloaderPlugin(base.Plugin): def _grub2_cfg_patch(self, value): log.debug("patching grub.cfg") - if self._grub2_cfg_file is None: + if self._grub2_cfg_file_name is None: log.error("cannot find grub.cfg to patch, you need to regenerate it by hand by grub2-mkconfig") return False - grub2_cfg = self._cmd.read_file(self._grub2_cfg_file) + grub2_cfg = self._cmd.read_file(self._grub2_cfg_file_name) if len(grub2_cfg) <= 0: - log.error("error patching %s, you need to regenerate it by hand by grub2-mkconfig" % self._grub2_cfg_file) + log.error("error patching %s, you need to regenerate it by hand by grub2-mkconfig" % self._grub2_cfg_file_name) return False - log.debug("adding boot command line parameters to '%s'" % self._grub2_cfg_file) + log.debug("adding boot command line parameters to '%s'" % self._grub2_cfg_file_name) (grub2_cfg_new, nsubs) = re.subn(r"\b(set\s+" + consts.GRUB2_TUNED_VAR + "\s*=).*$", r"\1" + "\"" + str(value) + "\"", grub2_cfg, flags = re.MULTILINE) if nsubs < 1 or re.search(r"\$" + consts.GRUB2_TUNED_VAR, grub2_cfg, flags = re.MULTILINE) is None: grub2_cfg_new = self._grub2_cfg_patch_initial(self._grub2_cfg_unpatch(grub2_cfg), value) - self._cmd.write_to_file(self._grub2_cfg_file, grub2_cfg_new) + self._cmd.write_to_file(self._grub2_cfg_file_name, grub2_cfg_new) self._grub2_default_env_patch() return True @@ -142,7 +142,7 @@ class BootloaderPlugin(base.Plugin): if verify: return None if enabling and value is not None: - self._grub2_cfg_file = value + self._grub2_cfg_file_name = value @command_custom("cmdline", per_device = False, priority = 10) def _cmdline(self, enabling, value, verify, ignore_missing): From 316f9b5bc3227788e20556b9d5a5ea0f592885f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 14 Feb 2017 12:45:00 +0100 Subject: [PATCH 2/4] plugin_loader: Pylint fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initialize some attributes of PluginLoader to avoid the following pylint errors: E: 21,14: Instance of 'PluginLoader' has no '_namespace' member (no-member) E: 22,14: Instance of 'PluginLoader' has no '_prefix' member (no-member) E: 23,14: Instance of 'PluginLoader' has no '_interface' member (no-member) The attributes were initialized only in subclasses. Signed-off-by: Ondřej Lysoněk --- tuned/utils/plugin_loader.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tuned/utils/plugin_loader.py b/tuned/utils/plugin_loader.py index aa80e20..cdaa040 100644 --- a/tuned/utils/plugin_loader.py +++ b/tuned/utils/plugin_loader.py @@ -17,6 +17,9 @@ class PluginLoader(object): def __init__(self): super(PluginLoader, self).__init__() + self._namespace = None + self._prefix = None + self._interface = None self._set_loader_parameters() assert type(self._namespace) is str assert type(self._prefix) is str From e1632568c6f94914372c5ce7b7a182285098fc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 14 Feb 2017 12:51:11 +0100 Subject: [PATCH 3/4] Fix some pylint errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ondřej Lysoněk --- tuned/profiles/variables.py | 2 +- tuned/utils/commands.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tuned/profiles/variables.py b/tuned/profiles/variables.py index 396e590..a871ad9 100644 --- a/tuned/profiles/variables.py +++ b/tuned/profiles/variables.py @@ -4,7 +4,7 @@ import tuned.logs import functions.functions as functions import tuned.consts as consts from tuned.utils.commands import commands -from configobj import ConfigObj +from configobj import ConfigObj, ConfigObjError log = tuned.logs.get() diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py index d5b2a1f..672ea0e 100644 --- a/tuned/utils/commands.py +++ b/tuned/utils/commands.py @@ -129,7 +129,7 @@ class commands: os.rename(src, dst) except OSError as error: if not no_error: - log.error("cannot rename file '%s' to '%s': '%s'" % (f, str(error))) + log.error("cannot rename file '%s' to '%s': '%s'" % (src, dst, str(error))) return False return True From 8e6827c8981c6d7f4fef9deaa905d40bf00726fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 14 Feb 2017 15:32:01 +0100 Subject: [PATCH 4/4] GUI: Fix some pylint errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the following pylint errors: ************* Module tuned.gtk.gui_plugin_loader E:145,18: TunedException is not callable (not-callable) E: 45,11: Undefined variable name 'GTKPluginLoader' in __all__ (undefined-all-variable) ************* Module tuned.gtk.managerException E: 44, 4: method already defined line 41 (function-redefined) ************* Module tuned.gtk.gui_profile_loader E:126, 4: method already defined line 95 (function-redefined) Signed-off-by: Ondřej Lysoněk --- tuned/gtk/gui_plugin_loader.py | 4 ++-- tuned/gtk/gui_profile_loader.py | 4 ---- tuned/gtk/managerException.py | 12 +++++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tuned/gtk/gui_plugin_loader.py b/tuned/gtk/gui_plugin_loader.py index 2b3e93b..67fa195 100644 --- a/tuned/gtk/gui_plugin_loader.py +++ b/tuned/gtk/gui_plugin_loader.py @@ -33,7 +33,7 @@ import tuned.consts as consts import tuned.logs import tuned.plugins.repository as repository import configobj as ConfigObj -import tuned.exceptions as TunedException +from tuned.exceptions import TunedException from tuned import plugins from tuned.utils.plugin_loader import PluginLoader @@ -42,7 +42,7 @@ from tuned import storage, units, monitors, plugins, profiles, exports, \ import tuned.plugins as Plugins -__all__ = ['GTKPluginLoader'] +__all__ = ['GuiPluginLoader'] global_config_spec = ['dynamic_tuning = boolean(default=%s)' % consts.CFG_DEF_DYNAMIC_TUNING, diff --git a/tuned/gtk/gui_profile_loader.py b/tuned/gtk/gui_profile_loader.py index 47b2da6..10bd7cd 100644 --- a/tuned/gtk/gui_profile_loader.py +++ b/tuned/gtk/gui_profile_loader.py @@ -123,10 +123,6 @@ class GuiProfileLoader(object): config.write() self._refresh_profiles() - def _refresh_profiles(self): - self.profiles = {} - self._load_all_profiles() - def update_profile( self, old_profile_name, diff --git a/tuned/gtk/managerException.py b/tuned/gtk/managerException.py index 9589b52..958a346 100644 --- a/tuned/gtk/managerException.py +++ b/tuned/gtk/managerException.py @@ -38,10 +38,8 @@ class ManagerException(Exception): return repr(self.code) - def profile_already_exists(self, text): - return repr(text) - - def profile_already_exists(self): - return repr(self.code) - - + def profile_already_exists(self, text=None): + if text is None: + return repr(self.code) + else: + return repr(text)