#!/usr/bin/env python #-*- coding: ISO-8859-1 -*- # # Author: Valentin Kuznetsov, Cornell University, 2006 # # system modules import os, sys, string, sre, httplib, urllib, inspect import cElementTree as ElementTree # DBS modules from XMLToDict import * from DBSTables import * from dbsApi import DbsApi, DbsApiException, InvalidDataTier from dbsPrimaryDataset import * from dbsFileBlock import * from dbsApplication import * from dbsProcessing import * from dbsProcessedDataset import * from dbsBaseObject import * from dbsParameterSet import * from dbsApplicationConfig import * HOST = 'localhost' PORT = 8080 def call(iMethod,envelope,test=1,debug=1): """Send HTTP message to CherryPy server. Right now we use httplib to do a job""" if debug: httplib.HTTPConnection.debuglevel = 1 http_conn = httplib.HTTP(HOST,PORT) http_conn.putrequest('POST','/dbs/execute?iMethod=%s'%iMethod) http_conn.putheader('Host',HOST) http_conn.putheader('Content-Type','text/xml; charset=utf-8') http_conn.putheader('Content-Length',str(len(envelope))) http_conn.endheaders() http_conn.send(envelope) (status_code,msg,reply)=http_conn.getreply() response=http_conn.getfile().read() if debug or msg!="OK": print print http_conn.headers print "*** Outgoing MSG ******************************************************" print envelope print "************************************************************************" print "status code:",status_code print "message:",msg print "************************************************************************" print reply print "*** Incoming MSG ******************************************************" print response return response if __name__ == '__main__': # test listPrimaryDatasets method pDict = {'pattern':'*'} xml_string = call('listPrimaryDatasets',makeXML(pDict)) print "### We got the following results" print xml_string root = ElementTree.XML(xml_string) xmldict = XmlDictConfig(root) print "### Parse XML output" print xmldict # test createPrimaryDataset method basename = 'client_datasetName' application= {'executable' : 'testexe','version' : 'testversion','family' : 'testfamily'} appConfig = {'application':application,'parameterSet':{'hash':'myhash','content':'mycontent'}} primary = DbsPrimaryDataset (name = basename) # print "### Send: ",primary xml_string = call('createPrimaryDataset',makeXML(primary)) # print "### We got the following results" # print xml_string root = ElementTree.XML(xml_string) xmldict = XmlDictConfig(root) print "### Parse XML output" print xmldict