1 |
gutsche |
1.1 |
from crab_logger import Logger
|
2 |
|
|
from crab_exceptions import *
|
3 |
|
|
from crab_util import *
|
4 |
|
|
import common
|
5 |
|
|
|
6 |
|
|
import os, sys, time
|
7 |
|
|
|
8 |
|
|
class BlackWhiteListParser:
|
9 |
|
|
def __init__(self,cfg_params):
|
10 |
|
|
self.configure(cfg_params)
|
11 |
|
|
return
|
12 |
|
|
|
13 |
|
|
def configure(self, cfg_params):
|
14 |
|
|
|
15 |
|
|
SEBlackList = []
|
16 |
|
|
try:
|
17 |
|
|
tmpBad = string.split(cfg_params['EDG.se_black_list'],',')
|
18 |
|
|
for tmp in tmpBad:
|
19 |
|
|
tmp=string.strip(tmp)
|
20 |
|
|
SEBlackList.append(tmp)
|
21 |
|
|
except KeyError:
|
22 |
|
|
pass
|
23 |
|
|
common.logger.debug(5,'SEBlackList: '+str(SEBlackList))
|
24 |
|
|
self.reSEBlackList=[]
|
25 |
|
|
for bad in SEBlackList:
|
26 |
|
|
self.reSEBlackList.append(re.compile( string.lower(bad) ))
|
27 |
|
|
|
28 |
|
|
SEWhiteList = []
|
29 |
|
|
try:
|
30 |
|
|
tmpGood = string.split(cfg_params['EDG.se_white_list'],',')
|
31 |
|
|
for tmp in tmpGood:
|
32 |
|
|
tmp=string.strip(tmp)
|
33 |
|
|
SEWhiteList.append(tmp)
|
34 |
|
|
except KeyError:
|
35 |
|
|
pass
|
36 |
|
|
common.logger.debug(5,'SEWhiteList: '+str(SEWhiteList))
|
37 |
|
|
self.reSEWhiteList=[]
|
38 |
|
|
for good in SEWhiteList:
|
39 |
|
|
self.reSEWhiteList.append(re.compile( string.lower(good) ))
|
40 |
|
|
|
41 |
|
|
def checkBlackList(self, Sites, fileblocks):
|
42 |
|
|
"""
|
43 |
|
|
select sites that are not excluded by the user (via SE black list)
|
44 |
|
|
"""
|
45 |
|
|
goodSites = []
|
46 |
|
|
for aSite in Sites:
|
47 |
|
|
common.logger.debug(10,'Site '+aSite)
|
48 |
|
|
good=1
|
49 |
|
|
for re in self.reSEBlackList:
|
50 |
|
|
if re.search(string.lower(aSite)):
|
51 |
|
|
common.logger.debug(5,'SE in black list, skipping site '+aSite)
|
52 |
|
|
good=0
|
53 |
|
|
pass
|
54 |
|
|
if good: goodSites.append(aSite)
|
55 |
|
|
if len(goodSites) == 0:
|
56 |
|
|
msg = "No sites hosting the block %s after BlackList" % fileblocks
|
57 |
|
|
common.logger.debug(5,msg)
|
58 |
|
|
common.logger.debug(5,"Proceeding without this block.\n")
|
59 |
|
|
else:
|
60 |
|
|
common.logger.debug(5,"Selected sites for block "+str(fileblocks)+" via BlackList are "+str(goodSites)+"\n")
|
61 |
|
|
return goodSites
|
62 |
|
|
|
63 |
|
|
def checkWhiteList(self, Sites, fileblocks):
|
64 |
|
|
"""
|
65 |
|
|
select sites that are defined by the user (via SE white list)
|
66 |
|
|
"""
|
67 |
|
|
if len(self.reSEWhiteList)==0: return Sites
|
68 |
|
|
goodSites = []
|
69 |
|
|
for aSite in Sites:
|
70 |
|
|
good=0
|
71 |
|
|
for re in self.reSEWhiteList:
|
72 |
|
|
if re.search(string.lower(aSite)):
|
73 |
|
|
common.logger.debug(5,'SE in white list, adding site '+aSite)
|
74 |
|
|
good=1
|
75 |
|
|
pass
|
76 |
|
|
if good: goodSites.append(aSite)
|
77 |
|
|
|
78 |
|
|
if len(goodSites) == 0:
|
79 |
|
|
msg = "No sites hosting the block %s after WhiteList" % fileblocks
|
80 |
|
|
common.logger.debug(5,msg)
|
81 |
|
|
common.logger.debug(5,"Proceeding without this block.\n")
|
82 |
|
|
else:
|
83 |
|
|
common.logger.debug(5,"Selected sites for block "+str(fileblocks)+" via WhiteList are "+str(goodSites)+"\n")
|
84 |
|
|
|
85 |
|
|
return goodSites
|
86 |
fanzago |
1.1.2.1 |
|
87 |
|
|
def cleanForBlackWhiteList(self,destinations):
|
88 |
|
|
"""
|
89 |
|
|
clean for black/white lists using parser
|
90 |
|
|
"""
|
91 |
|
|
|
92 |
|
|
return ','.join(self.checkWhiteList(self.checkBlackList(destinations,''),''))
|
93 |
|
|
|