ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/python/translator.py
Revision: 1.2
Committed: Fri Jul 30 18:41:11 2010 UTC (14 years, 9 months ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d
Changes since 1.1: +22 -2 lines
Log Message:
Cleaned up and updated version.

File Contents

# Content
1 #---------------------------------------------------------------------------------------------------
2 # Python Module File to translate storage/computing elements into meta site names
3 #
4 # Author: C.Paus (Jun 16, 2010)
5 #---------------------------------------------------------------------------------------------------
6 import os,sys,re,string
7
8 #---------------------------------------------------------------------------------------------------
9 """
10 Class: Translator(table)
11 Each SubTask in CRAB can be described through this class
12 """
13 #---------------------------------------------------------------------------------------------------
14 class Translator:
15 "Translator for the storage and computing elements to the "
16 # variable to be determined
17 ceTable = 'undefined' # compute elements translation table
18 seTable = 'undefined' # storage elements translation table
19 allSites = 'undefined' # comma separated list of all sites
20 preferredSites = 'undefined' # comma separated list of preferred sites
21 ces = {}
22 ses = {}
23 #-----------------------------------------------------------------------------------------------
24 # constructor to connect with existing setup
25 #-----------------------------------------------------------------------------------------------
26 def __init__(self,ceTable,seTable):
27 self.ceTable = ceTable
28 self.seTable = seTable
29 if os.path.exists(self.seTable):
30 self.ses = self.readTable(self.seTable)
31 else:
32 print ' WARNING -- SE table file not found.'
33 if os.path.exists(self.ceTable):
34 self.ces = self.readTable(self.ceTable)
35 else:
36 print ' WARNING -- CE table file not found.'
37
38 #self.show()
39
40 def readTable(self,file):
41 table = {}
42 cmd = 'grep -v ^# ' + file + ' | tr -d \' \''
43 print ' Loading table: ' + cmd
44 for line in os.popen(cmd).readlines():
45 line = line[:-1]
46 # decode the storage directory name
47 names = line.split(":")
48 if names[1] in table:
49 print ' Site already in tables %s (%s)'%(names[1],names[0])
50 table[names[1]] = names[0]
51
52 return table
53
54 def translateSes(self,seString):
55 print ' translating SE sites: ' + seString
56 sites = seString.split(",")
57 newString = ''
58 #print ' Looping through sites %s'%(seString)
59 for site in sites:
60 if site in self.ses:
61 #print ' -> %s == %s'%(site,self.ses[site])
62 if newString == '':
63 newString = self.ses[site]
64 else:
65 newString = "%s,%s"%(newString,self.ses[site])
66 else:
67 print ' dropping %s because it is not in our table'%(site)
68
69 #print 'Translated: %s'%(newString)
70 self.allSites = newString
71 return newString
72
73 def translateCes(self,ceString):
74 print ' translating CE sites: ' + ceString
75 sites = ceString.split(",")
76 newString = ''
77 #print ' Looping through sites %s'%(ceString)
78 for site in sites:
79 if site in self.ces:
80 #print ' -> %s == %s'%(site,self.ces[site])
81 if newString == '':
82 newString = self.ces[site]
83 else:
84 newString = "%s,%s"%(newString,self.ces[site])
85 else:
86 print ' dropping %s because it is not in our table'%(site)
87
88 #print 'Translated: %s'%(newString)
89 self.allSites = newString
90 return newString
91
92 def selectPreferred(self):
93 if re.search('T2_US_MIT',self.allSites):
94 self.preferredSites = 'T2_US_MIT'
95 print ' '
96 print ' ' + self.allSites
97 print ' INFO -- found a preferred site in the list. Reducing to preferred sites.'
98 print ' '
99 else:
100 #print ' '
101 #print ' INFO -- no preferred site in the list. Keeping all sites.'
102 #print ' '
103 self.preferredSites = self.allSites
104 return self.preferredSites
105
106 #-----------------------------------------------------------------------------------------------
107 # present the current crab subtask
108 #-----------------------------------------------------------------------------------------------
109 def show(self):
110 print ' Translator (CE Table: %s, SE Table: %s) ===='%(self.ceTable,self.seTable)
111 print ' ==== Compute Elements'
112 for name,hostname in self.ces.iteritems():
113 print ' Site: %s --> CE: %s'%(name,hostname)
114 print ' ==== Storage Elements'
115 for name,hostname in self.ses.iteritems():
116 print ' Site: %s --> SE: %s'%(name,hostname)