ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/crab_util.py
Revision: 1.94
Committed: Wed Sep 16 09:03:40 2009 UTC (15 years, 7 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.93: +20 -0 lines
Log Message:
Coexistence of both lcg-utils 1.6 and 1.7

File Contents

# User Rev Content
1 spiga 1.80 ##########################################################################
2 nsmirnov 1.1 #
3     # C O N V E N I E N C E F U N C T I O N S
4     #
5     ###########################################################################
6    
7 slacapra 1.12 import string, sys, os, time
8 slacapra 1.16 import ConfigParser, re, popen2, select, fcntl
9 ewv 1.89 import statvfs
10 nsmirnov 1.1
11 nsmirnov 1.2 import common
12 slacapra 1.30 from crab_exceptions import CrabException
13 spiga 1.42 from ServerConfig import *
14 nsmirnov 1.1
15     ###########################################################################
16     def parseOptions(argv):
17     """
18     Parses command-line options.
19     Returns a dictionary with specified options as keys:
20     -opt1 --> 'opt1' : None
21     -opt2 val --> 'opt2' : 'val'
22     -opt3=val --> 'opt3' : 'val'
23     Usually called as
24     options = parseOptions(sys.argv[1:])
25     """
26     options = {}
27     argc = len(argv)
28     i = 0
29     while ( i < argc ):
30     if argv[i][0] != '-':
31     i = i + 1
32     continue
33     eq = string.find(argv[i], '=')
34     if eq > 0 :
35     opt = argv[i][:eq]
36     val = argv[i][eq+1:]
37     pass
38     else:
39     opt = argv[i]
40     val = None
41     if ( i+1 < argc and argv[i+1][0] != '-' ):
42     i = i + 1
43     val = argv[i]
44     pass
45     pass
46     options[opt] = val
47     i = i + 1
48     pass
49     return options
50    
51 slacapra 1.47 def loadConfig(file, config):
52 nsmirnov 1.1 """
53     returns a dictionary with keys of the form
54     <section>.<option> and the corresponding values
55     """
56 slacapra 1.47 #config={}
57 nsmirnov 1.1 cp = ConfigParser.ConfigParser()
58     cp.read(file)
59     for sec in cp.sections():
60     for opt in cp.options(sec):
61 spiga 1.79 ## temporary check. Allow compatibility
62 ewv 1.89 new_sec = sec
63 spiga 1.79 if sec == 'EDG':
64 spiga 1.80 print ('\tWARNING: The [EDG] section is now deprecated.\n\tPlease remove it and use [GRID] instead.\n')
65 ewv 1.89 new_sec = 'GRID'
66 spiga 1.79 config[new_sec+'.'+opt] = string.strip(cp.get(sec,opt))
67 nsmirnov 1.1 return config
68    
69     ###########################################################################
70     def isInt(str):
71     """ Is the given string an integer ?"""
72     try: int(str)
73     except ValueError: return 0
74     return 1
75    
76     ###########################################################################
77     def isBool(str):
78     """ Is the given string 0 or 1 ?"""
79     if (str in ('0','1')): return 1
80     return 0
81    
82     ###########################################################################
83 nsmirnov 1.3 def parseRange(range):
84     """
85     Takes as the input a string with two integers separated by
86     the minus sign and returns the tuple with these numbers:
87     'n1-n2' -> (n1, n2)
88     'n1' -> (n1, n1)
89     """
90     start = None
91     end = None
92     minus = string.find(range, '-')
93     if ( minus < 0 ):
94     if isInt(range):
95     start = int(range)
96     end = start
97     pass
98     pass
99     else:
100     if isInt(range[:minus]) and isInt(range[minus+1:]):
101     start = int(range[:minus])
102     end = int(range[minus+1:])
103     pass
104     pass
105     return (start, end)
106    
107     ###########################################################################
108 nsmirnov 1.4 def parseRange2(range):
109     """
110     Takes as the input a string in the form of a comma-separated
111     numbers and ranges
112     and returns a list with all specified numbers:
113     'n1' -> [n1]
114     'n1-n2' -> [n1, n1+1, ..., n2]
115     'n1,n2-n3,n4' -> [n1, n2, n2+1, ..., n3, n4]
116     """
117 slacapra 1.30 result = []
118     if not range: return result
119 nsmirnov 1.4
120     comma = string.find(range, ',')
121     if comma == -1: left = range
122     else: left = range[:comma]
123    
124     (n1, n2) = parseRange(left)
125     while ( n1 <= n2 ):
126 slacapra 1.11 try:
127 slacapra 1.30 result.append(n1)
128 slacapra 1.11 n1 += 1
129     pass
130     except:
131     msg = 'Syntax error in range <'+range+'>'
132     raise CrabException(msg)
133 nsmirnov 1.4
134     if comma != -1:
135 slacapra 1.11 try:
136 slacapra 1.30 result.extend(parseRange2(range[comma+1:]))
137 slacapra 1.11 pass
138     except:
139     msg = 'Syntax error in range <'+range+'>'
140     raise CrabException(msg)
141 nsmirnov 1.4
142 slacapra 1.30 return result
143 nsmirnov 1.4
144     ###########################################################################
145 nsmirnov 1.1 def findLastWorkDir(dir_prefix, where = None):
146    
147     if not where: where = os.getcwd() + '/'
148     # dir_prefix usually has the form 'crab_0_'
149     pattern = re.compile(dir_prefix)
150    
151 slacapra 1.76 file_list = [f for f in os.listdir(where) if os.path.isdir(f) and pattern.match(f)]
152 nsmirnov 1.1
153     if len(file_list) == 0: return None
154    
155     file_list.sort()
156    
157 slacapra 1.76 wdir = where + file_list[-1]
158 nsmirnov 1.1 return wdir
159    
160     ###########################################################################
161     def importName(module_name, name):
162     """
163     Import a named object from a Python module,
164     i.e., it is an equivalent of 'from module_name import name'.
165     """
166     module = __import__(module_name, globals(), locals(), [name])
167     return vars(module)[name]
168    
169     ###########################################################################
170 slacapra 1.16 def readable(fd):
171 ewv 1.44 return bool(select.select([fd], [], [], 0))
172 slacapra 1.16
173     ###########################################################################
174     def makeNonBlocking(fd):
175     fl = fcntl.fcntl(fd, fcntl.F_GETFL)
176     try:
177     fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
178     except AttributeError:
179     fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.FNDELAY)
180    
181     ###########################################################################
182 slacapra 1.11 def runCommand(cmd, printout=0, timeout=-1):
183 nsmirnov 1.1 """
184     Run command 'cmd'.
185     Returns command stdoutput+stderror string on success,
186     or None if an error occurred.
187 slacapra 1.16 Following recipe on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52296
188 nsmirnov 1.1 """
189 fanzago 1.15
190 slacapra 1.11 if printout:
191 spiga 1.78 common.logger.info(cmd)
192 slacapra 1.11 else:
193 spiga 1.78 common.logger.log(10-1,cmd)
194 slacapra 1.29 pass
195 slacapra 1.11
196 slacapra 1.16 child = popen2.Popen3(cmd, 1) # capture stdout and stderr from command
197     child.tochild.close() # don't need to talk to child
198 ewv 1.44 outfile = child.fromchild
199 slacapra 1.16 outfd = outfile.fileno()
200     errfile = child.childerr
201     errfd = errfile.fileno()
202     makeNonBlocking(outfd) # don't deadlock!
203     makeNonBlocking(errfd)
204     outdata = []
205     errdata = []
206     outeof = erreof = 0
207    
208     if timeout > 0 :
209     maxwaittime = time.time() + timeout
210    
211     err = -1
212     while (timeout == -1 or time.time() < maxwaittime):
213     ready = select.select([outfd,errfd],[],[]) # wait for input
214     if outfd in ready[0]:
215     outchunk = outfile.read()
216     if outchunk == '': outeof = 1
217     outdata.append(outchunk)
218     if errfd in ready[0]:
219     errchunk = errfile.read()
220     if errchunk == '': erreof = 1
221     errdata.append(errchunk)
222     if outeof and erreof:
223     err = child.wait()
224     break
225 slacapra 1.21 select.select([],[],[],.01) # give a little time for buffers to fill
226 slacapra 1.16 if err == -1:
227     # kill the pid
228 spiga 1.78 common.logger.info('killing process '+(cmd)+' with timeout '+str(timeout))
229 slacapra 1.16 os.kill (child.pid, 9)
230 slacapra 1.11 err = child.wait()
231 slacapra 1.16
232 fanzago 1.17 cmd_out = string.join(outdata,"")
233     cmd_err = string.join(errdata,"")
234    
235 slacapra 1.11 if err:
236 spiga 1.78 common.logger.info('`'+cmd+'`\n failed with exit code '
237 slacapra 1.11 +`err`+'='+`(err&0xff)`+'(signal)+'
238     +`(err>>8)`+'(status)')
239 spiga 1.78 common.logger.info(cmd_out)
240     common.logger.info(cmd_err)
241 nsmirnov 1.1 return None
242    
243 fanzago 1.17 # cmd_out = string.join(outdata,"")
244     # cmd_err = string.join(errdata,"")
245 nsmirnov 1.1 cmd_out = cmd_out + cmd_err
246 slacapra 1.11 if printout:
247 spiga 1.78 common.logger.info(cmd_out)
248 slacapra 1.11 else:
249 spiga 1.78 common.logger.log(10-1,cmd_out)
250 slacapra 1.29 pass
251 slacapra 1.16 #print "<"+cmd_out+">"
252 nsmirnov 1.1 return cmd_out
253 nsmirnov 1.4
254 slacapra 1.11 ####################################
255 gutsche 1.20 def makeCksum(filename) :
256     """
257 ewv 1.44 make check sum using filename and content of file
258 gutsche 1.20 """
259    
260 ewv 1.44 from zlib import crc32
261     hashString = filename
262 gutsche 1.20
263 ewv 1.44 inFile = open(filename, 'r')
264     hashString += inFile.read()
265     inFile.close()
266 gutsche 1.20
267 ewv 1.44 cksum = str(crc32(hashString))
268 gutsche 1.20 return cksum
269    
270 ewv 1.52
271 gutsche 1.32 def spanRanges(jobArray):
272     """
273     take array of job numbers and concatenate 1,2,3 to 1-3
274     return string
275     """
276    
277     output = ""
278 mcinquil 1.35 jobArray.sort()
279 ewv 1.44
280 gutsche 1.32 previous = jobArray[0]-1
281     for job in jobArray:
282     if previous+1 == job:
283     previous = job
284     if len(output) > 0 :
285     if output[-1] != "-":
286     output += "-"
287     else :
288     output += str(previous)
289     else:
290     output += str(previous) + "," + str(job)
291 mcinquil 1.35 #output += "," + str(job)
292 gutsche 1.32 previous = job
293     if len(jobArray) > 1 :
294     output += str(previous)
295    
296     return output
297    
298 spiga 1.40 def displayReport(self, header, lines, xml=''):
299 ewv 1.44
300 spiga 1.49 counter = 0
301     printline = ''
302     printline+= header
303 spiga 1.87 msg = '\n%s'%printline
304 spiga 1.49
305     for i in range(len(lines)):
306     if counter != 0 and counter%10 == 0 :
307 slacapra 1.84 msg += '-------------------------------------------------------------------------------------------------------\n'
308 spiga 1.82 msg+= '%s\n'%lines[i]
309 spiga 1.49 counter += 1
310     if xml != '' :
311 spiga 1.40 fileName = common.work_space.shareDir() + xml
312     task = common._db.getTask()
313     taskXML = common._db.serializeTask(task)
314 spiga 1.87 common.logger.log(10-1, taskXML)
315 spiga 1.40 f = open(fileName, 'w')
316     f.write(taskXML)
317     f.close()
318     pass
319 spiga 1.82 common.logger.info(msg)
320 spiga 1.39
321 spiga 1.42 def CliServerParams(self):
322 slacapra 1.45 """
323     Init client-server interactions
324     """
325     self.srvCfg = {}
326 slacapra 1.63 ## First I have to check if the decision has been already taken...
327     task = common._db.getTask()
328 slacapra 1.81 if task['serverName']!=None and task['serverName']!="":
329 slacapra 1.63 self.cfg_params['CRAB.server_name']=task['serverName']
330 slacapra 1.81
331     if self.cfg_params.has_key('CRAB.server_name'):
332     self.srvCfg = ServerConfig(self.cfg_params['CRAB.server_name']).config()
333     elif self.cfg_params.has_key('CRAB.use_server'):
334 slacapra 1.77 serverName=self.cfg_params.get('CRAB.server_name','default')
335 slacapra 1.62 if self.cfg_params.has_key('CRAB.server_name'):
336     serverName=self.cfg_params['CRAB.server_name']
337     else:
338     serverName='default'
339     self.srvCfg = ServerConfig(serverName).config()
340 slacapra 1.61 else:
341     msg = 'No server selected or port specified.\n'
342     msg += 'Please specify a server in the crab cfg file'
343     raise CrabException(msg)
344     return
345 slacapra 1.81 # save the serverName for future use
346     opsToBeSaved={}
347     opsToBeSaved['serverName']=self.srvCfg['serverGenericName']
348     common._db.updateTask_(opsToBeSaved)
349 slacapra 1.45
350 slacapra 1.61 self.server_admin = str(self.srvCfg['serverAdmin'])
351     self.server_dn = str(self.srvCfg['serverDN'])
352 spiga 1.58
353 slacapra 1.61 self.server_name = str(self.srvCfg['serverName'])
354     self.server_port = int(self.srvCfg['serverPort'])
355 slacapra 1.45
356 slacapra 1.61 self.storage_name = str(self.srvCfg['storageName'])
357     self.storage_path = str(self.srvCfg['storagePath'])
358     self.storage_proto = str(self.srvCfg['storageProtocol'])
359     self.storage_port = str(self.srvCfg['storagePort'])
360 spiga 1.39
361 ewv 1.44 def bulkControl(self,list):
362 slacapra 1.45 """
363     Check the BULK size and reduce collection ...if needed
364     """
365     max_size = 400
366     sub_bulk = []
367     if len(list) > int(max_size):
368     n_sub_bulk = int( int(len(list) ) / int(max_size) )
369 mcinquil 1.53 for n in xrange(n_sub_bulk):
370 slacapra 1.45 first =n*int(max_size)
371     last = (n+1)*int(max_size)
372     sub_bulk.append(list[first:last])
373     if len(list[last:-1]) < 50:
374     for pp in list[last:-1]:
375     sub_bulk[n_sub_bulk-1].append(pp)
376 spiga 1.43 else:
377 mcinquil 1.53 sub_bulk.append(list[last:])
378 slacapra 1.45 else:
379     sub_bulk.append(list)
380    
381     return sub_bulk
382 ewv 1.89
383 slacapra 1.45
384 spiga 1.69 def getUserName():
385 spiga 1.66 """
386     extract user name from either SiteDB or Unix
387     """
388 mcinquil 1.91 if common.scheduler.name().upper() in ['LSF', 'CAF', 'SGE']:
389 ewv 1.89 common.logger.log(10-1, "Using as username the Unix user name")
390     userName = unixUserName()
391 spiga 1.66 else :
392 ewv 1.89 userName = gethnUserNameFromSiteDB()
393    
394     return userName
395 spiga 1.66
396 spiga 1.58
397 ewv 1.89 def unixUserName():
398 spiga 1.58 """
399     extract username from whoami
400     """
401     try:
402 ewv 1.89 userName = runCommand("whoami")
403     userName = string.strip(userName)
404 spiga 1.58 except:
405     msg = "Error. Problem with whoami command"
406     raise CrabException(msg)
407 ewv 1.89 return userName
408    
409 spiga 1.66
410 spiga 1.69 def getDN():
411 spiga 1.66 """
412     extract DN from user proxy's identity
413     """
414     try:
415     userdn = runCommand("voms-proxy-info -identity")
416     userdn = string.strip(userdn)
417     #search for a / to avoid picking up warning messages
418     userdn = userdn[userdn.find('/'):]
419     except:
420     msg = "Error. Problem with voms-proxy-info -identity command"
421     raise CrabException(msg)
422     return userdn.split('\n')[0]
423    
424 ewv 1.89
425 spiga 1.69 def gethnUserNameFromSiteDB():
426 spiga 1.66 """
427     extract user name from SiteDB
428     """
429     from WMCore.Services.SiteDB.SiteDB import SiteDBJSON
430     hnUserName = None
431 spiga 1.69 userdn = getDN()
432 ewv 1.89 params = { 'cacheduration' : 24,
433     'logger' : common.logger() }
434     mySiteDB = SiteDBJSON(params)
435 ewv 1.90 msg_ = "there is no user name associated to DN %s in SiteDB.\n" % userdn
436     msg_ += "You need to register in SiteDB with the instructions at https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB"
437 spiga 1.66 try:
438     hnUserName = mySiteDB.dnUserName(dn=userdn)
439 ewv 1.89 except Exception, text:
440     msg = "Error extracting user name from SiteDB: %s\n" % text
441     msg += " Check that you are registered in SiteDB, see https://twiki.cern.ch/twiki/bin/view/CMS/SiteDBForCRAB\n"
442     msg += ' or %s' % msg_
443 spiga 1.66 raise CrabException(msg)
444     if not hnUserName:
445 ewv 1.89 msg = "Error. %s" % msg_
446 spiga 1.66 raise CrabException(msg)
447     return hnUserName
448    
449    
450 slacapra 1.45 def numberFile(file, txt):
451     """
452     append _'txt' before last extension of a file
453     """
454     txt=str(txt)
455     p = string.split(file,".")
456     # take away last extension
457     name = p[0]
458     for x in p[1:-1]:
459     name=name+"."+x
460     # add "_txt"
461     if len(p)>1:
462     ext = p[len(p)-1]
463     result = name + '_' + txt + "." + ext
464     else:
465     result = name + '_' + txt
466 spiga 1.43
467 slacapra 1.45 return result
468 spiga 1.46
469     def readTXTfile(self,inFileName):
470     """
471     read file and return a list with the content
472     """
473     out_list=[]
474     if os.path.exists(inFileName):
475     f = open(inFileName, 'r')
476     for line in f.readlines():
477 ewv 1.52 out_list.append(string.strip(line))
478 spiga 1.46 f.close()
479     else:
480     msg = ' file '+str(inFileName)+' not found.'
481 ewv 1.52 raise CrabException(msg)
482 spiga 1.46 return out_list
483    
484     def writeTXTfile(self, outFileName, args):
485     """
486     write a file with the given content ( args )
487     """
488     outFile = open(outFileName,"a")
489     outFile.write(str(args))
490     outFile.close()
491     return
492    
493 spiga 1.54 def readableList(self,rawList):
494 ewv 1.64 """
495     Turn a list of numbers into a string like 1-5,7,9,12-20
496     """
497     if not rawList:
498     return ''
499    
500 slacapra 1.56 listString = str(rawList[0])
501     endRange = ''
502     for i in range(1,len(rawList)):
503     if rawList[i] == rawList[i-1]+1:
504     endRange = str(rawList[i])
505     else:
506     if endRange:
507     listString += '-' + endRange + ',' + str(rawList[i])
508     endRange = ''
509     else:
510     listString += ',' + str(rawList[i])
511     if endRange:
512     listString += '-' + endRange
513     endRange = ''
514 ewv 1.64
515 slacapra 1.56 return listString
516 spiga 1.54
517 spiga 1.51 def getLocalDomain(self):
518 ewv 1.52 """
519 slacapra 1.56 Get local domain name
520 ewv 1.52 """
521 spiga 1.51 import socket
522 slacapra 1.88 tmp=socket.getfqdn()
523 spiga 1.51 dot=string.find(tmp,'.')
524     if (dot==-1):
525     msg='Unkown domain name. Cannot use local scheduler'
526     raise CrabException(msg)
527     localDomainName = string.split(tmp,'.',1)[-1]
528 ewv 1.52 return localDomainName
529 spiga 1.51
530 slacapra 1.56 #######################################################
531     # Brian Bockelman bbockelm@cse.unl.edu
532     # Module to check the avaialble disk space on a specified directory.
533     #
534    
535     def has_freespace(dir_name, needed_space_kilobytes):
536     enough_unix_quota = False
537     enough_quota = False
538     enough_partition = False
539     enough_mount = False
540     try:
541     enough_mount = check_mount(dir_name, need_space_kilobytes)
542     except:
543     enough_mount = True
544     try:
545     enough_quota = check_quota(dir_name, needed_space_kilobytes)
546     except:
547     raise
548     enough_quota = True
549     try:
550     enough_partition = check_partition(dir_name,
551     needed_space_kilobytes)
552     except:
553     enough_partition = True
554     try:
555     enough_unix_quota = check_unix_quota(dir_name,
556     needed_space_kilobytes)
557     except:
558     enough_unix_quota = True
559     return enough_mount and enough_quota and enough_partition \
560     and enough_unix_quota
561    
562     def check_mount(dir_name, needed_space_kilobytes):
563     try:
564     vfs = os.statvfs(dir_name)
565     except:
566     raise Exception("Unable to query VFS for %s." % dir_name)
567     dev_free = vfs[statvfs.F_FRSIZE] * vfs[statvfs.F_BAVAIL]
568     return dev_free/1024 > needed_space_kilobytes
569    
570     def check_quota(dir_name, needed_space_kilobytes):
571     _, fd, _ = os.popen3("/usr/bin/fs lq %s" % dir_name)
572     results = fd.read()
573     if fd.close():
574     raise Exception("Unable to query the file system quota!")
575     try:
576     results = results.split('\n')[1].split()
577     quota, used = results[1:3]
578     avail = int(quota) - int(used)
579     return avail > needed_space_kilobytes
580     except:
581     return Exception("Unable to parse AFS output.")
582    
583     def check_partition(dir_name, needed_space_kilobytes):
584     _, fd, _ = os.popen3("/usr/bin/fs diskfree %s" % dir_name)
585     results = fd.read()
586     if fd.close():
587     raise Exception("Unable to query the file system quota!")
588     try:
589     results = results.split('\n')[1].split()
590     avail = results[3]
591     return int(avail) > needed_space_kilobytes
592     except:
593     raise Exception("Unable to parse AFS output.")
594    
595     def check_unix_quota(dir_name, needed_space_kilobytes):
596     _, fd, _ = os.popen3("df %s" % dir_name)
597     results = fd.read()
598     if fd.close():
599     raise Exception("Unable to query the filesystem with df.")
600     fs = results.split('\n')[1].split()[0]
601     _, fd, _ = os.popen3("quota -Q -u -g")
602     results = fd.read()
603     if fd.close():
604     raise Exception("Unable to query the quotas.")
605     has_info = False
606     for line in results.splitlines():
607     info = line.split()
608     if info[0] in ['Filesystem', 'Disk']:
609     continue
610     if len(info) == 1:
611     filesystem = info[0]
612     has_info = False
613     if len(info) == 6:
614 ewv 1.93 used, limit = info[0], max(info[1], info[2])
615 slacapra 1.56 has_info = True
616     if len(info) == 7:
617 ewv 1.93 filesystem, used, limit = info[0], info[1], max(info[2], info[3])
618 slacapra 1.56 has_info = True
619     if has_info:
620     if filesystem != fs:
621     continue
622     avail = int(limit) - int(used)
623     if avail < needed_space_kilobytes:
624     return False
625     return True
626 spiga 1.54
627 slacapra 1.57 def getGZSize(gzipfile):
628     # return the uncompressed size of a gzipped file
629     import struct
630     f = open(gzipfile, "rb")
631     if f.read(2) != "\x1f\x8b":
632     raise IOError("not a gzip file")
633     f.seek(-4, 2)
634 ewv 1.64 return struct.unpack("<i", f.read())[0]
635 slacapra 1.57
636 spiga 1.60 def showWebMon(server_name):
637 spiga 1.72 taskName = common._db.queryTask('name')
638 spiga 1.60 msg = ''
639 spiga 1.71 msg +='You can also follow the status of this task on :\n'
640 spiga 1.72 msg +='\tCMS Dashboard: http://dashb-cms-job-task.cern.ch/taskmon.html#task=%s\n'%(taskName)
641 ewv 1.64 if server_name != '' :
642 spiga 1.71 msg += '\tServer page: http://%s:8888/logginfo\n'%server_name
643 spiga 1.72 msg += '\tYour task name is: %s \n'%taskName
644 spiga 1.60 return msg
645    
646 slacapra 1.86 def SE2CMS(dests):
647 slacapra 1.85 """
648     Trasnsform a list of SE grid name into a list SE according to CMS naming convention
649     input: array of SE grid names
650     output: array of SE CMS names
651     """
652     from ProdCommon.SiteDB.CmsSiteMapper import SECmsMap
653     se_cms = SECmsMap()
654     SEDestination = [se_cms[d] for d in dests]
655     return SEDestination
656 spiga 1.60
657 slacapra 1.86 def CE2CMS(dests):
658     """
659     Trasnsform a list of CE grid name into a list SE according to CMS naming convention
660     input: array of CE grid names
661     output: array of CE CMS names
662     """
663     from ProdCommon.SiteDB.CmsSiteMapper import CECmsMap
664     ce_cms = CECmsMap()
665     CEDestination = [ce_cms[d] for d in dests]
666     return CEDestination
667    
668 mcinquil 1.94 def checkLcgUtils( self ):
669     """
670     _checkLcgUtils_
671     check the lcg-utils version and report
672     """
673     import commands
674     cmd = "lcg-cp --version | grep lcg_util"
675     status, output = commands.getstatusoutput( cmd )
676     num_ver = -1
677     if output.find("not found") == -1 or status == 0:
678     temp = output.split("-")
679     version = ""
680     if len(temp) >= 2:
681     version = output.split("-")[1]
682     temp = version.split(".")
683     if len(temp) >= 1:
684     num_ver = int(temp[0])*10
685     num_ver += int(temp[1])
686     return num_ver
687    
688 gutsche 1.20 ####################################
689 nsmirnov 1.4 if __name__ == '__main__':
690     print 'sys.argv[1] =',sys.argv[1]
691     list = parseRange2(sys.argv[1])
692     print list
693 slacapra 1.29 cksum = makeCksum("crab_util.py")
694     print cksum
695 ewv 1.44