file_query_text 0.1.7__py3-none-any.whl → 0.1.8__py3-none-any.whl

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.
@@ -2,4 +2,4 @@
2
2
  SQL-like interface for querying files in your filesystem.
3
3
  """
4
4
 
5
- __version__ = "0.1.7"
5
+ __version__ = "0.1.8"
@@ -27,6 +27,7 @@ WHERE = Suppress(CaselessKeyword("WHERE"))
27
27
  AND = CaselessKeyword("AND")
28
28
  OR = CaselessKeyword("OR")
29
29
  NOT = CaselessKeyword("NOT")
30
+ LIKE = CaselessKeyword("LIKE")
30
31
 
31
32
  # Define identifiers and literals
32
33
  IDENTIFIER = Word(alphas + "_")
@@ -36,7 +37,7 @@ NUMERIC_LITERAL = pyparsing_common.integer
36
37
  DIRECTORY_LIST = Group(delimitedList(STRING_LITERAL))
37
38
 
38
39
  # Define comparison operators
39
- COMPARISON_OP = oneOf("= == != <> < <= > >=")
40
+ COMPARISON_OP = oneOf("= == != <> < <= > >=") | LIKE
40
41
  ATTRIBUTE = IDENTIFIER + Suppress("=") + STRING_LITERAL
41
42
 
42
43
  # Define basic condition with support for both string and numeric literals
file_query_text/main.py CHANGED
@@ -3,6 +3,7 @@ import sys
3
3
  from file_query_text.grammar import query # Import the fixed grammar
4
4
  import file_query_text.gitignore_parser as gitignore_parser
5
5
  import os.path
6
+ import re
6
7
 
7
8
 
8
9
  def parse_query(query_str):
@@ -128,6 +129,15 @@ def evaluate_conditions(file_path, condition):
128
129
  if op == "<=": return attr_val is not None and int(attr_val) <= int(val)
129
130
  if op == ">": return attr_val is not None and int(attr_val) > int(val)
130
131
  if op == ">=": return attr_val is not None and int(attr_val) >= int(val)
132
+ if op.upper() == "LIKE":
133
+ if attr_val is None:
134
+ return False
135
+ # Convert SQL LIKE pattern (with % wildcards) to regex pattern
136
+ # Escape any regex special characters in the pattern except %
137
+ pattern = re.escape(val).replace('\\%', '%') # Unescape % after escaping everything else
138
+ pattern = pattern.replace("%", ".*")
139
+ pattern = f"^{pattern}$" # Anchor pattern to match whole string
140
+ return bool(re.search(pattern, str(attr_val), re.IGNORECASE))
131
141
 
132
142
  # 2. Logical operations from infixNotation: [left, op, right]
133
143
  elif expr[1] == "AND":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: file_query_text
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: SQL-like interface for querying files in your filesystem
5
5
  Author-email: nik <42a11b@nikdav.is>
6
6
  License-Expression: MIT
@@ -14,7 +14,7 @@ Requires-Dist: pyparsing>=3.2.3
14
14
  Provides-Extra: dev
15
15
  Requires-Dist: pytest>=8.3.5; extra == "dev"
16
16
 
17
- # File Query
17
+ # File Query (fq)
18
18
 
19
19
  A SQL-like interface for querying files in your filesystem.
20
20
 
@@ -111,4 +111,20 @@ fq "SELECT * FROM '.' WHERE (extension == 'jpg' OR extension == 'png') AND size
111
111
 
112
112
  # Find files with 'config' in their path
113
113
  fq "path == '.*config.*'"
114
+
115
+ ### Using wildcards with the LIKE operator
116
+
117
+ Find all Python files with "test" in their name:
118
+ ```
119
+ fq "name LIKE '%test%.py'"
120
+ ```
121
+
122
+ Find all files with a specific prefix:
123
+ ```
124
+ fq "name LIKE 'config%'"
125
+ ```
126
+
127
+ Find all markdown files in a specific year's folder:
128
+ ```
129
+ fq "path LIKE '%/2023/%' AND extension == 'md'"
114
130
  ```
@@ -0,0 +1,10 @@
1
+ file_query_text/__init__.py,sha256=-84ne-3HrCOzvhTwsN8M7-xOwSv24H1wen5OvnEo6_s,89
2
+ file_query_text/cli.py,sha256=eijCT1pHk4wtBhhmFHyeTOoLNz0zwk7Bm4izRLrjZb4,3709
3
+ file_query_text/gitignore_parser.py,sha256=PZk5MKyW5e8NXCyfC8w3r2JIp1HeF5CpZ5MdXOWlPNM,7734
4
+ file_query_text/grammar.py,sha256=mnyOd4UPg489Z-HQcxEySI41H02iDZRBbpaL3-mOFMU,1693
5
+ file_query_text/main.py,sha256=YswvqX-4yLGZ_qSTFBUjFxG7OAoLyB9FQ2PIVY-CpoU,7688
6
+ file_query_text-0.1.8.dist-info/METADATA,sha256=EPLhtU8ysQfuEo9pZGv7hVRa8YOeiCgSZIEgi7q6Shk,2753
7
+ file_query_text-0.1.8.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ file_query_text-0.1.8.dist-info/entry_points.txt,sha256=rNFYWzvcIsUZkGNsc_E_B5HyYRnqqdj_u8_IeQpw1wo,48
9
+ file_query_text-0.1.8.dist-info/top_level.txt,sha256=o1FzSvLa6kSV61b7RLHWRhEezc96m05YwIKqjuWUSxU,16
10
+ file_query_text-0.1.8.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- file_query_text/__init__.py,sha256=0koRSyAOr7mcK_M2meJyNhIJ9Bu-dOUa-wR1SJdXvw4,89
2
- file_query_text/cli.py,sha256=eijCT1pHk4wtBhhmFHyeTOoLNz0zwk7Bm4izRLrjZb4,3709
3
- file_query_text/gitignore_parser.py,sha256=PZk5MKyW5e8NXCyfC8w3r2JIp1HeF5CpZ5MdXOWlPNM,7734
4
- file_query_text/grammar.py,sha256=XanSi9VCKuIQNlOMXRBZbeWxaJj2UhMJPDIYKgw4lEQ,1655
5
- file_query_text/main.py,sha256=PQGwULcO0R8MxMcWcyjcXbH6UyZZAgNOML2zACVVZu4,7060
6
- file_query_text-0.1.7.dist-info/METADATA,sha256=gx0dg_yfDf1x94hDMIDB4qwLb3Gsi03c_KslaM1GS_A,2440
7
- file_query_text-0.1.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- file_query_text-0.1.7.dist-info/entry_points.txt,sha256=rNFYWzvcIsUZkGNsc_E_B5HyYRnqqdj_u8_IeQpw1wo,48
9
- file_query_text-0.1.7.dist-info/top_level.txt,sha256=o1FzSvLa6kSV61b7RLHWRhEezc96m05YwIKqjuWUSxU,16
10
- file_query_text-0.1.7.dist-info/RECORD,,