Anonymous avatar Anonymous 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.

Comments (0)

Files changed (2)

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 http://dev01.hrworx.com:8180/occ/formworx/admin -n occ.formworx@hrworx.com -p manager -c /newhires/RetrieveQueuedExport.do -s c:\EODS.xml
+rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/RetrieveQueuedExport.do -s c:\EODS.xml
 
 rem To review the data (without purging the records), use the "Review" command:
-rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin -n occ.formworx@hrworx.com -p manager -c /newhires/ReviewQueuedExport.do -s c:\EODS.xml
+rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/ReviewQueuedExport.do -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 http://dev01.hrworx.com:8180/occ/formworx/admin -n occ.formworx@hrworx.com -p manager -c /newhires/ReviewQueuedExport.do
+rem eodsfetch.exe -u http://dev01.hrworx.com:8180/occ/formworx/admin/ -n occ.formworx@hrworx.com -p manager -c newhires/ReviewQueuedExport.do

eodsfetch/eodsfetch.py

 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/ReviewQueuedExport.do", help="Web site path to retrieval command" )
+	parser.add_option( "-c", "--retrieve-command", default="newhires/ReviewQueuedExport.do", 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 )
+	log.info( '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 )
+		log.info( "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' )
 	urllib2.urlopen(login_form.click()).read()
-	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 )
+	log.info( 'Assuming login was successful, retrieving %s', command )
+	result = urllib2.urlopen( command ).read()
 	try:
 		output = open( options.save_file, 'w' )
+		log.info( 'Writing response to file %s', options.save_file )
 	except TypeError:
+		log.warning( 'Writing response to console' )
 		output = sys.stdout
 	output.write( result )
 
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 ProjectModifiedEvent.java.
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.