Skip to content
Snippets Groups Projects
Commit dd32db4b authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

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
parent a265d7a6
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment