1. Jason R. Coombs
  2. eodsfetch

Commits

jaraco  committed 6e4d549

Updated setup script to build the batch file dynamically so the usage doesn't have to be kept in sync with the code.

  • Participants
  • Parent commits 1eaa228
  • Branches default

Comments (0)

Files changed (4)

File eodsfetch/eodsfetch.bat

  • Ignore whitespace
-@echo off
-
-:: $Id$
-:: Copyright 2007-2008 HRWorX
-
-:: This batch file demonstrates some of the options for eodsfetch.exe
-:: To see all of the options available, run eodsfetch --help
-
-:: C:\Users\jaraco\projects\hrworx-util\dist>eodsfetch --help
-:: Usage:
-:: eodsfetch.py [options]
-
-:: FormworX fetch utility - retrieves data from a FormworX site.
-
-
-:: Options:
-::   --version             show program's version number and exit
-::   -h, --help            show this help message and exit
-::   -u URL, --url=URL     URL for the admin site
-::   -n USERNAME, --username=USERNAME
-::                         Username with export priveleges
-::   -p PASSWORD, --password=PASSWORD
-::                         Password
-::   -l LOG_LEVEL, --log-level=LOG_LEVEL
-::                         level should be DEBUG, INFO, WARNING, ERROR
-::   -c RETRIEVE_COMMAND, --retrieve-command=RETRIEVE_COMMAND
-::                         Web site path to retrieval command (relative to url)
-::   -s SAVE_FILE, --save-file=SAVE_FILE
-::                         Filename to save data (or '-' for stdout)
-::   -e MAIL_RESPONSE, --mail-response=MAIL_RESPONSE
-::                         An e-mail address to send the response
-::   --save_mail_response  Save the e-mail response to a file instead of actually
-::                         sending it.
-::   -r PROXY_SERVER, --proxy-server=PROXY_SERVER
-::                         Optional proxy server and port (server:port)
-::   -w PROXY_PASSWORD, --proxy-password=PROXY_PASSWORD
-::                         Password for the proxy server '-' for prompt
-::   -i PROXY_USER, --proxy-user=PROXY_USER
-::                         User name for the proxy server
-::   -t SOCKET_TIMEOUT, --socket-timeout=SOCKET_TIMEOUT
-::                         Socket timeout (seconds) for HTTP connections
-::   --require-content-type=REQUIRE_CONTENT_TYPE
-::                         Fail if the result content type does not match
-
-:: Sometimes, the library will be able to autodetect if you have a proxy configured.
-:: Other times, you have to specify a proxy explicitly.
-:: set HTTP_PROXY=10.104.1.200:8080
-
-set ADMIN_USER=admin
-set ADMIN_PASSWORD=pa55word
-set BASE_URL=http://dev.hrworx.com/ots-formworx-admin/
-
-:: To retrieve data from the development site, use the following command:
-:: eodsfetch.exe -u %BASE_URL% -n %ADMIN_USER% -p %ADMIN_PASSWORD% -c newhires/RetrieveQueuedExport.do -s c:\EODS.xml -l debug
-
-:: To review the data (without purging the records), use the "Review" command:
-eodsfetch.exe -u %BASE_URL% -n %ADMIN_USER% -p %ADMIN_PASSWORD% -c newhires/ReviewQueuedExport.do -s c:\EODS.xml -l debug
-
-:: If you don't specify a file to save to, the XML will be output to the screen
-:: eodsfetch.exe -u %BASE_URL% -n %ADMIN_USER% -p %ADMIN_PASSWORD% -c newhires/ReviewQueuedExport.do

File eodsfetch/eodsfetch.bat.template

View file
  • Ignore whitespace
+@echo off
+
+:: $Id$
+:: Copyright 2007-2008 HRWorX
+
+:: This batch file demonstrates some of the options for eodsfetch.exe
+:: To see all of the options available, run eodsfetch --help
+
+:: >eodsfetch --help
+{0}
+
+:: Sometimes, the library will be able to autodetect if you have a proxy configured.
+:: Other times, you have to specify a proxy explicitly.
+:: set HTTP_PROXY=10.104.1.200:8080
+
+set ADMIN_USER=admin
+set ADMIN_PASSWORD=pa55word
+set BASE_URL=http://dev.hrworx.com/ots-formworx-admin/
+
+:: To retrieve data from the development site, use the following command:
+:: eodsfetch.exe -u %BASE_URL% -n %ADMIN_USER% -p %ADMIN_PASSWORD% -c newhires/RetrieveQueuedExport.do -s c:\EODS.xml -l debug
+
+:: To review the data (without purging the records), use the "Review" command:
+eodsfetch.exe -u %BASE_URL% -n %ADMIN_USER% -p %ADMIN_PASSWORD% -c newhires/ReviewQueuedExport.do -s c:\EODS.xml -l debug
+
+:: If you don't specify a file to save to, the XML will be output to the screen
+:: eodsfetch.exe -u %BASE_URL% -n %ADMIN_USER% -p %ADMIN_PASSWORD% -c newhires/ReviewQueuedExport.do

File eodsfetch/eodsfetch.py

View file
  • Ignore whitespace
 	def find_user_password(self, realm, uri):
 		return self.username, self.password
 
-def get_args():
+def _get_arg_parser():
 	parser = OptionParser(usage = __doc__, version='%%prog %s' % __version__)
 	parser.add_option("-u", "--url", default="http://dev.hrworx.com/occ/formworx/admin/", help="URL for the admin site")
 	parser.add_option("-n", "--username", default="admin", help="Username with export priveleges")
 	parser.add_option("-i", "--proxy-user", help="User name for the proxy server")
 	parser.add_option("-t", "--socket-timeout", help="Socket timeout (seconds) for HTTP connections", default=30)
 	parser.add_option("--require-content-type", help="Fail if the result content type does not match", default="text/xml")
-	return parser.parse_args()
+	return parser
+
+def get_args():
+	return _get_arg_parser().parse_args()
 
 def setup_logging():
 	global log

File eodsfetch/setup-eodsfetch.py

View file
  • Ignore whitespace
 		pass
 	return readme_docs
 
+def escape_for_batch(stream):
+	"""
+	Place '::' at the beginning of each non-blank line to make it a comment
+	"""
+	for line in stream:
+		if line:
+			line = ':: ' + line
+		yield line
+
+def publish_batch():
+	"""
+	Generate the batch file with the usage dynamically generated
+	"""
+	batch_src = 'eodsfetch.bat.template'
+	template = open(batch_src, 'r').read()
+	import eodsfetch
+	parser = eodsfetch._get_arg_parser()
+	parser.prog = 'eodsfetch'
+	from StringIO import StringIO
+	usage = StringIO()
+	parser.print_help(usage)
+	usage.seek(0)
+	content = ''.join(escape_for_batch(usage))
+	content = template.format(content)
+	open('eodsfetch.bat', 'w').write(content)
+	return ['eodsfetch.bat']
+
 setup(
 	console=['eodsfetch.py'],
 	script_args=('py2exe',),
-	data_files=[('.',['eodsfetch.bat'] + publish_readme())],
+	data_files=[('.',publish_batch() + publish_readme())],
 )