File:  [Repository] / cdli / put.py
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Thu Nov 3 01:47:58 2005 UTC (18 years, 6 months ago) by dwinter
Branches: MAIN
CVS tags: zcat_only_1, Root_zcat_only_1, HEAD
*** empty log message ***

#!/usr/bin/python

import httplib
import sys
from string import rfind

collection = sys.argv[1]
file = sys.argv[2]

f = open(file, 'r')
print "reading file %s ..." % file
xml = f.read()
f.close()

p = rfind(file, '/')
if p > -1:
    doc = file[p+1:]
else:
    doc = file
print doc
print "storing document to collection %s ..." % collection
con = httplib.HTTP('localhost:8800')
con.putrequest('PUT', '/exist/servlet/%s/%s' % (collection, doc))
con.putheader('Content-Type', 'text/xml')
clen = len(xml)
con.putheader('Content-Length', `clen`)
con.endheaders()
con.send(xml)

errcode, errmsg, headers = con.getreply()

if errcode != 200:
    f = con.getfile()
    print 'An error occurred: %s' % errmsg
    f.close()
else:
    print "Ok."

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>