Skip to content
Snippets Groups Projects
Commit 28506fc6 authored by Seblu's avatar Seblu
Browse files

Add timeout paramter to isinstall

parent f562ee94
No related branches found
No related tags found
No related merge requests found
...@@ -37,7 +37,9 @@ p_main.add_argument('-q', "--quiet", action="store_false", dest="verbose", defau ...@@ -37,7 +37,9 @@ p_main.add_argument('-q', "--quiet", action="store_false", dest="verbose", defau
p_main.add_argument("-c", "--config", dest="config", type=str, default=None, p_main.add_argument("-c", "--config", dest="config", type=str, default=None,
help="config file path") help="config file path")
p_main.add_argument("-v", "--image-version", dest="image_version", type=int, default=None, p_main.add_argument("-v", "--image-version", dest="image_version", type=int, default=None,
help="specific image version") help="image version")
p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=3,
help="download timeout")
p_main.add_argument("image_name", type=str, p_main.add_argument("image_name", type=str,
help="image to install (path or name)") help="image to install (path or name)")
try: try:
...@@ -51,7 +53,7 @@ try: ...@@ -51,7 +53,7 @@ try:
pkg = PackageImage(istools.abspath(args.image_name)) pkg = PackageImage(istools.abspath(args.image_name))
elif image_name_type == "name": elif image_name_type == "name":
# init repo cache object # init repo cache object
repocache = RepositoryCache(config.cache, verbose=args.verbose) repocache = RepositoryCache(config.cache, timeout=args.timeout, verbose=args.verbose)
# register repositories # register repositories
repocache.register(config.repos) repocache.register(config.repos)
# update remote info # update remote info
......
...@@ -176,8 +176,9 @@ class RepositoryConfig(object): ...@@ -176,8 +176,9 @@ class RepositoryConfig(object):
class RepositoryCache(object): class RepositoryCache(object):
'''Local repository cache class''' '''Local repository cache class'''
def __init__(self, cache_path, verbose=True): def __init__(self, cache_path, timeout=3, verbose=True):
self.verbose = verbose self.verbose = verbose
self.timeout = timeout
self.repos = {} self.repos = {}
self.path = os.path.abspath(cache_path) self.path = os.path.abspath(cache_path)
# ensure cache directories are avaiblable # ensure cache directories are avaiblable
...@@ -209,9 +210,9 @@ class RepositoryCache(object): ...@@ -209,9 +210,9 @@ class RepositoryCache(object):
# last local # last local
local_last = self.last(r) local_last = self.last(r)
# copy last file # copy last file
arrow("Copying %s repository last" % r, 2, self.verbose) arrow("Checking %s repository last" % r, 2, self.verbose)
istools.copy(self.repos[r]["orig"].last_path, istools.copy(self.repos[r]["orig"].last_path,
self.repos[r]["cache"].last_path,) self.repos[r]["cache"].last_path, timeout=self.timeout)
# last after update # last after update
remote_last = self.last(r) remote_last = self.last(r)
debug("%s: last: local: %s, remote:%s" % (r, local_last, remote_last)) debug("%s: last: local: %s, remote:%s" % (r, local_last, remote_last))
...@@ -221,8 +222,7 @@ class RepositoryCache(object): ...@@ -221,8 +222,7 @@ class RepositoryCache(object):
if remote_last > local_last or not os.path.exists(local_db): if remote_last > local_last or not os.path.exists(local_db):
# copy db file # copy db file
arrow("Copying %s repository db" % r, 2, self.verbose) arrow("Copying %s repository db" % r, 2, self.verbose)
istools.copy(remote_db, local_db) istools.copy(remote_db, local_db, timeout=self.timeout)
arrow("%s updated" % r, 2, self.verbose)
def last(self, reponame): def last(self, reponame):
'''Return the last timestamp of a repo''' '''Return the last timestamp of a repo'''
...@@ -244,7 +244,7 @@ class RepositoryCache(object): ...@@ -244,7 +244,7 @@ class RepositoryCache(object):
# get remote image # get remote image
remotepath = os.path.join(self.repos[reponame]["orig"].config.image, filename) remotepath = os.path.join(self.repos[reponame]["orig"].config.image, filename)
arrow("Copying from repository", 2, self.verbose) arrow("Copying from repository", 2, self.verbose)
istools.copy(remotepath, cachepath) istools.copy(remotepath, cachepath, timeout=self.timeout)
return cachepath return cachepath
def find_image(self, name, version): def find_image(self, name, version):
......
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