file_query_text 0.1.7__tar.gz → 0.1.8__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.
- {file_query_text-0.1.7 → file_query_text-0.1.8}/PKG-INFO +18 -2
- {file_query_text-0.1.7 → file_query_text-0.1.8}/README.md +17 -1
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text/__init__.py +1 -1
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text/grammar.py +2 -1
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text/main.py +10 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/PKG-INFO +18 -2
- {file_query_text-0.1.7 → file_query_text-0.1.8}/pyproject.toml +1 -1
- {file_query_text-0.1.7 → file_query_text-0.1.8}/tests/test_main.py +95 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text/cli.py +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text/gitignore_parser.py +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/SOURCES.txt +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/dependency_links.txt +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/entry_points.txt +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/requires.txt +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/top_level.txt +0 -0
- {file_query_text-0.1.7 → file_query_text-0.1.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: file_query_text
|
3
|
-
Version: 0.1.
|
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
|
```
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# File Query
|
1
|
+
# File Query (fq)
|
2
2
|
|
3
3
|
A SQL-like interface for querying files in your filesystem.
|
4
4
|
|
@@ -95,4 +95,20 @@ fq "SELECT * FROM '.' WHERE (extension == 'jpg' OR extension == 'png') AND size
|
|
95
95
|
|
96
96
|
# Find files with 'config' in their path
|
97
97
|
fq "path == '.*config.*'"
|
98
|
+
|
99
|
+
### Using wildcards with the LIKE operator
|
100
|
+
|
101
|
+
Find all Python files with "test" in their name:
|
102
|
+
```
|
103
|
+
fq "name LIKE '%test%.py'"
|
104
|
+
```
|
105
|
+
|
106
|
+
Find all files with a specific prefix:
|
107
|
+
```
|
108
|
+
fq "name LIKE 'config%'"
|
109
|
+
```
|
110
|
+
|
111
|
+
Find all markdown files in a specific year's folder:
|
112
|
+
```
|
113
|
+
fq "path LIKE '%/2023/%' AND extension == 'md'"
|
98
114
|
```
|
@@ -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
|
@@ -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.
|
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
|
```
|
@@ -432,3 +432,98 @@ def test_hidden_files(temp_dir):
|
|
432
432
|
# Also check if every visible file is in results
|
433
433
|
for visible_file in visible_files:
|
434
434
|
assert visible_file in with_hidden_files, f"Visible file {visible_file} missing from results"
|
435
|
+
|
436
|
+
def test_like_operator_with_wildcards(temp_dir):
|
437
|
+
"""Test LIKE operator with SQL-style percentage wildcards."""
|
438
|
+
# Create specific files with different naming patterns
|
439
|
+
with open(temp_dir / "docs/report_2023.pdf", "w") as f:
|
440
|
+
f.write("Test PDF report 2023")
|
441
|
+
with open(temp_dir / "docs/report_2024.pdf", "w") as f:
|
442
|
+
f.write("Test PDF report 2024")
|
443
|
+
with open(temp_dir / "docs/summary_2023.pdf", "w") as f:
|
444
|
+
f.write("Test PDF summary 2023")
|
445
|
+
with open(temp_dir / "docs/note_2023.txt", "w") as f:
|
446
|
+
f.write("Test TXT note 2023")
|
447
|
+
|
448
|
+
# Test LIKE with wildcard at beginning
|
449
|
+
query_str = f"""
|
450
|
+
SELECT *
|
451
|
+
FROM '{temp_dir}/docs'
|
452
|
+
WHERE name LIKE '%2023.pdf'
|
453
|
+
"""
|
454
|
+
|
455
|
+
parsed = parse_query(query_str)
|
456
|
+
visitor = QueryVisitor()
|
457
|
+
visitor.visit(parsed)
|
458
|
+
|
459
|
+
results = execute_query(
|
460
|
+
visitor.select,
|
461
|
+
visitor.from_dirs,
|
462
|
+
visitor.where
|
463
|
+
)
|
464
|
+
|
465
|
+
# Should match all 2023 PDF files
|
466
|
+
expected = [
|
467
|
+
str(temp_dir / "docs/report_2023.pdf"),
|
468
|
+
str(temp_dir / "docs/summary_2023.pdf")
|
469
|
+
]
|
470
|
+
|
471
|
+
# Normalize paths for comparison
|
472
|
+
actual = [str(p) for p in results]
|
473
|
+
assert sorted(actual) == sorted(expected)
|
474
|
+
|
475
|
+
# Test LIKE with wildcard in middle
|
476
|
+
query_str = f"""
|
477
|
+
SELECT *
|
478
|
+
FROM '{temp_dir}/docs'
|
479
|
+
WHERE name LIKE 'report%pdf'
|
480
|
+
"""
|
481
|
+
|
482
|
+
parsed = parse_query(query_str)
|
483
|
+
visitor = QueryVisitor()
|
484
|
+
visitor.visit(parsed)
|
485
|
+
|
486
|
+
results = execute_query(
|
487
|
+
visitor.select,
|
488
|
+
visitor.from_dirs,
|
489
|
+
visitor.where
|
490
|
+
)
|
491
|
+
|
492
|
+
# Should match all report PDF files
|
493
|
+
expected = [
|
494
|
+
str(temp_dir / "docs/report.pdf"),
|
495
|
+
str(temp_dir / "docs/report_2023.pdf"),
|
496
|
+
str(temp_dir / "docs/report_2024.pdf")
|
497
|
+
]
|
498
|
+
|
499
|
+
# Normalize paths for comparison
|
500
|
+
actual = [str(p) for p in results]
|
501
|
+
assert sorted(actual) == sorted(expected)
|
502
|
+
|
503
|
+
# Test LIKE with wildcards at both ends
|
504
|
+
query_str = f"""
|
505
|
+
SELECT *
|
506
|
+
FROM '{temp_dir}/docs'
|
507
|
+
WHERE name LIKE '%report%'
|
508
|
+
"""
|
509
|
+
|
510
|
+
parsed = parse_query(query_str)
|
511
|
+
visitor = QueryVisitor()
|
512
|
+
visitor.visit(parsed)
|
513
|
+
|
514
|
+
results = execute_query(
|
515
|
+
visitor.select,
|
516
|
+
visitor.from_dirs,
|
517
|
+
visitor.where
|
518
|
+
)
|
519
|
+
|
520
|
+
# Should match all files with 'report' in the name
|
521
|
+
expected = [
|
522
|
+
str(temp_dir / "docs/report.pdf"),
|
523
|
+
str(temp_dir / "docs/report_2023.pdf"),
|
524
|
+
str(temp_dir / "docs/report_2024.pdf")
|
525
|
+
]
|
526
|
+
|
527
|
+
# Normalize paths for comparison
|
528
|
+
actual = [str(p) for p in results]
|
529
|
+
assert sorted(actual) == sorted(expected)
|
File without changes
|
File without changes
|
File without changes
|
{file_query_text-0.1.7 → file_query_text-0.1.8}/file_query_text.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|