Skip to content

Commit

Permalink
Adding filter to list just files no dirs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iury O. G. Figueiredo committed Oct 27, 2019
1 parent bc4a6c5 commit 0ec3b41
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions vyapp/plugins/fsniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,31 @@ def set_wide(cls, event):
root.status.set_msg('Set wide search: %s' % FSniffer.wide)

def update_pattern(self, wid):
pattern = ' '.join(self.make_cmd(wid.get()))
root.status.set_msg('Unix locate cmd: %s' % pattern)
pattern = build_regex(wid.get(), '.*')
root.status.set_msg('File pattern: %s' % pattern)

def make_cmd(self, pattern):
# When FSniffer.wide is False it searches in the current
# Areavi instance project.
cmd = ['locate', '--limit', '50']
cmd = ['locate', '--limit', '200']
regex = build_regex(pattern, '.*')

if self.wide or not self.area.project:
cmd.extend(['--regexp', regex])
else:
cmd.extend(['--regexp', '%s.*%s' % (
self.area.project, regex)])

# Used to filter only files because locate doesn't support
# searching only for files.
cmd = '%s | %s' % (' '.join(cmd), '''while read -r file; do
[ -d "$file" ] || printf '%s\n' "$file"; done''')
return cmd

def run_cmd(self, pattern):
cmd = self.make_cmd(pattern)
child = Popen(cmd, stdout=PIPE, stderr=STDOUT,
encoding=self.area.charset)
encoding=self.area.charset, shell=True)

output = child.communicate()[0]
return output
Expand Down

0 comments on commit 0ec3b41

Please sign in to comment.