pseek 2.2.1__tar.gz → 2.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pseek
3
- Version: 2.2.1
3
+ Version: 2.3.2
4
4
  Summary: Pseek is a Python library to search files, folders, and text
5
5
  Author-email: Arian <ariannasiri86@gmail.com>
6
6
  License-Expression: MIT
@@ -90,6 +90,7 @@ pseek "error\d+" --regex
90
90
  | `--re-include`, `--re-exclude` | Limit search results to specific directories or files with regex |
91
91
  | `--word` | Match the whole word only (except when --expr is enabled, in which case you can make it match whole word by putting w before term: w"foo") |
92
92
  | `--expr` | Enable to write conditions in the query. Example: r"foo.*bar" and ("bar" or "baz") and not "qux" (To use regex, word, and case-sensitive features, you can use the prefixes r, w, and c before terms. Allowed modes: r, w, c, wc, cw, rc, cr. Examples: r"foo.*bar", wc"Foo", cr".*Foo", ...) |
93
+ | `--timeout` | To stop the search after a specified period of time (Seconds) |
93
94
  | `--max-size`, `--min-size` | Specify maximum and minimum sizes for files and directories |
94
95
  | `--full-path` | Display full path of files and directories |
95
96
  | `--no-content` | Only display files path for content search |
@@ -76,6 +76,7 @@ pseek "error\d+" --regex
76
76
  | `--re-include`, `--re-exclude` | Limit search results to specific directories or files with regex |
77
77
  | `--word` | Match the whole word only (except when --expr is enabled, in which case you can make it match whole word by putting w before term: w"foo") |
78
78
  | `--expr` | Enable to write conditions in the query. Example: r"foo.*bar" and ("bar" or "baz") and not "qux" (To use regex, word, and case-sensitive features, you can use the prefixes r, w, and c before terms. Allowed modes: r, w, c, wc, cw, rc, cr. Examples: r"foo.*bar", wc"Foo", cr".*Foo", ...) |
79
+ | `--timeout` | To stop the search after a specified period of time (Seconds) |
79
80
  | `--max-size`, `--min-size` | Specify maximum and minimum sizes for files and directories |
80
81
  | `--full-path` | Display full path of files and directories |
81
82
  | `--no-content` | Only display files path for content search |
@@ -1,5 +1,26 @@
1
1
  import click
2
2
  from .searcher import Search
3
+ from multiprocessing import Process
4
+
5
+
6
+ def run_search_process(file, directory, content, ext, exclude_ext, search_instance):
7
+ """Performs the basic search operation"""
8
+ total_results = 0
9
+
10
+ # Search for files if requested.
11
+ if file:
12
+ total_results += search_instance.search('file').echo('Files', 'file')
13
+ # Search for directories if requested and extension filters are not active.
14
+ if directory and not (ext or exclude_ext):
15
+ total_results += search_instance.search('directory').echo('Directories', 'directory')
16
+ # Search for content inside files if requested.
17
+ if content:
18
+ total_results += search_instance.search('content').echo('Contents', 'content')
19
+
20
+ # Display final summary message.
21
+ message = f'\nTotal results: {total_results}' if total_results else 'No results found'
22
+ click.echo(click.style(message, fg='red'))
23
+
3
24
 
4
25
 
5
26
  @click.command()
@@ -28,6 +49,8 @@ from .searcher import Search
28
49
  '(To use regex, word, and case-sensitive features, '
29
50
  'you can use the prefixes r, w, and c before terms. Allowed modes: r, w, c, wc, cw, rc, cr. '
30
51
  'Examples: r"foo.*bar", wc"Foo", cr".*Foo", ...)')
52
+ @click.option('--timeout', type=click.INT,
53
+ help='To stop the search after a specified period of time (Seconds)')
31
54
  # Extension filters
32
55
  @click.option('--ext', multiple=True, type=click.STRING,
33
56
  help='Include files with these extensions. Example: --ext py --ext js')
@@ -49,7 +72,7 @@ from .searcher import Search
49
72
  @click.option('--full-path', is_flag=True, help='Display full paths for results.')
50
73
  @click.option('--no-content', is_flag=True, help='Only display files path for content search.')
51
74
  def search(query, path, file, directory, content, case_sensitive, ext, exclude_ext, regex, include, exclude,
52
- re_include, re_exclude, word, expr, max_size, min_size, full_path, no_content):
75
+ re_include, re_exclude, word, expr, timeout, max_size, min_size, full_path, no_content):
53
76
  """Search for files, directories, and file content based on the query."""
