Skip to content

Commit

Permalink
use fnmatch for wildcarded subtopics
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Feb 21, 2024
1 parent eb7cc1c commit 606c970
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions msc_wis2node/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
###############################################################################

from datetime import date, datetime, timezone
from fnmatch import fnmatch
import json
import logging
import random
Expand Down Expand Up @@ -48,7 +49,6 @@ def after_accept(self, worklist) -> None:
:returns: None
"""

LOGGER.debug('JJJ')
new_incoming = []

for msg in worklist.incoming:
Expand Down Expand Up @@ -124,12 +124,12 @@ def identify(self, path: str) -> Union[dict, None]:
"""

for dataset in self.datasets:
LOGGER.debug(f"DATASETS: {self.datasets}")
LOGGER.debug(f'Dataset: {dataset}')
match = False
subtopic_dirpath = self._subtopic2dirpath(dataset['subtopic'])

LOGGER.debug(f'Testing subtopic match: {subtopic_dirpath}')
if path.startswith(subtopic_dirpath):
if fnmatch(path, subtopic_dirpath):
LOGGER.debug('Found matching subtopic')
match = True

Expand All @@ -145,6 +145,10 @@ def identify(self, path: str) -> Union[dict, None]:
if match:
LOGGER.debug('Found matching dataset definition')
return dataset
else:
LOGGER.debug('NO MATCH')
LOGGER.debug(path)
LOGGER.debug(subtopic_dirpath)

LOGGER.debug('No match found')

Expand Down Expand Up @@ -216,6 +220,7 @@ def _subtopic2dirpath(self, subtopic: str) -> str:
LOGGER.debug(f'AMQP subtopic: {subtopic}')

dirpath = '/' + subtopic.replace('.', '/').rstrip('/#')
dirpath = f'*{dirpath}*'

LOGGER.debug(f'directory path: {dirpath}')

Expand Down

0 comments on commit 606c970

Please sign in to comment.