ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/GliteConfig.py
Revision: 1.18
Committed: Tue Oct 7 14:02:25 2008 UTC (16 years, 6 months ago) by fanzago
Content type: text/x-python
Branch: MAIN
Changes since 1.17: +1 -1 lines
Log Message:
download of config file from https://cmsweb.cern.ch/crabconf/ and not https://cmsweb.cern.ch/crabconf/files

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 spiga 1.16 # self.url = 'http://cmsdoc.cern.ch/cms/ccs/wm/www/Crab/useful_script/'
13 fanzago 1.18 self.url ='https://cmsweb.cern.ch/crabconf/'
14 slacapra 1.17 self.configFileName = 'glite_wms_'+str(RB)+'.conf'
15 fanzago 1.1 self.theConfig = self.getConfig_()
16     pass
17    
18     def config(self):
19     return self.theConfig
20    
21 mcinquil 1.8 def downloadFile(self, url, destination):
22     try:
23 slacapra 1.12 f = urllib2.urlopen(url)
24 mcinquil 1.9 ff = open(destination, 'w')
25 mcinquil 1.8 ff.write(f.read())
26     ff.close()
27 slacapra 1.12 except urllib2.HTTPError:
28 mcinquil 1.8 # print 'Cannot access URL: '+url
29 mcinquil 1.9 raise CrabException('Cannot download config file '+destination+' from '+self.url)
30 mcinquil 1.8
31 fanzago 1.1 def getConfig_(self):
32 mcinquil 1.7 if not os.path.exists(self.configFileName):
33     url = self.url+self.configFileName
34 mcinquil 1.8 common.logger.message('Downloading config files for WMS: '+url)
35     self.downloadFile( url, self.configFileName)
36     else:
37     statinfo = os.stat(self.configFileName)
38 fanzago 1.10 ## if the file is older then 12 hours it is re-downloaded to update the configuration
39     oldness = 12*3600
40 mcinquil 1.8 if (time.time() - statinfo.st_ctime) > oldness:
41     url = self.url+self.configFileName
42     common.logger.message('Downloading config files for WMS: '+url)
43 afanfani 1.11 try:
44     self.downloadFile( url, self.configFileName)
45 slacapra 1.12 except CrabException:
46 afanfani 1.11 common.logger.message('Error downloading config files for WMS: %s . Keep using the local one.'%url)
47     pass
48 mcinquil 1.8 pass
49 spiga 1.5 return os.getcwd()+'/'+self.configFileName