我正在尝试从他们的快照中提取 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()
有任何想法吗?
看来你遇到过Python 中的错误 http://bugs.python.org/issue4710. This 其他问题 https://stackoverflow.com/questions/639962/unzipping-directory-structure-with-python详细说明问题和解决方法。您可以选择使用其中一种解决方法,或更新到 Python 2.6.5 或 2.7b2。
解决方法之一建议复制修补了 zipfile.py 模块 http://svn.python.org/projects/python/branches/release26-maint/Lib/zipfile.py来自固定的Python。
祝你好运!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)