jaraco  committed 999fbba

Updated eodsfetch to be more user-friendly, including actually outputting log values. It now parses the second request relative to the original URL.

  • Participants
  • Parent commits e4d5289

Comments (0)

Files changed (2)

File eodsfetch/eodsfetch.bat

 rem   -l LOG_LEVEL, --log-level=LOG_LEVEL
 rem                         level should be DEBUG, INFO, WARNING, ERROR
 rem   -c RETRIEVE_COMMAND, --retrieve-command=RETRIEVE_COMMAND
-rem                         Web site path to retrieval command
+rem                         Web site path to retrieval command (relative to url)
 rem   -s SAVE_FILE, --save-file=SAVE_FILE
 rem                         filename to save data
 rem To retrieve data from the dev01 demonstration site, use the following command:
-rem eodsfetch.exe -u -n -p manager -c /newhires/ -s c:\EODS.xml
+rem eodsfetch.exe -u -n -p manager -c newhires/ -s c:\EODS.xml
 rem To review the data (without purging the records), use the "Review" command:
-rem eodsfetch.exe -u -n -p manager -c /newhires/ -s c:\EODS.xml
+rem eodsfetch.exe -u -n -p manager -c newhires/ -s c:\EODS.xml
 rem If you don't specify a file to save to, the XML will be output to the screen
-rem eodsfetch.exe -u -n -p manager -c /newhires/
+rem eodsfetch.exe -u -n -p manager -c newhires/

File eodsfetch/

 import urllib2, sys
 from ClientForm import ParseResponse
 from optparse import OptionParser
+from urlparse import urljoin
+import logging
 def getArgs( ):
 	parser = OptionParser()
 	parser.add_option( "-n", "--username", default="admin", dest="username", help="Username with export priveleges" )
 	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/", help="Web site path to retrieval command" )
+	parser.add_option( "-c", "--retrieve-command", default="newhires/", help="Web site path to retrieval command (relative to url)" )
 	parser.add_option( "-s", "--save-file", help="filename to save data" )
 	return parser.parse_args()
+def setupLogging():
+	global log
+	log = logging.getLogger( 'eodsfetch' )
+	logging.basicConfig( level = getattr( logging, options.log_level.upper() ) )
 def main():
 	global options
 	options, args = getArgs()
+	setupLogging()
 	opener = urllib2.build_opener(urllib2.HTTPCookieProcessor)
 	urllib2.install_opener( opener )
+ 'Retrieving %s for login', options.url )
 	login_page = urllib2.urlopen( options.url )
-	login_form = ParseResponse( login_page, backwards_compat=False )[0]
+	try:
+		login_form = ParseResponse( login_page, backwards_compat=False )[0]
+	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 />)." )
+	log.debug( 'login form follows' )
+	log.debug( str( login_form ) )
 	login_form['userName'] = options.username
 	login_form['password'] = options.password
+	log.debug( 'Submitting login form' )
-	result = urllib2.urlopen( options.url + options.retrieve_command ).read()
+	# consider checking the response above for some confirmation value (string "Main Menu" ?)
+	command = urljoin( options.url, options.retrieve_command )
+ 'Assuming login was successful, retrieving %s', command )
+	result = urllib2.urlopen( command ).read()
 		output = open( options.save_file, 'w' )
+ 'Writing response to file %s', options.save_file )
 	except TypeError:
+		log.warning( 'Writing response to console' )
 		output = sys.stdout
 	output.write( result )