Anonymous committed 1bdd1a3

Refactored functionality for clarity.

Comments (0)

Files changed (1)


+#!/usr/bin/env python
+# $ Id: $
 import urllib2, sys
 from ClientForm import ParseResponse
 from optparse import OptionParser
 	log = logging.getLogger( 'eodsfetch' )
 	logging.basicConfig( level = getattr( logging, options.log_level.upper() ) )
-def main():
-	global options
-	options, args = getArgs()
-	setupLogging()
+def getLoginPage():
 	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor)
 	urllib2.install_opener( opener ) 'Retrieving %s for login', options.url )
 	except IndexError:
 		log.exception( 'Did not find any forms on the login page (%s)', options.url ) "Check for <br/> elements, which don't follow the spec (use <br />)." )
+		sys.exit(1)
 	log.debug( 'login form follows' )
 	log.debug( str( login_form ) )
+	return login_form
+def submitLoginPage( login_form ):
 	login_form['userName'] = options.username
 	login_form['password'] = options.password
 	log.debug( 'Submitting login form' )
 	# consider checking the response above for some confirmation value (string "Main Menu" ?)
+def runRetrievalCommand():
 	command = urljoin( options.url, options.retrieve_command ) 'Assuming login was successful, retrieving %s', command )
 	result = urllib2.urlopen( command ).read()
 		output = sys.stdout
 	output.write( result )
+def main():
+	global options
+	options, args = getArgs()
+	setupLogging()
+	login_form = getLoginPage()
+	submitLoginPage( login_form )
+	runRetrievalCommand()
 if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.