Commit 38d6770b authored by Seblu's avatar Seblu
Browse files

add timeout to uopen

parent bdb3b4af
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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