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
|