ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ServerConfig.py
Revision: 1.9
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.8: +2 -1 lines
Log Message:
back to cmsdoc...waiting for cmsweb working properly

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