diff --git a/bin/is b/bin/is index 88b31892ff93ed173e0a252eee9a4450bb9e43f6..92a03a276f804d1ade7c1144334e8510b123bcf6 100755 --- a/bin/is +++ b/bin/is @@ -15,6 +15,7 @@ import fnmatch import warnings import argparse import psutil +import socket import installsystems import installsystems.printer import installsystems.tools as istools @@ -39,7 +40,7 @@ def load_repositories(args): # split filter in list args.repo_filter = Repository.split_repository_list(args.repo_filter) # init repo cache object - repoman = RepositoryManager(args.cache, timeout=args.timeout, + repoman = RepositoryManager(args.cache, timeout=args.repo_timeout or args.timeout, filter=args.repo_filter, search=args.repo_search) # register repositories (order matter) # load repo configs from command line @@ -417,17 +418,19 @@ def arg_parser_init(): help="filter repositories by name") parser.add_argument("-r", "--repo-path", default="", metavar="PATH", help="define a temporary repository") + parser.add_argument("-T", "--repo-timeout", type=int, default=None, + metavar="SECONDS", help="repository access timeout") parser.add_argument("-C", "--cache", default="", metavar="PATH", help="path of repositories cache") - parser.add_argument("-t", "--timeout", dest="timeout", type=int, default=3, - metavar="SECONDS", help="download timeout (default 3)") + parser.add_argument("-t", "--timeout", dest="timeout", type=int, default=None, + metavar="SECONDS", help="socket timeout") parser.add_argument("--no-cache", action="store_true", help="not use persistent database caching") parser.add_argument("--no-sync", action="store_true", 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, + parser.add_argument("--nice", type=int, default=None, help="nice of the process") parser.add_argument("--ionice-class", choices=["none","rt", "be","idle"], help="ionice class of the process (default: none)") @@ -672,7 +675,9 @@ def main(): if options.nice is not None or options.ionice_class is not None: proc = psutil.Process(os.getpid()) if options.nice is not None: - try: proc.nice = options.nice + try: + proc.nice = options.nice + debug("Setting nice to %d" % options.nice) except Exception: warn("Unable to nice process to %s" % options.nice) if options.ionice_class is not None: @@ -683,8 +688,14 @@ def main(): "be": psutil.IOPRIO_CLASS_BE, "idle": psutil.IOPRIO_CLASS_IDLE} proc.set_ionice(ioclassmap[options.ionice_class], options.ionice_level) + debug("Setting ionice to class %s, level %s" % + (options.ionice_class, options.ionice_level)) except Exception: warn("Unable to ionice process to %s" % options.ionice_class) + # set timeout option + if options.timeout is not None: + socket.setdefaulttimeout(options.timeout) + debug("Global timeout setted to %ds" % options.timeout) # except for install command we parse all args! # install command is responsible of parsing if options.func is not c_install: diff --git a/installsystems/config.py b/installsystems/config.py index 0babb4cc115307b36c50dab71c286142e8134a78..d6ef496238b852fb4671485168bbc707f58d15b6 100644 --- a/installsystems/config.py +++ b/installsystems/config.py @@ -61,6 +61,7 @@ class MainConfigFile(ConfigFile): "repo_search": str, "repo_filter": str, "repo_config": str, + "repo_timeout": int, "nice": int, "ionice_class": ["none", "rt", "be", "idle"], "ionice_level": int diff --git a/installsystems/repository.py b/installsystems/repository.py index eb065350ac22048286098d0cbdd3c80a4e064006..f9731d7385774c1878e814476a068cc0f111b4df 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -487,14 +487,16 @@ class RepositoryManager(object): Manage multiple repostories This call implement a cache and a manager for multiple repositories + Default repository timeout is 3 ''' def __init__(self, cache_path=None, timeout=None, filter=None, search=None): - self.timeout = 3 if timeout is None else timeout self.repos = [] self.tempfiles = [] self.filter = [] if filter is None else filter self.search = [] if search is None else search + self.timeout = timeout or 3 + debug("Repostiory timeout setted to %ds" % self.timeout) if cache_path is None: self.cache_path = None debug("No repository cache") diff --git a/installsystems/tools.py b/installsystems/tools.py index eac45a7b82767edbb9fa4fa6381c19bbc38a7d4e..ca38d61887ae6ed15bbb77ee340171e62b2ae124 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -6,13 +6,14 @@ InstallSystems Generic Tools Library ''' +import hashlib +import math import os import re -import hashlib import shutil -import urllib2 +import socket import time -import math +import urllib2 from subprocess import call, check_call, CalledProcessError @@ -59,17 +60,17 @@ class PipeFile(object): return self.format % (scaled, self.prefixes[power], self.unit) - def __init__(self, path=None, mode="r", fileobj=None, timeout=3, + def __init__(self, path=None, mode="r", fileobj=None, timeout=None, progressbar=False): - self.open(path, mode, fileobj, timeout, progressbar=progressbar) + self.open(path, mode, fileobj, timeout, progressbar) - def open(self, path=None, mode="r", fileobj=None, timeout=3, progressbar=False): + def open(self, path=None, mode="r", fileobj=None, timeout=None, progressbar=False): if path is None and fileobj is None: raise AttributeError("You must have a path or a fileobj to open") if mode not in ("r", "w"): raise AttributeError("Invalid open mode. Must be r or w") + self.timeout = timeout or socket.getdefaulttimeout() self.mode = mode - self.timeout = timeout self._md5 = hashlib.md5() self.size = 0 self.mtime = None @@ -172,8 +173,7 @@ class PipeFile(object): self._ssh.load_system_host_keys() self._ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self._ssh.connect(host, port=port, username=login, password=passwd, - look_for_keys=True, - timeout=int(self.timeout)) + look_for_keys=True, timeout=self.timeout) # swith in sftp mode sftp = self._ssh.open_sftp() # get the file infos diff --git a/samples/installsystems.conf b/samples/installsystems.conf index f2cd34d6abebc2a2bf2768c9a2343aa557908a4f..4ed2f6b143bea7c6da7fb4649b830e1f7b3949a5 100644 --- a/samples/installsystems.conf +++ b/samples/installsystems.conf @@ -26,7 +26,7 @@ # disable check of script during build #no_check = 1 -# define connection timeout +# global connection timeout #timeout = 30 # search images inside repositories @@ -37,3 +37,6 @@ # custom repository config file #repo_config = + +# repository loading timeout +#repo_timeout = 1