ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/GliteConfig.py
Revision: 1.12
Committed: Mon Jun 9 15:36:08 2008 UTC (16 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_DLS_PHED1, CRAB_DLS_PHED, CRAB_2_3_2_Fnal, CRAB_2_3_2, CRAB_2_3_2_pre7, CRAB_2_3_2_pre5, CRAB_2_3_2_pre4, CRAB_2_3_2_pre3, CRAB_2_3_2_pre2, CRAB_2_3_2_pre1, CRAB_2_4_0_test, CRAB_2_3_1, CRAB_2_3_1_pre6, CRAB_2_3_1_pre5, CRAB_2_3_1_pre4, CRAB_2_3_1_pre3, CRAB_2_3_1_pre2, CRAB_2_3_1_pre1, CRAB_2_3_0, CRAB_2_3_0_pre6, CRAB_2_3_0_pre1, CRAB_2_2_2_pre5
Branch point for: AnaDataSet, CRAB_2_3_0_br
Changes since 1.11: +4 -4 lines
Log Message:
use urlib2 to catch 404 error from http

File Contents

# User Rev Content
1 fanzago 1.1 from crab_logger import Logger
2     from crab_exceptions import *
3     from crab_util import *
4     import common
5    
6 slacapra 1.12 import urllib2
7 slacapra 1.2 import os, time
8 fanzago 1.1
9     class GliteConfig:
10     def __init__(self, RB):
11     common.logger.debug(5,'Calling GliteConfig')
12     self.url = 'http://cmsdoc.cern.ch/cms/ccs/wm/www/Crab/useful_script/'
13     self.configFileName = 'glite.conf.CMS_'+str(RB)
14     self.theConfig = self.getConfig_()
15     pass
16    
17     def config(self):
18     return self.theConfig
19    
20 mcinquil 1.8 def downloadFile(self, url, destination):
21     try:
22 slacapra 1.12 f = urllib2.urlopen(url)
23 mcinquil 1.9 ff = open(destination, 'w')
24 mcinquil 1.8 ff.write(f.read())
25     ff.close()
26 slacapra 1.12 except urllib2.HTTPError:
27 mcinquil 1.8 # print 'Cannot access URL: '+url
28 mcinquil 1.9 raise CrabException('Cannot download config file '+destination+' from '+self.url)
29 mcinquil 1.8
30 fanzago 1.1 def getConfig_(self):
31 mcinquil 1.7 if not os.path.exists(self.configFileName):
32     url = self.url+self.configFileName
33 mcinquil 1.8 common.logger.message('Downloading config files for WMS: '+url)
34     self.downloadFile( url, self.configFileName)
35     else:
36     statinfo = os.stat(self.configFileName)
37 fanzago 1.10 ## if the file is older then 12 hours it is re-downloaded to update the configuration
38     oldness = 12*3600
39 mcinquil 1.8 if (time.time() - statinfo.st_ctime) > oldness:
40     url = self.url+self.configFileName
41     common.logger.message('Downloading config files for WMS: '+url)
42 afanfani 1.11 try:
43     self.downloadFile( url, self.configFileName)
44 slacapra 1.12 except CrabException:
45 afanfani 1.11 common.logger.message('Error downloading config files for WMS: %s . Keep using the local one.'%url)
46     pass
47 mcinquil 1.8 pass
48 spiga 1.5 return os.getcwd()+'/'+self.configFileName