file_query_text 0.1.7__py3-none-any.whl → 0.1.9__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.
- file_query_text/__init__.py +1 -1
- file_query_text/grammar.py +10 -2
- file_query_text/main.py +24 -0
- {file_query_text-0.1.7.dist-info → file_query_text-0.1.9.dist-info}/METADATA +30 -2
- file_query_text-0.1.9.dist-info/RECORD +10 -0
- file_query_text-0.1.7.dist-info/RECORD +0 -10
- {file_query_text-0.1.7.dist-info → file_query_text-0.1.9.dist-info}/WHEEL +0 -0
- {file_query_text-0.1.7.dist-info → file_query_text-0.1.9.dist-info}/entry_points.txt +0 -0
- {file_query_text-0.1.7.dist-info → file_query_text-0.1.9.dist-info}/top_level.txt +0 -0
file_query_text/__init__.py
CHANGED
file_query_text/grammar.py
CHANGED
@@ -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
|
@@ -45,8 +46,15 @@ basic_condition = Group(IDENTIFIER + COMPARISON_OP + VALUE)
|
|
45
46
|
|
46
47
|
# Define logical expressions using infixNotation for better handling of AND and OR
|
47
48
|
condition_expr = Forward()
|
49
|
+
|
50
|
+
# Define a new pattern for the NOT LIKE operator
|
51
|
+
not_like_condition = Group(IDENTIFIER + NOT + LIKE + VALUE)
|
52
|
+
|
53
|
+
# Include both basic conditions and NOT LIKE conditions
|
54
|
+
basic_expr = basic_condition | not_like_condition
|
55
|
+
|
48
56
|
condition_expr <<= infixNotation(
|
49
|
-
|
57
|
+
basic_expr,
|
50
58
|
[
|
51
59
|
(NOT, 1, opAssoc.RIGHT),
|
52
60
|
(AND, 2, opAssoc.LEFT),
|
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":
|
@@ -139,6 +149,20 @@ def evaluate_conditions(file_path, condition):
|
|
139
149
|
elif len(expr) == 2 and expr[0] == "NOT":
|
140
150
|
return not eval_expr(expr[1])
|
141
151
|
|
152
|
+
# 4. Special case for NOT LIKE: [attr, 'NOT', 'LIKE', value]
|
153
|
+
elif len(expr) == 4 and expr[1] == "NOT" and expr[2] == "LIKE":
|
154
|
+
attr_val = get_file_attr(expr[0])
|
155
|
+
val = expr[3].strip("'") if isinstance(expr[3], str) else expr[3]
|
156
|
+
|
157
|
+
if attr_val is None:
|
158
|
+
return True # If attribute doesn't exist, NOT LIKE is True
|
159
|
+
|
160
|
+
# Convert SQL LIKE pattern (with % wildcards) to regex pattern
|
161
|
+
pattern = re.escape(val).replace('\\%', '%') # Unescape % after escaping everything else
|
162
|
+
pattern = pattern.replace("%", ".*")
|
163
|
+
pattern = f"^{pattern}$" # Anchor pattern to match whole string
|
164
|
+
return not bool(re.search(pattern, str(attr_val), re.IGNORECASE))
|
165
|
+
|
142
166
|
return False
|
143
167
|
|
144
168
|
return eval_expr(condition.asList())
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: file_query_text
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.9
|
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,32 @@ 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'"
|
130
|
+
```
|
131
|
+
|
132
|
+
### Excluding files with NOT LIKE
|
133
|
+
|
134
|
+
Find all JavaScript files in src directory except those in lib folders:
|
135
|
+
```
|
136
|
+
fq "path LIKE 'src%' AND path NOT LIKE '%lib%' AND extension == 'js'"
|
137
|
+
```
|
138
|
+
|
139
|
+
Find all Python files that don't have "test" in their name:
|
140
|
+
```
|
141
|
+
fq "extension == 'py' AND name NOT LIKE '%test%'"
|
114
142
|
```
|
@@ -0,0 +1,10 @@
|
|
1
|
+
file_query_text/__init__.py,sha256=DscljOkp8bJlAFVMhb6P8fV2gFzCHmf9BhSd60zI9Xg,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=shs5Vh30ybAhsrEjRmSaiUAtt1PKDHvw4nVJ6mktmBM,1906
|
5
|
+
file_query_text/main.py,sha256=cjp7FiyaRHN4rV8l5DsLN5ZYqfLir8nKC2vj70v30PI,8446
|
6
|
+
file_query_text-0.1.9.dist-info/METADATA,sha256=PlhAF2sao4kDe28BcIbi6fcgTWKXmUOgcALb7psYpY8,3058
|
7
|
+
file_query_text-0.1.9.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
file_query_text-0.1.9.dist-info/entry_points.txt,sha256=rNFYWzvcIsUZkGNsc_E_B5HyYRnqqdj_u8_IeQpw1wo,48
|
9
|
+
file_query_text-0.1.9.dist-info/top_level.txt,sha256=o1FzSvLa6kSV61b7RLHWRhEezc96m05YwIKqjuWUSxU,16
|
10
|
+
file_query_text-0.1.9.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,,
|
File without changes
|
File without changes
|
File without changes
|