update.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:factotum 作者: Denubis 项目源码 文件源码
def updateFactorio():


    file_name = "/tmp/latestFactorio.tar.gz"
    print("Downloading %s" % file_name)

    r = requests.get(DOWNLOADURL, stream=True)
    total_length = int(r.headers.get('content-length'))

    if not os.path.isfile(file_name) or total_length != os.path.getsize(file_name):
        with open(file_name, 'wb') as f:
            for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): 
                if chunk:
                    f.write(chunk)
                    f.flush()
            #os.chmod(file_name, stat.S_IWUSR | stat.S_IRUSR)
    else:
        print("File already exists and file sizes match. Skipping download.")   

    if os.access(FACTORIOPATH, os.W_OK):
        if os.path.isfile(file_name):
            tar = tarfile.open(file_name, "r:gz")
            tar.extractall(path="/tmp")
            tar.close()

            copytree("/tmp/factorio", FACTORIOPATH)
            print("Success.")
        else:
            print("Help! Can't find %s, but I should have!" % (file_name))
            sys.exit(1)         
    else:
        print("Can't write to %s" % (FACTORIOPATH))
        sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号