downloadkit/downloadkit.py
changeset 126 c107e11c37e8
parent 125 b60a149520e7
child 127 e6bf005a5f58
equal deleted inserted replaced
125:b60a149520e7 126:c107e11c37e8
   111 		return topstatus
   111 		return topstatus
   112 	def run(self):
   112 	def run(self):
   113 		self.status = self.unzip(self.filename, self.levels, self.deletelevels)
   113 		self.status = self.unzip(self.filename, self.levels, self.deletelevels)
   114 
   114 
   115 def downloadkit(version):
   115 def downloadkit(version):
       
   116 	headers = { 'User-Agent' : user_agent }
   116 	urlbase = 'http://developer.symbian.org/main/tools_and_kits/downloads/'
   117 	urlbase = 'http://developer.symbian.org/main/tools_and_kits/downloads/'
   117 
   118 
   118 	viewid = 5   # default to Symbian^3
   119 	viewid = 5   # default to Symbian^3
   119 	if version[0] == 2:
   120 	if version[0] == 2:
   120 		viewid= 1  # Symbian^2
   121 		viewid= 1  # Symbian^2
   121 	if version[0] == 3:
   122 	if version[0] == 3:
   122 		viewid= 5  # Symbian^3
   123 		viewid= 5  # Symbian^3
   123 	url = urlbase + ('view.php?id=%d'% viewid) + 'vId=' + version
   124 	url = urlbase + ('view.php?id=%d'% viewid) + 'vId=' + version
   124 
   125 
   125 	req = urllib2.Request(url)
   126 	req = urllib2.Request(url, None, headers)
   126 	response = urllib2.urlopen(req)
   127 	response = urllib2.urlopen(req)
   127 	doc=response.read()
   128 	doc=response.read()
   128 	
   129 	
   129 	# BeatifulSoup chokes on some javascript, so we cut away everything before the <body>
   130 	# BeatifulSoup chokes on some javascript, so we cut away everything before the <body>
   130 	try:
   131 	try:
   141 	results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$"))
   142 	results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$"))
   142 	for result in results:
   143 	for result in results:
   143 		downloadurl = urlbase + result['href']
   144 		downloadurl = urlbase + result['href']
   144 		filename = result['title']
   145 		filename = result['title']
   145 		print 'Downloading ' + filename
   146 		print 'Downloading ' + filename
   146 		req = urllib2.Request(downloadurl)
   147 		req = urllib2.Request(downloadurl, None, headers)
   147 		
   148 		
   148 		try:
   149 		try:
   149 			response = urllib2.urlopen(req)
   150 			response = urllib2.urlopen(req)
   150 			CHUNK = 128 * 1024
   151 			CHUNK = 128 * 1024
   151 			first_chunk = True
   152 			first_chunk = True