ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/GliteConfig.py
Revision: 1.11
Committed: Thu May 1 10:56:31 2008 UTC (17 years ago) by afanfani
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_2_2_pre4, CRAB_2_2_2_pre3, CRAB_2_2_2_pre2, CRAB_2_2_2_pre1, CRAB_2_2_1, CRAB_2_2_1_pre6, CRAB_2_2_1_pre5, CRAB_2_2_1_pre4, PRODCOMMON_0_10_7_testCS2, CRAB_2_2_1_pre3, CRAB_2_2_1_pre2, CRAB_2_2_1_pre1, CRAB_2_2_0, CRAB_2_2_0_pre21, CRAB_2_2_0_pre19, CRAB_2_2_0_pre18, CRAB_2_2_0_pre17, CRAB_2_2_0_pre16
Changes since 1.10: +5 -1 lines
Log Message:
if download from cmsdoc fails then keep using the local config

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     import urllib
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     f = urllib.urlopen(url)
23 mcinquil 1.9 ff = open(destination, 'w')
24 mcinquil 1.8 ff.write(f.read())
25     ff.close()
26     except IOError:
27     # 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     except:
45     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