pseek 2.1.2__tar.gz → 2.1.3__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.2
2
2
  Name: pseek
3
- Version: 2.1.2
3
+ Version: 2.1.3
4
4
  Summary: Pseek is a Python library to search files, folders, and text
5
5
  Home-page: https://github.com/ArianN8610/pysearch
6
6
  Author: Arian
@@ -100,3 +100,4 @@ pseek "error\d+" --regex
100
100
  | `--word` | Match the whole word only |
101
101
  | `--max-size`, `--min-size` | Specify maximum and minimum sizes for files and directories |
102
102
  | `--full-path` | Display full path of files and directories |
103
+ | `--no-content` | Only display files path for content search |
@@ -76,3 +76,4 @@ pseek "error\d+" --regex
76
76
  | `--word` | Match the whole word only |
77
77
  | `--max-size`, `--min-size` | Specify maximum and minimum sizes for files and directories |
78
78
  | `--full-path` | Display full path of files and directories |
79
+ | `--no-content` | Only display files path for content search |
@@ -29,8 +29,9 @@ from .searcher import Search
29
29
  @click.option('--min-size', type=click.FLOAT, help='Minimum file/directory size (in MB).')
30
30
  # Output option
31
31
  @click.option('--full-path', is_flag=True, help='Display full paths for results.')
32
+ @click.option('--no-content', is_flag=True, help='Only display files path for content search.')
32
33
  def search(query, path, file, directory, content, case_sensitive, ext, exclude_ext, regex,
33
- include, exclude, word, max_size, min_size, full_path):
34
+ include, exclude, word, max_size, min_size, full_path, no_content):
34
35
  """Search for files, directories, and file content based on the query."""
35
36
  # If no search type is specified, search in all types.
36
37
  if not any((file, directory, content)):
@@ -49,7 +50,8 @@ def search(query, path, file, directory, content, case_sensitive, ext, exclude_e
49
50
  whole_word=word,
50
51
  max_size=max_size,
51
52
  min_size=min_size,
52
- full_path=full_path
53
+ full_path=full_path,
54
+ no_content=no_content
53
55
  )
54
56
 
55
57
  total_results = 0
@@ -21,7 +21,7 @@ EXCLUDED_EXTENSIONS = {
21
21
 
22
22
  class Search:
23
23
  def __init__(self, base_path, query, case_sensitive, ext, exclude_ext, regex, include, exclude, whole_word,
24
- max_size, min_size, full_path):
24
+ max_size, min_size, full_path, no_content):
25
25
  """Initialize search parameters"""
26
26
  self.base_path = Path(base_path)
27
27
  self.query = query
@@ -35,6 +35,7 @@ class Search:
35
35
  self.max_size = max_size
36
36
  self.min_size = min_size
37
37
  self.full_path = full_path
38
+ self.no_content = no_content
38
39
  self.result = None
39
40
 
40
41
  def should_skip(self, p_resolved: Path, search_type: str) -> bool:
@@ -102,7 +103,7 @@ class Search:
102
103
  matches.append(f'{p_parent}\\{highlighted_name}')
103
104
  else: # content search
104
105
  # Use dictionary: key: file path (colored), value: list of line matches
105
- matches = {}
106
+ matches = {} if not self.no_content else set()
106
107
  # Compile binary version of the pattern
107
108
  pattern_bytes = re.compile(pattern.pattern.encode('utf-8'))
108
109
 
@@ -119,6 +120,14 @@ class Search:
119
120
  with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
120
121
  # Search for the pattern in the entire file as bytes
121
122
  if pattern_bytes.search(mm):
123
+ # Choose the file path format based on the full_path setting
124
+ file_label = str(file_path.resolve()) if self.full_path else str(file_path)
125
+
126
+ # Avoid searching through the entire file content if the fast-content flag is True
127
+ if self.no_content:
128
+ matches.add(click.style(file_label, fg='cyan'))
129
+ return
130
+
122
131
  lines = []
123
132
  mm.seek(0) # Move the cursor to the beginning of the file
124
133
 
@@ -149,8 +158,6 @@ class Search:
149
158
 
150
159
  # If any matching lines were found
151
160
  if lines:
152
- # Choose the file path format based on the full_path setting
153
- file_label = str(file_path.resolve()) if self.full_path else str(file_path)
154
161
  # Add the file and its matching lines to the results
155
162
  matches[click.style(file_label, fg='cyan')] = lines
156
163
  except Exception:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pseek
3
- Version: 2.1.2
3
+ Version: 2.1.3
4
4
  Summary: Pseek is a Python library to search files, folders, and text
5
5
  Home-page: https://github.com/ArianN8610/pysearch
6
6
  Author: Arian
@@ -100,3 +100,4 @@ pseek "error\d+" --regex
100
100
  | `--word` | Match the whole word only |
101
101
  | `--max-size`, `--min-size` | Specify maximum and minimum sizes for files and directories |
102
102
  | `--full-path` | Display full path of files and directories |
103
+ | `--no-content` | Only display files path for content search |
@@ -5,7 +5,7 @@ with open("README.md", encoding="utf-8") as f:
5
5
 
6
6
  setup(
7
7
  name="pseek",
8
- version="2.1.2",
8
+ version="2.1.3",
9
9
  author="Arian",
10
10
  author_email="ariannasiri86@gmail.com",
11
11
  description="Pseek is a Python library to search files, folders, and text",
File without changes
File without changes
File without changes
File without changes
File without changes