मैं मूल रूप से सवाल के हिस्से के रूप में इस पोस्ट ... (कोई नौसिखिया stackoverflow पोस्टर कभी यह करता है;)
के बाद से उत्तर की एक बड़ी कमी थी। ये रहा:
मैं ऐसा करने के लिए निम्न अजगर स्क्रिप्ट के साथ आने के लिए सक्षम था, लेकिन किसी भी इनपुट = सराहना की जाएगी) (यह अजगर कोड में मेरा पहला वार है तो वहाँ एक बेहतर तरीका हो सकता है)
import os
import urllib2
import urllib
cmServerURL = 'http://<serverURL>:<port>/<path-to-cache.manifest>'
# download file code taken from stackoverflow
# http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python
def loadURL(url, dirToSave):
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(dirToSave, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100./file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
# download the cache.manifest file
# since this request doesn't include the Conent-Length header we will use a different api =P
urllib.urlretrieve (cmServerURL+ 'cache.manifest', './cache.manifest')
# open the cache.manifest and go through line-by-line checking for the existance of files
f = open('cache.manifest', 'r')
for line in f:
filepath = line.split('/')
if len(filepath) > 1:
fileName = line.strip()
# if the file doesn't exist, lets download it
if not os.path.exists(fileName):
print 'NOT FOUND: ' + line
dirName = os.path.dirname(fileName)
print 'checking dirctory: ' + dirName
if not os.path.exists(dirName):
os.makedirs(dirName)
else:
print 'directory exists'
print 'downloading file: ' + cmServerURL + line,
loadURL (cmServerURL+fileName, fileName)
आपके प्रश्न में "प्रश्नोत्तरी" की कमी है, लेकिन कोड पाइथन काम कर रहा है, हालांकि कुछ हिस्सों को सरल बनाया जा सकता है। इसके अलावा urlgrabber नामक पुस्तकालय भी हैं और अनुरोध जो फ़ाइल की बचत प्रक्रिया को आसान बना सकते हैं। –
प्रतिक्रिया के लिए धन्यवाद Mikko मैं आगे के विकास के लिए वर्णित पुस्तकालयों की जांच करूंगा। तो मूल रूप से, आप cache.manifest फ़ाइल के अंदर संसाधनों की सूची डाउनलोड करने के लिए लाइब्रेरी के बारे में नहीं जानते हैं। दुर्भाग्यवश, इस पोस्ट में सबसे अधिक महत्वपूर्ण कीवर्ड "cache.manifest" है जो स्पष्ट रूप से अभी तक किसी कीवर्ड के रूप में नहीं जोड़ा गया है। 1500 का स्कोर नहीं है मैं इसे जोड़ नहीं सकता। >। दुर्भाग्यवश यह प्रश्न उन लोगों द्वारा देखा जाएगा जो HTML5 "cache.manifest" में रूचि रखने वाले लोगों के बजाय "पायथन" टैग देख रहे हैं। – rockhowse
क्योंकि कैश मेनिफेस्ट को पार्सिंग और डाउनलोड करना पाइथन कोड की केवल 50 लाइनें हैं, मुझे नहीं लगता कि किसी को भी उस उद्देश्य के लिए एक विशिष्ट पुस्तकालय क्यों बनाना चाहिए :) –