downloadkit/downloadkit.py
changeset 175 5ebd70511e4c
parent 172 5f1dcce7f6d4
child 194 f74ba2451a44
equal deleted inserted replaced
174:4c0108e0b6dd 175:5ebd70511e4c
    10 # Symbian Foundation - Initial contribution
    10 # Symbian Foundation - Initial contribution
    11 # 
    11 # 
    12 # Description:
    12 # Description:
    13 # Script to download and unpack a Symbian PDK - assumes "7z" installed to unzip the files
    13 # Script to download and unpack a Symbian PDK - assumes "7z" installed to unzip the files
    14 
    14 
       
    15 import socket
    15 import urllib2
    16 import urllib2
    16 import urllib
    17 import urllib
    17 import os.path
    18 import os.path
    18 import cookielib
    19 import cookielib
    19 import sys
    20 import sys
    23 from BeautifulSoup import BeautifulSoup
    24 from BeautifulSoup import BeautifulSoup
    24 from optparse import OptionParser
    25 from optparse import OptionParser
    25 import hashlib
    26 import hashlib
    26 import xml.etree.ElementTree as ET 
    27 import xml.etree.ElementTree as ET 
    27 
    28 
    28 version = '0.10'
    29 version = '0.11'
    29 user_agent = 'downloadkit.py script v' + version
    30 user_agent = 'downloadkit.py script v' + version
    30 headers = { 'User-Agent' : user_agent }
    31 headers = { 'User-Agent' : user_agent }
    31 top_level_url = "http://developer.symbian.org"
    32 top_level_url = "http://developer.symbian.org"
    32 download_list = []
    33 download_list = []
    33 unzip_list = []
    34 unzip_list = []
    57 
    58 
    58     return opener
    59     return opener
    59 
    60 
    60 urlopen = urllib2.urlopen
    61 urlopen = urllib2.urlopen
    61 Request = urllib2.Request
    62 Request = urllib2.Request
       
    63 
       
    64 def quick_networking_check():
       
    65 	global options
       
    66 	defaulttimeout = socket.getdefaulttimeout()
       
    67 	socket.setdefaulttimeout(15)
       
    68 	probesite = 'https://developer.symbian.org'
       
    69 	probeurl = probesite + '/main/user_profile/login.php'
       
    70 	headers = { 'User-Agent' : user_agent }
       
    71 
       
    72 	req = urllib2.Request(probeurl, None, headers)
       
    73 
       
    74 	try:
       
    75 		response = urllib2.urlopen(req)
       
    76 		doc=response.read()
       
    77 	except urllib2.URLError, e:
       
    78 		print '*** Problem accessing ' + probesite
       
    79 		if hasattr(e, 'reason'):
       
    80 			print '*** Reason: ', e.reason
       
    81 		elif hasattr(e, 'code'):
       
    82 			print '*** Error code: ', e.code
       
    83 		print "Do you need to use a proxy server to access the developer.symbian.org website?"
       
    84 		sys.exit(1)
       
    85 	socket.setdefaulttimeout(defaulttimeout)	# restore the default timeout
       
    86 	if options.progress:
       
    87 		print "Confirmed that we can access " + probesite
    62 
    88 
    63 def login(prompt):
    89 def login(prompt):
    64 	global options
    90 	global options
    65 	loginurl = 'https://developer.symbian.org/main/user_profile/login.php'
    91 	loginurl = 'https://developer.symbian.org/main/user_profile/login.php'
    66 	
    92 	
   423 	parser.error("Unable to execute 7z command")
   449 	parser.error("Unable to execute 7z command")
   424 
   450 
   425 opener = build_opener(options.debug)
   451 opener = build_opener(options.debug)
   426 urllib2.install_opener(opener)
   452 urllib2.install_opener(opener)
   427 
   453 
       
   454 quick_networking_check()
   428 login(True)
   455 login(True)
   429 downloadkit(args[0])
   456 downloadkit(args[0])
   430 
   457 
   431 if options.dryrun:
   458 if options.dryrun:
   432 	print "# instructions for downloading kit " + args[0]
   459 	print "# instructions for downloading kit " + args[0]