downloadkit/downloadkit.py
changeset 129 249ca6c587b6
parent 128 c63eca238256
child 139 7b2d146ef884
equal deleted inserted replaced
128:c63eca238256 129:249ca6c587b6
   110 				self.unzip(subzip, unziplevel-1, deletelevel-1)
   110 				self.unzip(subzip, unziplevel-1, deletelevel-1)
   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 orderResults(x,y) :
       
   116 	def ranking(name) :
       
   117 		# 1st = release_metadata, build_BOM.zip (both small things!)
       
   118 		if re.match(r"(build_BOM|release_metadata)", name):
       
   119 			return 1000;
       
   120 		# 2nd = tools, binaries (required for execution and compilation)
       
   121 		elif re.match(r"(binaries_|tools_)", name):
       
   122 			return 2000;
       
   123 		# 3rd = rnd binaries, binary patches
       
   124 		elif re.match(r"(bin_)", name):
       
   125 			return 3000;
       
   126 		# 4th = sources
       
   127 		elif re.match(r"(src_sfl|src_oss)", name):
       
   128 			return 4000;
       
   129 		# 5rd = rnd sources, source patches (not sure we'd ever have those)
       
   130 		elif re.match(r"(src_)", name):
       
   131 			return 5000;
       
   132 		# Last, anything else
       
   133 		return 10000;
       
   134 	xtitle = x['title']
       
   135 	ytitle = y['title']
       
   136 	return cmp(ranking(xtitle)+cmp(xtitle,ytitle), ranking(ytitle))
       
   137 
   115 def downloadkit(version):
   138 def downloadkit(version):
   116 	headers = { 'User-Agent' : user_agent }
   139 	headers = { 'User-Agent' : user_agent }
   117 	urlbase = 'http://developer.symbian.org/main/tools_and_kits/downloads/'
   140 	urlbase = 'http://developer.symbian.org/main/tools_and_kits/downloads/'
   118 
   141 
   119 	viewid = 5   # default to Symbian^3
   142 	viewid = 5   # default to Symbian^3
   138 	# let's hope the HTML format never changes...
   161 	# let's hope the HTML format never changes...
   139 	# <a href='download.php?id=27&cid=60&iid=270' title='src_oss_mw.zip'> ...</a> 
   162 	# <a href='download.php?id=27&cid=60&iid=270' title='src_oss_mw.zip'> ...</a> 
   140 
   163 
   141 	soup=BeautifulSoup(doc)
   164 	soup=BeautifulSoup(doc)
   142 	results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$"))
   165 	results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$"))
       
   166 	results.sort(orderResults)
   143 	for result in results:
   167 	for result in results:
   144 		downloadurl = urlbase + result['href']
   168 		downloadurl = urlbase + result['href']
   145 		filename = result['title']
   169 		filename = result['title']
   146 		print 'Downloading ' + filename
   170 		print 'Downloading ' + filename
   147 		req = urllib2.Request(downloadurl, None, headers)
   171 		req = urllib2.Request(downloadurl, None, headers)