pseek 2.2.0__tar.gz → 2.3.1__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.0
3
+ Version: 2.3.1
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
@@ -38,8 +38,8 @@ pip install pseek
38
38
 
39
39
  ```sh
40
40
  git clone https://github.com/ArianN8610/pysearch.git
41
- cd pseek
42
- pip install click==8.1.8
41
+ cd pysearch
42
+ pip install click==8.1.8 lark==1.2.2
43
43
  ```
44
44
 
45
45
  ## Usage
@@ -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 |
@@ -24,8 +24,8 @@ pip install pseek
24
24
 
25
25
  ```sh
26
26
  git clone https://github.com/ArianN8610/pysearch.git
27
- cd pseek
28
- pip install click==8.1.8
27
+ cd pysearch
28
+ pip install click==8.1.8 lark==1.2.2
29
29
  ```
30
30
 
31
31
  ## Usage
@@ -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,7 +126,7 @@ 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
@@ -170,7 +170,7 @@ class Search:
170
170
 
171
171
  # Filter files before processing
172
172
  files_to_process = {
173
- p for p in self.base_path.rglob('*') if not self.should_skip(p, 'content')
173
+ p for p in self.base_path.rglob('*') if not self.should_skip(p.resolve(), 'content')
174
174
  }
175
175
 
176
176
  with ThreadPoolExecutor(max_workers=8) as executor:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pseek
3
- Version: 2.2.0
3
+ Version: 2.3.1
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
@@ -38,8 +38,8 @@ pip install pseek
38
38
 
39
39
  ```sh
40
40
  git clone https://github.com/ArianN8610/pysearch.git
41
- cd pseek
42
- pip install click==8.1.8
41
+ cd pysearch
42
+ pip install click==8.1.8 lark==1.2.2
43
43
  ```
44
44
 
45
45
  ## Usage
@@ -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.0"
7
+ version = "2.3.1"
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