You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/08/05 08:44:07 UTC

[GitHub] [airflow] saveriogzz commented on a change in pull request #15409: Support regex pattern in SFTPHOOK

saveriogzz commented on a change in pull request #15409:
URL: https://github.com/apache/airflow/pull/15409#discussion_r619141253



##########
File path: airflow/providers/sftp/hooks/sftp.py
##########
@@ -166,16 +168,21 @@ def describe_directory(self, path: str) -> Dict[str, Dict[str, str]]:
             }
         return files
 
-    def list_directory(self, path: str) -> List[str]:
+    def list_directory(self, path: str, regex_pattern: Optional[str] = None) -> List[str]:
         """
         Returns a list of files on the remote system.
 
         :param path: full path to the remote directory to list
         :type path: str
+        :param regex_pattern: optional pattern to filter the remote_full_path files
+        :type: regex_pattern: Optional[str]
         """
         conn = self.get_conn()
-        files = conn.listdir(path)
-        return files
+        if regex_pattern:
+            pattern = re.compile(regex_pattern)
+            return [file for file in conn.listdir(path) if pattern.match(file)]

Review comment:
       would the usage of a [generator](https://docs.python.org/3/whatsnew/3.3.html#pep-380) be a more efficient solution when encountering directories with many files?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org