54
77
  # If no search type is specified, search in all types.
55
78
  if not any((file, directory, content)):
@@ -75,21 +98,21 @@ def search(query, path, file, directory, content, case_sensitive, ext, exclude_e
75
98
  no_content=no_content
76
99
  )
77
100
 
78
- total_results = 0
79
-
80
- # Search for files if requested.
81
- if file:
82
- total_results += search_instance.search('file').echo('Files', 'file')
83
- # Search for directories if requested and extension filters are not active.
84
- if directory and not (ext or exclude_ext):
85
- total_results += search_instance.search('directory').echo('Directories', 'directory')
86
- # Search for content inside files if requested.
87
- if content:
88
- total_results += search_instance.search('content').echo('Contents', 'content')
101
+ # Stop search if it exceeds timeout with multiprocessing
102
+ if timeout:
103
+ p = Process(
104
+ target=run_search_process,
105
+ args=(file, directory, content, ext, exclude_ext, search_instance)
106
+ )
107
+ p.start()
108
+ p.join(timeout)
89
109
 
90
- # Display final summary message.
91
- message = f'\nTotal results: {total_results}' if total_results else 'No results found'
92
- click.echo(click.style(message, fg='red'))
110
+ if p.is_alive():
111
+ p.terminate()
112
+ p.join()
113
+ click.echo(click.style(f"\nTimeout! Search exceeded {timeout} seconds and was stopped.", fg="red"))
114
+ else:
115
+ run_search_process(file, directory, content, ext, exclude_ext, search_instance)
93
116
 
94
117
 
95
118
  if __name__ == "__main__":
@@ -126,14 +126,14 @@ class Search:
126
126
  except UnicodeDecodeError:
127
127
  return
128
128
 
129
- if not pattern.evaluate(content):
129
+ if not pattern.evaluate(content) and not self.expr:
130
130
  return
131
131
 
132
132
  # Choose the file path format based on the full_path setting
133
133
  file_label = str(file_path.resolve()) if self.full_path else str(file_path)
134
134
 
135
135
  # Avoid searching through the entire file content if the fast-content flag is True
136
- if self.no_content:
136
+ if self.no_content and not self.expr:
137
137
  matches.add(click.style(file_label, fg='cyan'))
138
138
  return
139
139
 
@@ -151,6 +151,9 @@ class Search:
151
151
 
152
152
  # If the pattern matches in the decoded line
153
153
  if pattern.evaluate(line_decoded):
154
+ if self.no_content and self.expr:
155
+ matches.add(click.style(file_label, fg='cyan'))
156
+ return
154
157
  count = pattern.count_matches(line_decoded) if isinstance(pattern, TermNode) else 0
155
158
  # Highlight the matching parts in green
156
159
  highlighted = highlight_text_safe(pattern, line_decoded)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pseek
3
- Version: 2.2.1
3
+ Version: 2.3.2
4
4
  Summary: Pseek is a Python library to search files, folders, and text
5
5
  Author-email: Arian <ariannasiri86@gmail.com>
6
6
  License-Expression: MIT
@@ -90,6 +90,7 @@ pseek "error\d+" --regex
90
90
  | `--re-include`, `--re-exclude` | Limit search results to specific directories or files with regex |
91
91
  | `--word` | Match the whole word only (except when --expr is enabled, in which case you can make it match whole word by putting w before term: w"foo") |
92
92
  | `--expr` | Enable to write conditions in the query. Example: r"foo.*bar" and ("bar" or "baz") and not "qux" (To use regex, word, and case-sensitive features, you can use the prefixes r, w, and c before terms. Allowed modes: r, w, c, wc, cw, rc, cr. Examples: r"foo.*bar", wc"Foo", cr".*Foo", ...) |
93
+ | `--timeout` | To stop the search after a specified period of time (Seconds) |
93
94
  | `--max-size`, `--min-size` | Specify maximum and minimum sizes for files and directories |
94
95
  | `--full-path` | Display full path of files and directories |
95
96
  | `--no-content` | Only display files path for content search |
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pseek"
7
- version = "2.2.1"
7
+ version = "2.3.2"
8
8
  description = "Pseek is a Python library to search files, folders, and text"
9
9
  readme = "README.md"
10
10
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes