downloadkit/downloadkit.py
changeset 276 c1b745b16f58
parent 274 3b8bce67b574
child 279 73890f073898
equal deleted inserted replaced
275:1b8ed3598305 276:c1b745b16f58
    24 from BeautifulSoup import BeautifulSoup
    24 from BeautifulSoup import BeautifulSoup
    25 from optparse import OptionParser
    25 from optparse import OptionParser
    26 import hashlib
    26 import hashlib
    27 import xml.etree.ElementTree as ET 
    27 import xml.etree.ElementTree as ET 
    28 
    28 
    29 version = '0.17'
    29 version = '0.18'
    30 user_agent = 'downloadkit.py script v' + version
    30 user_agent = 'downloadkit.py script v' + version
    31 headers = { 'User-Agent' : user_agent }
    31 headers = { 'User-Agent' : user_agent }
    32 top_level_url = "https://developer.symbian.org"
    32 top_level_url = "https://developer.symbian.org"
    33 passman = urllib2.HTTPPasswordMgrWithDefaultRealm()	# not relevant for live Symbian website
    33 passman = urllib2.HTTPPasswordMgrWithDefaultRealm()	# not relevant for live Symbian website
    34 download_list = []
    34 download_list = []
   310 	last_time = start_time
   310 	last_time = start_time
   311 	last_size = size
   311 	last_size = size
   312 	try:
   312 	try:
   313 		response = urllib2.urlopen(req)
   313 		response = urllib2.urlopen(req)
   314 		chunk = response.read(CHUNK)
   314 		chunk = response.read(CHUNK)
   315 		if chunk.find('<div id="sign_in_box">') != -1:
   315 		if chunk.find('<div class="signin">') != -1:
   316 			# our urllib2 cookies have gone awol - login again
   316 			# our urllib2 cookies have gone awol - login again
       
   317 			if options.debug:
       
   318 				print "Redirected to login page? login again.."
   317 			login(False)
   319 			login(False)
   318 			req = urllib2.Request(url, None, request_headers)
   320 			req = urllib2.Request(url, None, request_headers)
   319 			response = urllib2.urlopen(req)
   321 			response = urllib2.urlopen(req)
   320 			chunk = response.read(CHUNK)
   322 			chunk = response.read(CHUNK)
   321 			if chunk.find('<div id="sign_in_box">') != -1:
   323 			if chunk.find('<div class="signin">') != -1:
   322 				# still broken - give up on this one
   324 				# still broken - give up on this one
   323 				print "*** ERROR trying to download %s" % (filename)
   325 				print "*** ERROR trying to download %s" % (filename)
   324 				return False
   326 				return False
   325 		info = response.info()
   327 		info = response.info()
   326 		if 'Content-Length' in info:
   328 		if 'Content-Length' in info:
   405 		print "Info from final response of transfer:"
   407 		print "Info from final response of transfer:"
   406 		print response.info()
   408 		print response.info()
   407 
   409 
   408 	if filesize > 0 and size != filesize:
   410 	if filesize > 0 and size != filesize:
   409 		print "Incomplete transfer - only received %d bytes of the expected %d byte file" % (size, filesize)
   411 		print "Incomplete transfer - only received %d bytes of the expected %d byte file" % (size, filesize)
       
   412 		if options.debug:
       
   413 			print "Transfer delivered %d bytes in %s seconds" % (size-resume_start, now-start_time)
   410 		return False
   414 		return False
   411 	
   415 	
   412 	if options.progress:
   416 	if options.progress:
   413 		now = time.time()
   417 		now = time.time()
   414 		print "- Completed %s - %d Kb in %d seconds" % (filename, (filesize/1024)+0.5, now-start_time)
   418 		print "- Completed %s - %d Kb in %d seconds" % (filename, (filesize/1024)+0.5, now-start_time)