Annotation of cdli/put.py, revision 1.1
1.1 ! dwinter 1: #!/usr/bin/python
! 2:
! 3: import httplib
! 4: import sys
! 5: from string import rfind
! 6:
! 7: collection = sys.argv[1]
! 8: file = sys.argv[2]
! 9:
! 10: f = open(file, 'r')
! 11: print "reading file %s ..." % file
! 12: xml = f.read()
! 13: f.close()
! 14:
! 15: p = rfind(file, '/')
! 16: if p > -1:
! 17: doc = file[p+1:]
! 18: else:
! 19: doc = file
! 20: print doc
! 21: print "storing document to collection %s ..." % collection
! 22: con = httplib.HTTP('localhost:8800')
! 23: con.putrequest('PUT', '/exist/servlet/%s/%s' % (collection, doc))
! 24: con.putheader('Content-Type', 'text/xml')
! 25: clen = len(xml)
! 26: con.putheader('Content-Length', `clen`)
! 27: con.endheaders()
! 28: con.send(xml)
! 29:
! 30: errcode, errmsg, headers = con.getreply()
! 31:
! 32: if errcode != 200:
! 33: f = con.getfile()
! 34: print 'An error occurred: %s' % errmsg
! 35: f.close()
! 36: else:
! 37: print "Ok."
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>