downloadkit/downloadkit.py
changeset 207 a99c74c53f62
parent 199 90e6dc719131
child 300 3b8bce67b574
equal deleted inserted replaced
199:90e6dc719131 207:a99c74c53f62
    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.15'
    29 version = '0.16'
    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 = []
   378 	global headers
   378 	global headers
   379 	global options
   379 	global options
   380 	urlbase = top_level_url + '/main/tools_and_kits/downloads/'
   380 	urlbase = top_level_url + '/main/tools_and_kits/downloads/'
   381 
   381 
   382 	viewid = 5   # default to Symbian^3
   382 	viewid = 5   # default to Symbian^3
   383 	if version[0] == 2:
   383 	if version[0] == '2':
   384 		viewid= 1  # Symbian^2
   384 		viewid= 1  # Symbian^2
   385 	if version[0] == 3:
   385 	if version[0] == '3':
   386 		viewid= 5  # Symbian^3
   386 		viewid= 5  # Symbian^3
   387 	url = urlbase + ('view.php?id=%d'% viewid) + 'vId=' + version
   387 	url = urlbase + ('view.php?id=%d'% viewid)
       
   388 	if len(version) > 1:
       
   389 		# single character version means "give me the latest"
       
   390 		url = url + '&vId=' + version
   388 
   391 
   389 	req = urllib2.Request(url, None, headers)
   392 	req = urllib2.Request(url, None, headers)
   390 	response = urllib2.urlopen(req)
   393 	response = urllib2.urlopen(req)
   391 	doc=response.read()
   394 	doc=response.read()
   392 	
   395 	
   404 
   407 
   405 	soup=BeautifulSoup(doc)
   408 	soup=BeautifulSoup(doc)
   406 
   409 
   407 	# check that this is the right version
   410 	# check that this is the right version
   408 	match = re.search('Platform Release (\(Public\) )?v(\d\.\d\.[0-9a-z]+)', doc, re.IGNORECASE)
   411 	match = re.search('Platform Release (\(Public\) )?v(\d\.\d\.[0-9a-z]+)', doc, re.IGNORECASE)
   409 	if match and match.group(2) != version:
   412 	if not match:
   410 		print "*** ERROR: version %s is not available" % version
   413 		print "*** ERROR: no version information in the download page"
   411 		print "*** the website is offering version %s instead" % match.group(1)
       
   412 		return 0
   414 		return 0
       
   415 		
       
   416 	if len(version) > 1:
       
   417 		if match.group(2) != version:
       
   418 			print "*** ERROR: version %s is not available" % version
       
   419 			print "*** the website is offering version %s instead" % match.group(2)
       
   420 			return 0
       
   421 	else:
       
   422 		print "The latest version of Symbian^%s is PDK %s" % (version, match.group(2))
   413 		
   423 		
   414 	# let's hope the HTML format never changes...
   424 	# let's hope the HTML format never changes...
   415 	# <a href='download.php?id=27&cid=60&iid=270' title='src_oss_mw.zip'> ...</a> 
   425 	# <a href='download.php?id=27&cid=60&iid=270' title='src_oss_mw.zip'> ...</a> 
   416 	threadlist = []
   426 	threadlist = []
   417 	results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$"))
   427 	results=soup.findAll('a', href=re.compile("^download"), title=re.compile("\.(zip|xml)$"))
   486 	debug=False
   496 	debug=False
   487 	)
   497 	)
   488 
   498 
   489 (options, args) = parser.parse_args()
   499 (options, args) = parser.parse_args()
   490 if len(args) != 1:
   500 if len(args) != 1:
   491 	parser.error("Must supply a PDK version, e.g. 3.0.f")
   501 	parser.error("Must supply a PDK version, e.g. 3 or 3.0.h")
   492 if not check_unzip_environment() :
   502 if not check_unzip_environment() :
   493 	parser.error("Unable to execute 7z command")
   503 	parser.error("Unable to execute 7z command")
   494 
   504 
   495 top_level_url = "https://" + options.webhost
   505 top_level_url = "https://" + options.webhost
   496 opener = build_opener(options.debug)
   506 opener = build_opener(options.debug)