originalmente publicado esto como parte de la pregunta ... (cartel sin novato stackoverflow NUNCA hace esto;)
desde hubo una gran falta de respuestas. Aquí van:
pude llegar a la siguiente secuencia de comandos Python para hacerlo, pero cualquier contribución será apreciado =) (Este es mi primer intento de código Python por lo que podría ser una mejor manera)
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)
Hay una falta de "preguntas" en su pregunta, pero el código parece funcionar en Python, aunque algunas partes podrían simplificarse. También hay bibliotecas llamadas urlgrabber y solicitudes que podrían facilitar el proceso de guardar archivos. –
Gracias por los comentarios Mikko verificará las bibliotecas que mencionó para un mayor desarrollo. Entonces, básicamente, usted no sabe de una biblioteca para descargar la lista de recursos dentro de un archivo cache.manifest. Lamentablemente, la palabra clave que más importa en esta publicación es "cache.manifest", que evidentemente aún no se ha agregado como palabra clave. Al no tener un puntaje de 1500, no puedo agregarlo. >.
rockhowse
Como el análisis y la descarga del manifiesto de caché son solo 50 líneas de código Python, no veo por qué alguien debería crear una biblioteca de nicho solo para ese propósito :) –