Commit 74081e11 authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

rewrite timeout code

Before this, timeout only apply to repository caching.

Now timeout is used by all transfert functions.
A new parameter repo_timeout is available to set a custom timeout on repository
parent f22badbf
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -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:
+1 −0
Original line number Diff line number Diff line
@@ -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
+3 −1
Original line number Diff line number Diff line
@@ -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")
+9 −9
Original line number Diff line number Diff line
@@ -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
+4 −1
Original line number Diff line number Diff line
@@ -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