Commits

Anonymous committed 4a4b827

added preliminary (untested) proxy support

Comments (0)

Files changed (1)

eodsfetch/eodsfetch.py

 	parser.add_option( "-p", "--password", default="pa55word", dest="password", help="Password" )
 	parser.add_option( "-l", "--log-level", dest="log_level", default="info", help="level should be DEBUG, INFO, WARNING, ERROR" )
 	parser.add_option( "-c", "--retrieve-command", default="newhires/ReviewQueuedExport.do", help="Web site path to retrieval command (relative to url)" )
+	parser.add_option( "-r", "--proxy-server", help="Optional proxy server and port (server:port)" )
 	parser.add_option( "-s", "--save-file", help="filename to save data" )
 	return parser.parse_args()
 
 	log = logging.getLogger( 'eodsfetch' )
 	logging.basicConfig( level = getattr( logging, options.log_level.upper() ) )
 
+def installOpener():
+	handlers = [ urllib2.HTTPCookieProcessor ]
+	if options.proxy_server:
+		handlers.append( urllib2.ProxyHandler( { 'http': options.proxy_server } ) )
+	opener = urllib2.build_opener( handlers )
+	urllib2.install_opener( opener )
+
 def getLoginPage():
-	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor)
-	urllib2.install_opener( opener )
 	log.info( 'Retrieving %s for login', options.url )
 	login_page = urllib2.urlopen( options.url )
 	try:
 	global options
 	options, args = getArgs()
 	setupLogging()
+	installOpener()
 	login_form = getLoginPage()
 	submitLoginPage( login_form )
 	runRetrievalCommand()