我想从铬.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详细说明了问题和解决方法。您可以选择使用其中一种解决方法,或者更新到python2.6.5或2.7b2。在
其中一个解决方法建议从固定的Python复制patched zipfile.py module。在
祝你好运!在
这似乎对我有用:
这是另一个剪切-这是相同的技术,但它遍历结果以证明它是有效的。在
我运行它时得到的输出是
^{pr2}$相关问题 更多 >
编程相关推荐