|
9 | 9 | """ |
10 | 10 |
|
11 | 11 | import os |
| 12 | +import re |
12 | 13 | from urllib.request import urlopen |
13 | 14 |
|
14 | 15 | from typing import ( |
@@ -123,7 +124,7 @@ def _get_hsilo_urn(self, hsilo_object: dict, |
123 | 124 | suffix = '' |
124 | 125 | if container_item_index > 0: |
125 | 126 | suffix = '-' + str(container_item_index) |
126 | | - return ('urn:oo:hsilo:' + domain_base + ':' + |
| 127 | + return ('urn:hdp:oo:hsilo:' + domain_base + ':' + |
127 | 128 | container_base + suffix) |
128 | 129 |
|
129 | 130 | def _update(self, hdp_rules: Union[List, dict], |
@@ -178,6 +179,13 @@ def _get_filtered(self, hdp_filters: dict = None) -> dict: |
178 | 179 | if self._debug: |
179 | 180 | print('HDP._get_filtered hdp_filters', hdp_filters) |
180 | 181 |
|
| 182 | + if 'verum_urn' in hdp_filters: |
| 183 | + filtered = self._get_filtered_urn( |
| 184 | + filtered, hdp_filters['verum_urn']) |
| 185 | + if 'non_urn' in hdp_filters: |
| 186 | + filtered = self._get_filtered_urn( |
| 187 | + filtered, hdp_filters['non_urn'], False) |
| 188 | + |
181 | 189 | if 'verum_grupum' in hdp_filters: |
182 | 190 | filtered = self._get_filtered_grupum( |
183 | 191 | filtered, hdp_filters['verum_grupum']) |
@@ -229,6 +237,52 @@ def _get_filtered_grupum(self, hdp_current: dict, |
229 | 237 | # or grupum not in hdpgroup.hsilo.grupum): |
230 | 238 | return hdp_result |
231 | 239 |
|
| 240 | + def _get_filtered_urn(self, hdp_current: dict, |
| 241 | + urn_regex: str, present: bool = True) -> dict: |
| 242 | + """Filter (present/absent) urn_regex on hdp_current subnamespace |
| 243 | +
|
| 244 | + Args: |
| 245 | + hdp_current (dict): HDP current internal representation |
| 246 | + urn_regex (str): urn (group) to filter |
| 247 | + present (bool, optional): If the grupum must be present (True) or |
| 248 | + is an inverse filter (absent). Defaults to True. |
| 249 | +
|
| 250 | + Returns: |
| 251 | + dict: Filtered result |
| 252 | + """ |
| 253 | + if self._debug: |
| 254 | + print('HDP._get_filtered_urn', urn_regex, present, hdp_current) |
| 255 | + |
| 256 | + if len(hdp_current) == 0: |
| 257 | + return hdp_current |
| 258 | + |
| 259 | + hdp_result = deepcopy(hdp_current) |
| 260 | + |
| 261 | + try: |
| 262 | + pattern = re.compile(urn_regex) |
| 263 | + |
| 264 | + for hdpns in hdp_current: |
| 265 | + # print('ooooi', hdpns, pattern, |
| 266 | + # re.search(pattern, hdpns), present) |
| 267 | + # print('ooooi2', re.search(pattern, hdpns) is not None) |
| 268 | + if re.search(pattern, hdpns) is not None: |
| 269 | + if present: |
| 270 | + continue |
| 271 | + else: |
| 272 | + if not present: |
| 273 | + continue |
| 274 | + |
| 275 | + deleteditem = hdp_result.pop(hdpns, None) |
| 276 | + if self._debug: |
| 277 | + print('HDP._get_filtered_urn deleteditem', deleteditem) |
| 278 | + except Exception as e: |
| 279 | + print("HDP._get_filtered_urn:An exception occurred", e) |
| 280 | + print('Did the regex is valid? urn_regex [ ' + urn_regex + ' ]') |
| 281 | + print('ABORTING') |
| 282 | + return False |
| 283 | + |
| 284 | + return hdp_result |
| 285 | + |
232 | 286 | def _prepare(self, hdp_entry_point: str, is_startup: bool = False) -> bool: |
233 | 287 |
|
234 | 288 | if self._debug: |
|
0 commit comments