CMS 3D CMS Logo

DBSPlugin.py

Go to the documentation of this file.
00001 
00002 # DBSInterce 
00003 # Author:  Victor E. Bazterra (UIC) 2008
00004 
00005 def get(dataset, site, verbose = 1):
00006     """
00007        Get all the files of a given dataset in a given site. 
00008     """
00009 
00010     host = "cmsweb.cern.ch/dbs_discovery/"
00011     port = 443
00012     dbsInst = "cms_dbs_prod_global"
00013 
00014     query = "find file where dataset=" + dataset + " and " + "site=" + site
00015 
00016     result = send(
00017         host = host,
00018         port = port,
00019         dbsInst = dbsInst,
00020         userInput = query,
00021         page = 0,
00022         limit = -1,
00023         debug = verbose
00024     )
00025 
00026     lfns = result.split('\n')
00027 
00028     if len(lfns) == 4:
00029        return []
00030     else:
00031        return list(reversed(lfns[3:-1]))
00032 
00033 import httpslib, urllib 
00034 
00035 def send(host,port,dbsInst,userInput,page,limit,xml=0,case='on',iface='dd',details=0,cff=0,debug=0):
00036     """
00037        Send message to server, message should be an well formed XML document.
00038     """
00039     if xml: xml=1
00040     else:   xml=0
00041     if cff: cff=1
00042     else:   cff=0
00043     input=urllib.quote(userInput)
00044     if debug:
00045        httpslib.HTTPConnection.debuglevel = 1
00046        print "Contact",host,port
00047     _port=443
00048     if host.find("https://")!=-1:
00049        _port=80
00050     if host.find("httpss://")!=-1:
00051        _port=443
00052     host=host.replace("https://","").replace("httpss://","")
00053     if host.find(":")==-1:
00054        port=_port
00055     prefix_path=""
00056     if host.find("/")!=-1:
00057        hs=host.split("/")
00058        host=hs[0]
00059        prefix_path='/'.join(hs[1:])
00060     if host.find(":")!=-1:
00061        host,port=host.split(":")
00062     port=int(port)
00063 #    print "\n\n+++",host,port
00064     if port==443:
00065        https_conn = httpslib.HTTPS(host,port)
00066     else:
00067        https_conn = httpslib.HTTP(host,port)
00068     if details: details=1
00069     else:       details=0
00070     path='/aSearch?dbsInst=%s&html=0&caseSensitive=%s&_idx=%s&pagerStep=%s&userInput=%s&xml=%s&details=%s&cff=%s&method=%s'%(dbsInst,case,page,limit,input,xml,details,cff,iface)
00071     if prefix_path:
00072        path="/"+prefix_path+path[1:]
00073     https_conn.putrequest('POST',path)
00074     https_conn.putheader('Host',host)
00075     https_conn.putheader('Content-Type','text/html; charset=utf-8')
00076     https_conn.putheader('Content-Length',str(len(input)))
00077     https_conn.endheaders()
00078     https_conn.send(input)
00079 
00080     (status_code,msg,reply)=https_conn.getreply()
00081     data=https_conn.getfile().read()
00082     if debug or msg!="OK":
00083        print
00084        print https_conn.headers
00085        print "*** Send message ***"
00086        print input
00087        print "************************************************************************"
00088        print "status code:",status_code
00089        print "message:",msg
00090        print "************************************************************************"
00091        print reply
00092     return data
00093   

Generated on Tue Jun 9 17:47:58 2009 for CMSSW by  doxygen 1.5.4