gpt4 book ai didi

python - 使用 ZipFile 从 Python 中的 zip 文件中提取 .app

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:30 26 4
gpt4 key购买 nike

我正在尝试从他们的快照中提取 Chromium.app 的新修订版,我可以很好地下载该文件,但是在提取它时,ZipFile 要么将其中的 chrome-mac 文件夹提取为一个文件,说目录不存在等。我是 python 的新手,所以这些错误对我来说意义不大。这是我目前所拥有的。

import urllib2
response = urllib2.urlopen('http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/LATEST')
latestRev = response.read()
print latestRev

# we have the revision, now we need to download the zip and extract it
latestZip = urllib2.urlopen('http://build.chromium.org/buildbot/snapshots/chromium-rel-mac/%i/chrome-mac.zip' % (int(latestRev)), '~/Desktop/ChromiumUpdate/%i-update' % (int(latestRev)))
#declare some vars that hold paths n shit
workingDir = '/Users/slehan/Desktop/ChromiumUpdate/'
chromiumZipPath = '%s%i-update.zip' % (workingDir, (int(latestRev)))
chromiumAppPath = 'chrome-mac/' #the path of the chromium executable within the zip file
chromiumAppExtracted = '%s/Chromium.app' % (workingDir) # path of the extracted executable

output = open(chromiumZipPath, 'w') #delete any current file there
output.write(latestZip.read())
output.close()

# we have the .zip now we need to extract the Chromium.app file, it's in ziproot/chrome-mac/Chromium.app
import zipfile, os
zippedFile = open(chromiumZipPath)
zippedChromium = zipfile.ZipFile(zippedFile, 'r')
zippedChromium.extract(chromiumAppPath, workingDir)
#print zippedChromium.namelist()

zippedChromium.close()
#zippedChromium.close()

有什么想法吗?

最佳答案

看来你遇到了bug in Python .这other question详细说明问题和解决方法。您可以选择使用其中一种解决方法,或更新到 Python 2.6.5 或 2.7b2。

解决方法之一建议复制 patched zipfile.py module来自固定的 Python。

祝你好运!

关于python - 使用 ZipFile 从 Python 中的 zip 文件中提取 .app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2928373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com