file_query_text 0.1.9__py3-none-any.whl → 0.1.11__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.9"
5
+ __version__ = "0.1.11"
file_query_text/cli.py CHANGED
@@ -86,7 +86,7 @@ def main():
86
86
  if args.debug:
87
87
  # Print all attributes in debug mode
88
88
  attrs = get_file_attributes(file_path)
89
- print(f"{attrs['extension']:<15} {attrs['name']:<30} {attrs['size']:<10} {attrs['relative_path']}")
89
+ print(f"{attrs['extension']:<15} {attrs['name']:<30} {attrs['size']:<10} {attrs['path']}")
90
90
  else:
91
91
  # Standard output
92
92
  print(file_path)
file_query_text/main.py CHANGED
@@ -97,6 +97,14 @@ def evaluate_conditions(file_path, condition):
97
97
  if not condition:
98
98
  return True
99
99
 
100
+ # Get the relative path for comparison
101
+ cwd = os.getcwd()
102
+ try:
103
+ relative_path = os.path.relpath(file_path, cwd)
104
+ except ValueError:
105
+ # Handle case when on different drives (Windows)
106
+ relative_path = file_path
107
+
100
108
  def get_file_attr(attr_name):
101
109
  if attr_name == "extension":
102
110
  return os.path.splitext(file_path)[1][1:]
@@ -105,7 +113,7 @@ def evaluate_conditions(file_path, condition):
105
113
  if attr_name == "size":
106
114
  return os.path.getsize(file_path)
107
115
  if attr_name == "path":
108
- return file_path
116
+ return relative_path # Use relative path instead of absolute
109
117
  # Add more attributes as needed
110
118
  return None
111
119
 
@@ -119,7 +127,8 @@ def evaluate_conditions(file_path, condition):
119
127
 
120
128
  # 1. Basic condition: [attr, op, value]
121
129
  if isinstance(expr[0], str) and isinstance(expr[1], str):
122
- attr_val = get_file_attr(expr[0])
130
+ attr_name = expr[0]
131
+ attr_val = get_file_attr(attr_name)
123
132
  op = expr[1]
124
133
  val = expr[2].strip("'") if isinstance(expr[2], str) else expr[2] # Remove quotes if string
125
134
 
@@ -130,14 +139,7 @@ def evaluate_conditions(file_path, condition):
130
139
  if op == ">": return attr_val is not None and int(attr_val) > int(val)
131
140
  if op == ">=": return attr_val is not None and int(attr_val) >= int(val)
132
141
  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))
142
+ return check_like_condition(attr_val, val)
141
143
 
142
144
  # 2. Logical operations from infixNotation: [left, op, right]
143
145
  elif expr[1] == "AND":
@@ -151,20 +153,28 @@ def evaluate_conditions(file_path, condition):
151
153
 
152
154
  # 4. Special case for NOT LIKE: [attr, 'NOT', 'LIKE', value]
153
155
  elif len(expr) == 4 and expr[1] == "NOT" and expr[2] == "LIKE":
154
- attr_val = get_file_attr(expr[0])
156
+ attr_name = expr[0]
157
+ attr_val = get_file_attr(attr_name)
155
158
  val = expr[3].strip("'") if isinstance(expr[3], str) else expr[3]
156
159
 
157
160
  if attr_val is None:
158
161
  return True # If attribute doesn't exist, NOT LIKE is True
159
162
 
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))
163
+ return not check_like_condition(attr_val, val)
165
164
 
166
165
  return False
167
166
 
167
+ # Helper function to check LIKE conditions with proper pattern matching
168
+ def check_like_condition(attr_val, val):
169
+ if attr_val is None:
170
+ return False
171
+ # Convert SQL LIKE pattern (with % wildcards) to regex pattern
172
+ # Escape any regex special characters in the pattern except %
173
+ pattern = re.escape(val).replace('\\%', '%') # Unescape % after escaping everything else
174
+ pattern = pattern.replace("%", ".*")
175
+ pattern = f"^{pattern}$" # Anchor pattern to match whole string
176
+ return bool(re.search(pattern, str(attr_val), re.IGNORECASE))
177
+
168
178
  return eval_expr(condition.asList())
169
179
 
170
180
  # Function to get all attributes for a file
@@ -182,8 +192,7 @@ def get_file_attributes(file_path):
182
192
  "extension": os.path.splitext(file_path)[1][1:],
183
193
  "name": os.path.basename(file_path),
184
194
  "size": os.path.getsize(file_path),
185
- "path": file_path,
186
- "relative_path": rel_path,
195
+ "path": rel_path, # Use relative path for consistency
187
196
  }
188
197
  return attributes
189
198
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: file_query_text
3
- Version: 0.1.9
3
+ Version: 0.1.11
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
@@ -0,0 +1,10 @@
1
+ file_query_text/__init__.py,sha256=zU3FMXN8el2gf2nq_7pCZate3Q0N42hSDVQK9bDgy1c,90
2
+ file_query_text/cli.py,sha256=kIBLzYM2doMFVtrC6qP-85GcWeoftObOk-nUVxPxAto,3700
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=Td3zB-F9aV5q823ScOx1OF3_RQ654M-0EeQLxLcd6BU,8576
6
+ file_query_text-0.1.11.dist-info/METADATA,sha256=cNyBd7Lc2xpLMTG2dEUnWA0xnEBk16Yr2dKjoECv_Xg,3059
7
+ file_query_text-0.1.11.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ file_query_text-0.1.11.dist-info/entry_points.txt,sha256=rNFYWzvcIsUZkGNsc_E_B5HyYRnqqdj_u8_IeQpw1wo,48
9
+ file_query_text-0.1.11.dist-info/top_level.txt,sha256=o1FzSvLa6kSV61b7RLHWRhEezc96m05YwIKqjuWUSxU,16
10
+ file_query_text-0.1.11.dist-info/RECORD,,
@@ -1,10 +0,0 @@
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,,