From c7036db210e54e4c089a49c2f4ae6fe7a8fa8913 Mon Sep 17 00:00:00 2001
From: Romain Broucquart <romain.broucquart@synchrotron-soleil.fr>
Date: Tue, 24 May 2022 18:34:21 +0200
Subject: [PATCH] Add a find attribute feature

---
 core/ArchiveExtractor.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/core/ArchiveExtractor.py b/core/ArchiveExtractor.py
index edfced8..6e1c1d3 100755
--- a/core/ArchiveExtractor.py
+++ b/core/ArchiveExtractor.py
@@ -82,6 +82,9 @@ class ArchiveExtractor:
         self.extractor.set_timeout_millis(3000)
         self.logger.debug("Archive Extractor %s used."%self.extractor.name())
 
+        # Get the attribute table
+        self.attr_table = self.extractor.getattnameall()
+
     ##---------------------------------------------------------------------------##
     @staticmethod
     def dateparse(datestr):
@@ -510,6 +513,29 @@ class ArchiveExtractor:
 
         return cdates
 
+    def findattr(self, pattern):
+        """
+        Search for an attribute path using the pattern given.
+        Case insensitive.
+
+        Parameters:
+        -----------
+        pattern: str
+            Pattern to search, wildchar * accepted.
+            example "dg*dcct*current"
+
+        Returns:
+        --------
+        results: (str,)
+            List of string match
+        """
+        keywords=pattern.lower().split('*')
+
+        matches = [attr for attr in self.attr_table if all(k in attr.lower() for k in keywords)]
+
+        return matches
+
+
     def infoattr(self, attribute):
         """
         Get informations for an attribute and pack it into a python dict.
-- 
GitLab