From 38d6770ba25b11b80e3ebc64f995ac73b150ab17 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Mon, 29 Aug 2011 14:21:02 +0200 Subject: [PATCH] add timeout to uopen --- installsystems/repository.py | 5 +++-- installsystems/tools.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/installsystems/repository.py b/installsystems/repository.py index 2763c44..c570ea6 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -104,7 +104,7 @@ class Repository(object): ''' try: last_path = os.path.join(config.path, config.lastname) - return int(istools.uopen(last_path, "r").read().rstrip()) + return int(open(last_path, "r").read().rstrip()) except Exception as e: raise Exception("Read last file failed: %s" % e) return 0 @@ -425,7 +425,8 @@ class RepositoryManager(object): open(filedest, "wb") # get remote last value try: - rlast = int(istools.uopen(config.lastpath).read().strip()) + rlast = int(istools.uopen(config.lastpath, + timeout=self.timeout).read().strip()) # get local last value llast = int(os.stat(filedest).st_mtime) # if repo is out of date, download it diff --git a/installsystems/tools.py b/installsystems/tools.py index 1630dab..430b590 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -130,7 +130,7 @@ def abspath(path): else: return None -def uopen(path, mode="rb"): +def uopen(path, mode="rb", timeout=3): ''' Universal Open Create a file-like object to a file which can be remote @@ -139,7 +139,7 @@ def uopen(path, mode="rb"): if ftype == "file": return open(path, mode) elif ftype == "http" or ftype == "ftp": - return urllib2.urlopen(path) + return urllib2.urlopen(path, timeout=timeout) else: raise NotImplementedError -- GitLab