Skip to content

Commit

Permalink
add timeout flag to post_xml (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Dec 17, 2012
1 parent 3b5303b commit 2e263fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pycsw/admin.py
Expand Up @@ -411,14 +411,14 @@ def gen_opensearch_description(context, mdata, url, output_file):
encoding='UTF-8', xml_declaration=1))


def post_xml(url, xml):
def post_xml(url, xml, timeout=30):
"""Execute HTTP XML POST request and print response"""

LOGGER.info('Executing HTTP POST request %s on server %s', xml, url)

from owslib.util import http_post
try:
return http_post(url, open(xml).read())
return http_post(url=url, request=open(xml).read(), timeout=timeout)
except Exception, err:
raise RuntimeError(err)

Expand Down
9 changes: 7 additions & 2 deletions sbin/pycsw-admin.py
Expand Up @@ -79,6 +79,8 @@ def usage():
-s XML Schema
-t Timeout (in seconds) for HTTP requests (default is 30)
-u URL of CSW
-x XML document
Expand Down Expand Up @@ -144,13 +146,14 @@ def usage():
CSW_URL = None
XML = None
XSD = None
TIMEOUT = 30

if len(sys.argv) == 1:
print usage()
sys.exit(1)

try:
OPTS, ARGS = getopt.getopt(sys.argv[1:], 'c:f:ho:p:ru:x:s:')
OPTS, ARGS = getopt.getopt(sys.argv[1:], 'c:f:ho:p:ru:x:s:t:')
except getopt.GetoptError, err:
print '\nERROR: %s' % err
print usage()
Expand All @@ -173,6 +176,8 @@ def usage():
XML = a
if o == '-s':
XSD = a
if o == '-t':
TIMEOUT = int(a)
if o == '-h': # dump help and exit
print usage()
sys.exit(3)
Expand Down Expand Up @@ -247,7 +252,7 @@ def usage():
elif COMMAND == 'gen_opensearch_description':
admin.gen_opensearch_description(CONTEXT, METADATA, URL, OUTPUT_FILE)
elif COMMAND == 'post_xml':
print admin.post_xml(CSW_URL, XML)
print admin.post_xml(CSW_URL, XML, TIMEOUT)
elif COMMAND == 'get_sysprof':
print admin.get_sysprof()
elif COMMAND == 'validate_xml':
Expand Down

0 comments on commit 2e263fa

Please sign in to comment.