コード例 #1
0
ファイル: deps.py プロジェクト: zhumj1231/SalviaRenderer
    def __distribute(self, dl_info):
        assert isinstance(dl_info, download_info)
        
        util.report_info("Verifying <%s> ..." % dl_info.res_path)

        # Verify distribute source
        if not os.path.isfile(dl_info.store_path):
            util.report_error("File <%s> is not existed. Please check your network state and re-run build script." % dl_info.res_path)

        if fhash.hash_file(dl_info.store_path) != dl_info.tag:
            util.report_error("File <%s> verificaition is failed. Please check your network state and re-run build script." % dl_info.res_path)

        util.report_info("Distributing <%s> ..." % dl_info.res_path)

        # Clean target if file is existed.
        if dl_info.res_type in [RAW_FILE, COMPRESSED_FILE]:
            if os.path.isfile(dl_info.dist_path):
                os.remove(dl_info.dist_path)
        elif dl_info.res_type in [COMPRESSED_FOLDER]:
            if os.path.isdir(dl_info.dist_path):
                shutil.rmtree(dl_info.dist_path)

        dist_parent = os.path.dirname(dl_info.dist_path)
        if dl_info.res_type in [COMPRESSED_FILE, COMPRESSED_FOLDER]:
            self.__decompress(dl_info.store_path, dist_parent)
        else:
            shutil.copy(dl_info.store_path, dist_parent)
コード例 #2
0
ファイル: deps.py プロジェクト: zhumj1231/SalviaRenderer
def download_file(url, file_path):
    if os.path.isfile(file_path):
        os.remove(file_path)

    if url.startswith("http://") or url.startswith("https://"):
        u = urllib2.urlopen(url)
        meta = u.info()
        file_size = int(meta.getheaders("Content-Length")[0])
    else:
        file_size = os.path.getsize(url)
        u = open(url, "rb")
        
    try:
        file_dir = os.path.dirname(file_path)
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)

        with open(file_path, 'wb') as f:
            f = open(file_path, 'wb')
            util.report_info( "Downloading: %s Bytes: %s" % (file_path, file_size) )
            file_size_dl = 0
            block_sz = 32 * 1024
            while True:
                buffer = u.read(block_sz)
                if not buffer: break
                file_size_dl += len(buffer)
                f.write(buffer)
                status = r"%7d KB  [%3.1f%%]" % (file_size_dl / 1024, file_size_dl * 100. / file_size)
                status = status + chr(8)*(len(status)+1)
                print status,
    except:
        if os.path.exists(file_path):
            os.remove(file_path)
        raise
コード例 #3
0
ファイル: deps.py プロジェクト: zhumj1231/SalviaRenderer
 def __download(self, dl_info):
     assert isinstance(dl_info, download_info)
     util.report_info("Downloading <%s> ..." % dl_info.res_path)
     download_file(dl_info.res_url, dl_info.store_path)