Revision: | 1.24 |
Committed: | Thu Jun 25 10:40:26 2009 UTC (15 years, 10 months ago) by slacapra |
Content type: | text/x-python |
Branch: | MAIN |
CVS Tags: | CRAB_2_6_6_pre6, CRAB_2_6_6_pre5, CRAB_2_6_6_pre4, CRAB_2_6_6_pre3, CRAB_2_6_6_pre2, CRAB_2_6_6_check, CRAB_2_6_6, CRAB_2_6_6_pre1, CRAB_2_6_5, CRAB_2_6_5_pre1, CRAB_2_6_4, CRAB_2_6_4_pre1, CRAB_2_6_3_patch_2, CRAB_2_6_3_patch_2_pre2, CRAB_2_6_3_patch_2_pre1, CRAB_2_6_3_patch_1, CRAB_2_7_0_pre4, CRAB_2_7_0_pre3, CRAB_2_6_3, CRAB_2_6_3_pre5, CRAB_2_6_3_pre4, CRAB_2_6_3_pre3, CRAB_2_6_3_pre2, CRAB_2_7_0_pre2, CRAB_2_6_3_pre1, test_1, CRAB_2_7_0_pre1, CRAB_2_6_2, CRAB_2_6_2_pre2, CRAB_2_6_2_pre1, CRAB_2_6_1_pre4, CRAB_2_6_1_pre3, CRAB_2_6_1_pre2, CRAB_2_6_1_pre1, CRAB_2_6_1, CRAB_2_6_0 |
Branch point for: | CRAB_2_6_X_br |
Changes since 1.23: | +1 -1 lines |
Log Message: | changes to allows use of CREAM ce by setting GRID.use_cream = 1 |
# | User | Rev | Content |
---|---|---|---|
1 | fanzago | 1.1 | from crab_exceptions import * |
2 | from crab_util import * | ||
3 | import common | ||
4 | |||
5 | slacapra | 1.21 | import urllib |
6 | class MyUrlOpener(urllib.FancyURLopener): | ||
7 | def http_error_default(*args, **kwargs): | ||
8 | return urllib.URLopener.http_error_default(*args, **kwargs) | ||
9 | |||
10 | slacapra | 1.2 | import os, time |
11 | fanzago | 1.1 | |
12 | class GliteConfig: | ||
13 | def __init__(self, RB): | ||
14 | slacapra | 1.24 | common.logger.debug('Calling GliteConfig with WMS= '+str(RB)) |
15 | spiga | 1.16 | # self.url = 'http://cmsdoc.cern.ch/cms/ccs/wm/www/Crab/useful_script/' |
16 | spiga | 1.20 | self.url ='https://cmsweb.cern.ch/crabconf/' |
17 | slacapra | 1.22 | self.configFileName = 'glite_wms_'+str(RB)+'.conf' |
18 | fanzago | 1.1 | self.theConfig = self.getConfig_() |
19 | pass | ||
20 | |||
21 | def config(self): | ||
22 | return self.theConfig | ||
23 | |||
24 | mcinquil | 1.8 | def downloadFile(self, url, destination): |
25 | try: | ||
26 | slacapra | 1.21 | urllib._urlopener = MyUrlOpener() |
27 | f = urllib.urlopen(url) | ||
28 | mcinquil | 1.9 | ff = open(destination, 'w') |
29 | mcinquil | 1.8 | ff.write(f.read()) |
30 | ff.close() | ||
31 | slacapra | 1.21 | except IOError, msg: |
32 | raise CrabException('Cannot download config file '+destination+' from '+self.url+'\n'+str(msg)) | ||
33 | mcinquil | 1.8 | |
34 | fanzago | 1.1 | def getConfig_(self): |
35 | mcinquil | 1.7 | if not os.path.exists(self.configFileName): |
36 | url = self.url+self.configFileName | ||
37 | spiga | 1.23 | common.logger.info('Downloading config files for WMS: '+url) |
38 | mcinquil | 1.8 | self.downloadFile( url, self.configFileName) |
39 | else: | ||
40 | statinfo = os.stat(self.configFileName) | ||
41 | fanzago | 1.10 | ## if the file is older then 12 hours it is re-downloaded to update the configuration |
42 | oldness = 12*3600 | ||
43 | mcinquil | 1.8 | if (time.time() - statinfo.st_ctime) > oldness: |
44 | url = self.url+self.configFileName | ||
45 | spiga | 1.23 | common.logger.info('Downloading config files for WMS: '+url) |
46 | afanfani | 1.11 | try: |
47 | self.downloadFile( url, self.configFileName) | ||
48 | slacapra | 1.12 | except CrabException: |
49 | spiga | 1.23 | common.logger.info('Error downloading config files for WMS: %s . Keep using the local one.'%url) |
50 | afanfani | 1.11 | pass |
51 | mcinquil | 1.8 | pass |
52 | spiga | 1.5 | return os.getcwd()+'/'+self.configFileName |