aboutsummaryrefslogtreecommitdiff
path: root/packages/finder/plugin/searcher/file/name.py
blob: 97bba89f1e65f43bff5c45036c396a48354a4215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Finder searcher and browser REPL.
#
# Copyright (C) 2024 Silvio Rhatto <rhatto@riseup.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import re

class FinderPluginFileNameSearcher():
    # TODO: check if path exists
    def __init__(self, path):
        self.setPath(path)
        self.items = []

    def setPath(self, path):
        self.path  = path
        self.items = []

    async def finder(self):
      path = self.path

      for parent, dirs, files in os.walk(self.path):
          # Ignore Git folders
          if '.git' in dirs:
              dirs.remove('.git')
              continue

          # Currently we're not listing folders
          #for folder in dirs:
          #    self.items.append(os.path.join(parent, folder))

          for file in files:
              self.items.append(os.path.join(parent, file))

      return self.items

    def filter(self, text = ''):
        if text == '' or text is None:
            return self.items

        return filter(lambda s: re.match(".*" + re.escape(text) + ".*", s), self.items)