ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/GliteConfig.py
Revision: 1.15
Committed: Sun Sep 21 11:49:50 2008 UTC (16 years, 7 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_0_pre1
Changes since 1.14: +2 -1 lines
Log Message:
back to cmsdoc...waiting for cmsweb working properly

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.15 self.url = 'http://cmsdoc.cern.ch/cms/ccs/wm/www/Crab/useful_script/'
13     # self.url ='https://cmsweb.cern.ch/crabconf/files/'
14 fanzago 1.1 self.configFileName = 'glite.conf.CMS_'+str(RB)
15     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