8 |
|
|
9 |
|
class ServerConfig: |
10 |
|
def __init__(self, serverName): |
11 |
+ |
import string |
12 |
+ |
serverName = string.lower(serverName) |
13 |
|
common.logger.debug(5,'Calling ServerConfig') |
14 |
|
# self.url = 'http://cmsdoc.cern.ch/cms/ccs/wm/www/Crab/useful_script/' |
15 |
+ |
|
16 |
|
self.url ='https://cmsweb.cern.ch/crabconf/files/' |
17 |
< |
if 'server_' in string.lower(serverName): |
18 |
< |
self.configFileName = '%s.conf'%string.lower(serverName) |
17 |
> |
if 'default' in serverName: |
18 |
> |
common.logger.debug(5,'getting serverlist from web') |
19 |
> |
# get a list of available servers |
20 |
> |
serverListFileName ='AvalableServerList' |
21 |
> |
serverListFile = self.getConfig_(serverListFileName) |
22 |
> |
#f = urllib.urlopen('http://www.pd.infn.it/~lacaprar/Computing/'+serverListFileName) |
23 |
> |
# parse the localCfg file |
24 |
> |
f = open(serverListFile, 'r') |
25 |
> |
tmp = f.readlines() |
26 |
> |
f.close() |
27 |
> |
if not tmp: |
28 |
> |
msg = 'List of avalable Server '+serverListFileName+' from '+self.url+' is empty\n' |
29 |
> |
msg += 'Please report to CRAB feedback hypernews' |
30 |
> |
raise CrabException(msg) |
31 |
> |
# clean up empty lines and "\n" |
32 |
> |
serverList=[] |
33 |
> |
[serverList.append(string.strip(it)) for it in tmp if (it.strip() and not it.strip()[0]=="#")] |
34 |
> |
|
35 |
> |
# if more than one, pick up a random one, waiting for something smarter (SiteDB) |
36 |
> |
import random |
37 |
> |
serverName = random.choice(serverList) |
38 |
> |
common.logger.debug(5,'Avaialble servers: '+str(serverList)+' choosen: '+serverName) |
39 |
> |
common.logger.write('Avaialble servers: '+str(serverList)+' choosen: '+serverName) |
40 |
> |
if 'server_' in serverName: |
41 |
> |
configFileName = '%s.conf'%serverName |
42 |
|
else: |
43 |
< |
self.configFileName = 'server_%s.conf'%string.lower(serverName) |
43 |
> |
configFileName = 'server_%s.conf'%serverName |
44 |
|
|
45 |
< |
localCfg = self.getConfig_() |
45 |
> |
localCfg = self.getConfig_(configFileName) |
46 |
|
|
47 |
|
# parse the localCfg file |
48 |
|
f = open(localCfg, 'r') |
70 |
|
except IOError: |
71 |
|
raise CrabException('Cannot download config file '+destination+' from '+self.url) |
72 |
|
|
73 |
< |
def getConfig_(self): |
74 |
< |
if not os.path.exists(self.configFileName): |
75 |
< |
url = self.url+self.configFileName |
73 |
> |
def getConfig_(self, configFileName): |
74 |
> |
url = self.url+configFileName |
75 |
> |
if not os.path.exists(configFileName): |
76 |
|
common.logger.message('Downloading config files for '+url) |
77 |
< |
self.downloadFile( url, self.configFileName) |
77 |
> |
self.downloadFile( url, configFileName) |
78 |
|
else: |
79 |
< |
statinfo = os.stat(self.configFileName) |
79 |
> |
statinfo = os.stat(configFileName) |
80 |
|
## if the file is older then 12 hours it is re-downloaded to update the configuration |
81 |
|
oldness = 12*3600 |
82 |
|
if (time.time() - statinfo.st_ctime) > oldness: |
57 |
– |
url = self.url+self.configFileName |
83 |
|
common.logger.message('Downloading config files for '+url) |
84 |
< |
self.downloadFile( url, self.configFileName) |
84 |
> |
self.downloadFile( url, configFileName) |
85 |
|
pass |
86 |
< |
return os.getcwd()+'/'+self.configFileName |
62 |
< |
|
63 |
< |
|
64 |
< |
|
86 |
> |
return os.getcwd()+'/'+configFileName |