From dd32db4bdeaad94ed2b8b13d28f9a9f1d6cacd9e Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer Date: Fri, 10 Feb 2012 16:38:15 +0100 Subject: [PATCH] add global --nice and --ionice options this options are also settable by config allow to have installsystems niced before launch action python-psutil minimun version is 0.2.1 to support set_ionice --- bin/is | 22 ++++++++++++++++++++++ completion/bash/is | 3 ++- debian/control | 2 +- installsystems/config.py | 2 ++ samples/installsystems.conf | 6 ++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bin/is b/bin/is index f71968a..1cf1e35 100755 --- a/bin/is +++ b/bin/is @@ -15,6 +15,7 @@ import fnmatch import warnings import argparse import json +import psutil import installsystems import installsystems.printer import installsystems.tools as istools @@ -479,6 +480,10 @@ def arg_parser_init(): help="doesn't sync repository database cache") parser.add_argument("--no-color", action="store_true", help="dot not display colored output") + parser.add_argument("--nice", type=int, default=0, + help="nice of the process") + parser.add_argument("--ionice", choices=["none","rt", "be","idle"], + help="ionice class of the process (default: none)") # create a subparser for commands subparser = parser.add_subparsers() # add command parser @@ -701,6 +706,23 @@ def main(): # no warning if we are not in debug mode if installsystems.verbosity < 2: warnings.filterwarnings("ignore") + # nice and ionice process + if options.nice is not None or options.ionice is not None: + proc = psutil.Process(os.getpid()) + if options.nice is not None: + try: proc.nice = options.nice + except Exception: + warn("Unable to nice process to %s" % options.nice) + if options.ionice is not None: + try: + ioclassmap = { + "none": psutil.IOPRIO_CLASS_NONE, + "rt": psutil.IOPRIO_CLASS_RT, + "be": psutil.IOPRIO_CLASS_BE, + "idle": psutil.IOPRIO_CLASS_IDLE} + proc.set_ionice(ioclassmap[options.ionice]) + except Exception: + warn("Unable to ionice process to %s" % options.ionice) # except for install command we parse all args! # install command is responsible of parsing if options.func is not c_install: diff --git a/completion/bash/is b/completion/bash/is index 6b3d27d..77143a5 100644 --- a/completion/bash/is +++ b/completion/bash/is @@ -53,6 +53,8 @@ _is() { '-c' '--config' '-C' '--cache' '-t' '--timeout' + '--nice' + '--ionice' '--no-cache' '--no-color' '--no-sync') @@ -131,7 +133,6 @@ _is() { _local_repo ;; install) - #[[ "$cur" == -* ]] && _opt '-b --best' && return 0 _count_args (( args == 2 )) && _image (( args > 2 )) && _filedir diff --git a/debian/control b/debian/control index 26cb37b..abd718b 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Standards-Version: 3.9.1 Package: installsystems Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, python-installsystems (>= ${source:Version}) +Depends: ${misc:Depends}, ${python:Depends}, python-installsystems (>= ${source:Version}), python-psutil (>= 0.2.1) XB-Python-Version: ${python:Versions} Description: InstallSytems Installer InstallSystems command line tool diff --git a/installsystems/config.py b/installsystems/config.py index 268f5b2..971576b 100644 --- a/installsystems/config.py +++ b/installsystems/config.py @@ -61,6 +61,8 @@ class MainConfigFile(ConfigFile): "repo_search": str, "repo_filter": str, "repo_config": str, + "nice": int, + "ionice": ["none", "rt", "be", "idle"] } def __init__(self, filename, prefix=os.path.basename(sys.argv[0])): self.prefix = prefix diff --git a/samples/installsystems.conf b/samples/installsystems.conf index cfc1bc3..8e8cd90 100644 --- a/samples/installsystems.conf +++ b/samples/installsystems.conf @@ -5,6 +5,12 @@ # Set verbosity (0: quiet, 1: normal, 2: debug) #verbosity = 2 +# Set nice process value +#nice = 0 + +# Set ionice class +#ionice = idle + # define a custom cache directory #cache = /tmp/sex -- GitLab