v0.11 - added quick_networking_check(), to confirm that we can talk to https://developer.symbian.org
authorWilliam Roberts <williamr@symbian.org>
Mon, 01 Mar 2010 17:46:44 +0000
changeset 175 5ebd70511e4c
parent 174 4c0108e0b6dd
child 176 266a7e9b9237
v0.11 - added quick_networking_check(), to confirm that we can talk to https://developer.symbian.org
downloadkit/downloadkit.py
--- a/downloadkit/downloadkit.py	Fri Feb 26 16:59:59 2010 +0000
+++ b/downloadkit/downloadkit.py	Mon Mar 01 17:46:44 2010 +0000
@@ -12,6 +12,7 @@
 # Description:
 # Script to download and unpack a Symbian PDK - assumes "7z" installed to unzip the files
 
+import socket
 import urllib2
 import urllib
 import os.path
@@ -25,7 +26,7 @@
 import hashlib
 import xml.etree.ElementTree as ET 
 
-version = '0.10'
+version = '0.11'
 user_agent = 'downloadkit.py script v' + version
 headers = { 'User-Agent' : user_agent }
 top_level_url = "http://developer.symbian.org"
@@ -60,6 +61,31 @@
 urlopen = urllib2.urlopen
 Request = urllib2.Request
 
+def quick_networking_check():
+	global options
+	defaulttimeout = socket.getdefaulttimeout()
+	socket.setdefaulttimeout(15)
+	probesite = 'https://developer.symbian.org'
+	probeurl = probesite + '/main/user_profile/login.php'
+	headers = { 'User-Agent' : user_agent }
+
+	req = urllib2.Request(probeurl, None, headers)
+
+	try:
+		response = urllib2.urlopen(req)
+		doc=response.read()
+	except urllib2.URLError, e:
+		print '*** Problem accessing ' + probesite
+		if hasattr(e, 'reason'):
+			print '*** Reason: ', e.reason
+		elif hasattr(e, 'code'):
+			print '*** Error code: ', e.code
+		print "Do you need to use a proxy server to access the developer.symbian.org website?"
+		sys.exit(1)
+	socket.setdefaulttimeout(defaulttimeout)	# restore the default timeout
+	if options.progress:
+		print "Confirmed that we can access " + probesite
+
 def login(prompt):
 	global options
 	loginurl = 'https://developer.symbian.org/main/user_profile/login.php'
@@ -425,6 +451,7 @@
 opener = build_opener(options.debug)
 urllib2.install_opener(opener)
 
+quick_networking_check()
 login(True)
 downloadkit(args[0])