57 def __init__ (self, catalog=None):
58 super (PoolFileCatalog, self).__init__()
59 self.catalog = None
60
61 if catalog is None:
62
63 catalog = os.environ.get("POOL_CATALOG", self.DefaultCatalog)
64
65 if isinstance(catalog, str):
66 catalog = [catalog]
67
68 if not isinstance (catalog, (str, list)):
69 raise TypeError(
70 "catalog contact string should be a string or a list thereof! (got %r)"%
72
73 osp = os.path
74 def osp_exp(x):
75 return osp.expanduser(osp.expandvars(x))
76
77 def _handle_apcfile_old(x):
78 """ return $ATLAS_POOLCOND_PATH/poolcond/x
79 """
80 if 'ATLAS_POOLCOND_PATH' not in os.environ:
81 return osp_exp(x)
82 pcp = os.environ["ATLAS_POOLCOND_PATH"]
83 if x.startswith("apcfile:"):
84 x = x[len("apcfile:"):]
85 return osp_exp(osp.join(pcp, 'poolcond', x))
86
87 def _handle_apcfile(x):
88 """ return $ATLAS_POOLCOND_PATH/x
89 """
90 if 'ATLAS_POOLCOND_PATH' not in os.environ:
91 return osp_exp(x)
92 pcp = os.environ["ATLAS_POOLCOND_PATH"]
93 if x.startswith("apcfile:"):
94 x = x[len("apcfile:"):]
95 return osp_exp(osp.join(pcp, x))
96
97 def _handle_xmlcatalog_file(x):
98 return osp_exp(x[len("xmlcatalog_file:"):])
99
100 def _handle_prfile(x):
101 x = x[len("prfile:"):]
102 x = osp_exp(x)
103 try:
104 import AthenaCommon.Utils.unixtools as u
105 return u.FindFile(x,
106 os.environ[
'DATAPATH'].
split(os.pathsep),
107 os.R_OK)
108 except ImportError:
109 return x
110
111 def _handle_file(x):
112 x = x[len("file:"):]
113 x = osp_exp(x)
114 return x
115
116 cat_dispatch = {
117 "xmlcatalog_file:": _handle_xmlcatalog_file,
118 "apcfile:": _handle_apcfile,
119 "prfile:": _handle_prfile,
120 "file:": _handle_file,
121 }
122 assert sorted(cat_dispatch.keys()) == sorted(self.AllowedProtocols), \
123 "catalog dispatch keys does not match AllowedProtocols:" \
124 "\n%s\n%s" % (sorted(cat_dispatch.keys()),
125 sorted(self.AllowedProtocols))
126
127 from . import xmldict
128 def _build_catalog(catalog):
129 if not catalog.startswith(self.AllowedProtocols):
130 raise ValueError(
131 "sorry PoolFile:PoolFileCatalog only supports %s"
132 " as a protocol for the POOL file catalog (got: '%s')"
133 % (self.AllowedProtocols, catalog)
134 )
135 for protocol, handler in cat_dispatch.iteritems():
136 if catalog.startswith(protocol):
138 break
139
140 import os
141
142 if not os.path.exists (catalog):
143 return {}
144
145
146
147
148
149 root = xmldict.ElementTree.parse (catalog).getroot()
150 return dict(xmldict.xml2dict(root))
151
152 errors = []
153 cat = {'POOLFILECATALOG':{'File':[]}}
154 for c in catalog:
155 try:
156 bc = _build_catalog(c)
157 pc = bc.get('POOLFILECATALOG',{})
158 files = []
159 if pc:
160 files = pc.get('File',[])
161 if isinstance(files, dict):
162 files = [files]
163 cat['POOLFILECATALOG']['File'].extend(files)
164 except Exception as err:
165 errors.append(err)
166
167 if errors:
168 raise errors[0]
169
170 self.catalog = cat
171 pass
172
std::vector< std::string > split(const std::string &s, const std::string &t=":")
void handler(int sig)
signal handler