(self, url, filename, cache_mode)
return True
Get a file and check its size. Optionally enable other
        capabilities such as caching to check if the
        file already exists locally and whether its size is the
        same to avoid downloaded it again.
Get a file and check its size. Optionally enable other
        capabilities such as caching to check if the
        file already exists locally and whether its size is the
        same to avoid downloaded it again.
Get a file and check its size . Optionally enable other capabilities such as caching to check if the file already exists locally and whether its size is the same to avoid downloaded it again .
def _get_file(self, url, filename, cache_mode):
        """Get a file and check its size. Optionally enable other
        capabilities such as caching to check if the
        file already exists locally and whether its size is the
        same to avoid downloaded it again.
        """
        match = re.search("/([^/:]+):(\\S+)$", filename)
        if match:
            layer_f_chksum = ChkSUM().hash(filename, match.group(1))
            if layer_f_chksum == match.group(2):
                return True             # is cached skip download
            cache_mode = 0
        if self.curl.cache_support and cache_mode:
            if cache_mode == 1:
                (hdr, dummy) = self._get_url(url, nobody=1)
            elif cache_mode == 3:
                (hdr, dummy) = self._get_url(url, sizeonly=True)
            remote_size = self.curl.get_content_length(hdr)
            if remote_size == FileUtil(filename).size():
                return True             # is cached skip download
        else:
            remote_size = -1
        resume = False
        if filename.endswith("layer"):
            resume = True
        (hdr, dummy) = self._get_url(url, ofile=filename, resume=resume)
        if self.curl.get_status_code(hdr.data["X-ND-HTTPSTATUS"]) != 200:
            return False
        if remote_size == -1:
            remote_size = self.curl.get_content_length(hdr)
        if (remote_size != FileUtil(filename).size() and
                hdr.data["X-ND-CURLSTATUS"]):
            Msg().err("Error: file size mismatch:", filename,
                      remote_size, FileUtil(filename).size())
            return False
        return True
def _get_file ( self , url , filename , cache_mode ) : match = re . search ( "/([^/:]+):(\\S+)$" , filename ) if match : layer_f_chksum = ChkSUM ( ) . hash ( filename , match . group ( 1 ) ) if layer_f_chksum == match . group ( 2 ) : return True # is cached skip download cache_mode = 0 if self . curl . cache_support and cache_mode : if cache_mode == 1 : ( hdr , dummy ) = self . _get_url ( url , nobody = 1 ) elif cache_mode == 3 : ( hdr , dummy ) = self . _get_url ( url , sizeonly = True ) remote_size = self . curl . get_content_length ( hdr ) if remote_size == FileUtil ( filename ) . size ( ) : return True # is cached skip download else : remote_size = - 1 resume = False if filename . endswith ( "layer" ) : resume = True ( hdr , dummy ) = self . _get_url ( url , ofile = filename , resume = resume ) if self . curl . get_status_code ( hdr . data [ "X-ND-HTTPSTATUS" ] ) != 200 : return False if remote_size == - 1 : remote_size = self . curl . get_content_length ( hdr ) if ( remote_size != FileUtil ( filename ) . size ( ) and hdr . data [ "X-ND-CURLSTATUS" ] ) : Msg ( ) . err ( "Error: file size mismatch:" , filename , remote_size , FileUtil ( filename ) . size ( ) ) return False return True