1
0
Fork 0

Fix problem with tuned-adm list command on python2

Unfortunately non-required subcommands are not supported by argparse
module on python2, so selection between plugins and profiles must be
done by new positional non-required arguments "profiles" and
"plugins"

Examples of usage:
$ tuned-adm list -- will list tuned profiles like before
$ tuned-adm list profiles -- new command which has the same function
as tuned-adm list
$ tuned-adm list plugins -- will list tuned accessible plugins
$ tuned-adm list plugins [-v|--verbose] -- will list tuned accessible
plugins + their configuration options and hints how to use them

Signed-off-by: Tomas Korbar <tkorbar@redhat.com>
This commit is contained in:
Tomas Korbar 2019-03-06 16:23:05 +01:00
parent a0f3bb3bb0
commit c0a2e1964a
2 changed files with 33 additions and 11 deletions

View file

@ -63,17 +63,11 @@ if __name__ == "__main__":
subparsers = parser.add_subparsers()
parser_list = subparsers.add_parser("list", help="list available profiles or plugins")
parser_list.set_defaults(action="list_profiles")
parser_list = subparsers.add_parser("list", help="list available profiles or plugins (by default profiles)")
parser_list.set_defaults(action="list")
subparsers_list = parser_list.add_subparsers()
parser_list_plugins = subparsers_list.add_parser("plugins", help="list avaible plugins")
parser_list_plugins.set_defaults(action="list_plugins")
parser_list_plugins.add_argument("--verbose", "-v", action="store_true", help="show plugin's configuration parameters and their meaning")
parser_list_profiles = subparsers_list.add_parser("profiles", help="list available profiles")
parser_list_profiles.set_defaults(action="list_profiles")
parser_list.add_argument("list_choice", nargs="?",default="profiles", choices=["plugins","profiles"], help="choose what to list", metavar="{plugins|profiles}")
parser_list.add_argument("--verbose", "-v", action="store_true", help="show plugin's configuration parameters and their meaning")
parser_active = subparsers.add_parser("active", help="show active profile")
parser_active.set_defaults(action="active")

View file

@ -281,7 +281,7 @@ class Admin(object):
def _action_profile(self, profiles):
if len(profiles) == 0:
return self._action_list()
return self._action_list_profiles()
profile_name = " ".join(profiles)
if profile_name == "":
return False
@ -350,6 +350,34 @@ class Admin(object):
print("Not supported in no_daemon mode.")
return False
def _action_dbus_list(self, list_choice="profiles", verbose=False):
"""Print accessible profiles or plugins got from tuned dbus api
Keyword arguments:
list_choice -- argument from command line deciding what will be listed
verbose -- if True then list plugin's config options and their hints
if possible. Functional only with plugin listing, with profiles
this argument is omitted
"""
if list_choice == "profiles":
return self._action_dbus_list_profiles()
elif list_choice == "plugins":
return self._action_dbus_list_plugins(verbose=verbose)
def _action_list(self, list_choice="profiles", verbose=False):
"""Print accessible profiles or plugins with no daemon mode
Keyword arguments:
list_choice -- argument from command line deciding what will be listed
verbose -- Plugins cannot be listed in this mode, so verbose argument
is here only because argparse module always supplies verbose
option and if verbose was not here it would result in error
"""
if list_choice == "profiles":
return self._action_list_profiles()
elif list_choice == "plugins":
return self._action_list_plugins(verbose=verbose)
def _action_dbus_list_plugins(self, verbose=False):
"""Print accessible plugins