ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/DLSInfo.py
Revision: 1.7
Committed: Tue May 30 22:54:49 2006 UTC (18 years, 11 months ago) by afanfani
Content type: text/x-python
Branch: MAIN
Changes since 1.6: +25 -3 lines
Log Message:
changes to set up PyXML installation and use in case dls_type=dli

File Contents

# User Rev Content
1 afanfani 1.1 #!/usr/bin/env python
2     import sys, os, commands,string, re
3 afanfani 1.4 import exceptions
4     from crab_exceptions import *
5 afanfani 1.1 from crab_util import *
6     import common
7    
8 afanfani 1.7 try:
9     import dlsApi
10     import dlsClient
11     from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
12     except:
13     try:
14     Crabpydir=commands.getoutput('which crab')
15     Topdir=string.replace(Crabpydir,'/python/crab','')
16     sys.path.append(Topdir+'/DLSAPI')
17     import dlsApi
18     import dlsClient
19     from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
20     except:
21     msg="ERROR no DLS API available"
22     raise CrabException(msg)
23    
24     ## for python 2.2 add the pyexpat.so to PYTHONPATH
25     pythonV=sys.version.split(' ')[0]
26     if pythonV.find('2.2') >= 0 :
27     Crabpydir=commands.getoutput('which crab')
28     Topdir=string.replace(Crabpydir,'/python/crab','')
29     extradir=Topdir+'/DLSAPI/extra'
30     if sys.path.count(extradir) <= 0:
31     if os.path.exists(extradir):
32     sys.path.insert(0, extradir)
33 afanfani 1.6
34    
35 afanfani 1.1 class DLSError:
36 slacapra 1.5 def __init__(self, fileblocks):
37     print '\nERROR accessing DLS for fileblock '+fileblocks+'\n'
38     pass
39 afanfani 1.1
40 afanfani 1.4
41     class DLSNoReplicas(exceptions.Exception):
42 slacapra 1.5 def __init__(self, FileBlock):
43     args ="No replicas exists for fileblock: "+FileBlock+"\n"
44     exceptions.Exception.__init__(self, args)
45     pass
46    
47     def getClassName(self):
48     """ Return class name. """
49     return "%s" % (self.__class__.__name__)
50    
51     def getErrorMessage(self):
52     """ Return exception error. """
53     return "%s" % (self.args)
54 afanfani 1.4
55 afanfani 1.6
56 afanfani 1.1 ##############################################################################
57     # Class to extract info from DLS
58     ##############################################################################
59    
60     class DLSInfo:
61 afanfani 1.6 def __init__(self, type):
62     if type=="DLS_TYPE_DLI":
63     endpoint="lfc-cms-test.cern.ch/grid/cms/DLS/LFCProto"
64     try:
65     import xml.dom.ext.reader
66     except:
67     crabdir=os.getenv('CRABDIR')
68     ## Let the user set up PyXML by hand
69     msg="Need to setup the PyXML python module. Do the following:\n"
70     msg+=" cd %s/DLSAPI\n"%crabdir
71     msg+=" ./InstallPyXML.sh"
72     raise CrabException(msg)
73    
74     elif type=="DLS_TYPE_MYSQL":
75     endpoint="lxgate10.cern.ch:18081"
76     else:
77     msg = "DLS type %s not among the supported DLS ( DLS_TYPE_DLI and DLS_TYPE_MYSQL ) "%type
78     raise CrabException(msg)
79    
80     try:
81     self.api = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
82     except dlsApi.DlsApiError, inst:
83     msg = "Error when binding the DLS interface: %s Server %s"%(str(inst),self.DLSServer_)
84     #print msg
85     raise CrabException(msg)
86 afanfani 1.1
87     # ####################################
88 afanfani 1.6 def getReplicas(self,fileblocks):
89 slacapra 1.5 """
90     query DLS to get replicas
91     """
92     ##
93 afanfani 1.6 try:
94     entryList=self.api.getLocations([fileblocks])
95     except dlsApi.DlsApiError, inst:
96     msg = "Error in the DLS query: %s." % str(inst)
97     #print msg
98     raise DLSNoReplicas(fileblocks)
99    
100     ListSites=[]
101     for entry in entryList:
102     for loc in entry.locations:
103     ListSites.append(str(loc.host))
104     if len(ListSites)<=0:
105     raise DLSNoReplicas(fileblocks)
106 afanfani 1.4
107 slacapra 1.5 return ListSites