ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ServerConfig.py
Revision: 1.8
Committed: Tue Sep 16 14:28:53 2008 UTC (16 years, 7 months ago) by spiga
Content type: text/x-python
Branch: MAIN
Changes since 1.7: +1 -1 lines
Log Message:
added correct url

File Contents

# Content
1 from crab_logger import Logger
2 from crab_exceptions import *
3 from crab_util import *
4 import common
5
6 import urllib
7 import os, time
8
9 class ServerConfig:
10 def __init__(self, serverName):
11 common.logger.debug(5,'Calling ServerConfig')
12 self.url ='https://cmsweb.cern.ch/crabconf/files/'
13 if 'server_' in string.lower(serverName):
14 self.configFileName = '%s.conf'%string.lower(serverName)
15 else:
16 self.configFileName = 'server_%s.conf'%string.lower(serverName)
17
18 localCfg = self.getConfig_()
19
20 # parse the localCfg file
21 f = open(localCfg, 'r')
22 l = ''.join( f.readlines() )
23 f.close()
24
25 if not l:
26 l = str('{}')
27 self.theConfig = eval(l)
28 pass
29
30 def config(self):
31 return self.theConfig
32
33 def downloadFile(self, url, destination):
34 try:
35 f = urllib.urlopen(url)
36 data = f.read()
37 if '<!' in data[:2]:
38 raise IOError
39
40 ff = open(destination, 'w')
41 ff.write(data)
42 ff.close()
43 except IOError:
44 raise CrabException('Cannot download config file '+destination+' from '+self.url)
45
46 def getConfig_(self):
47 if not os.path.exists(self.configFileName):
48 url = self.url+self.configFileName
49 common.logger.message('Downloading config files for '+url)
50 self.downloadFile( url, self.configFileName)
51 else:
52 statinfo = os.stat(self.configFileName)
53 ## if the file is older then 12 hours it is re-downloaded to update the configuration
54 oldness = 12*3600
55 if (time.time() - statinfo.st_ctime) > oldness:
56 url = self.url+self.configFileName
57 common.logger.message('Downloading config files for '+url)
58 self.downloadFile( url, self.configFileName)
59 pass
60 return os.getcwd()+'/'+self.configFileName
61
62
63