Skip to content

Commit 17e3f63

Browse files
committed
Fix strings: Use ' instead of "
1 parent 4bf1588 commit 17e3f63

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

metayaml.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
from subprocess import Popen
1212
from pathlib import Path
1313
import logging
14-
from cachetools import cached, TTLCache
15-
from datetime import datetime, timedelta
1614
from tempfile import NamedTemporaryFile
1715
import re
1816

17+
operators = ["<", ">", "=", "<=", ">=", "in"]
18+
1919
def parse_string(s):
2020
if s == "True":
2121
return True
@@ -36,7 +36,6 @@ def merge(a, b, key=None):
3636
logging.info(f"overwrite {key} from '{b}' to '{a}'")
3737
return a
3838

39-
4039
def get_meta_data(path):
4140
yml_paths = []
4241
if os.path.isfile(path):
@@ -72,15 +71,15 @@ def create_rclone_rules(arg1, operator, arg2, directory, abs_path):
7271
arg1 = parse_string(arg1)
7372
arg2 = parse_string(arg2)
7473

75-
already_harmonized = lambda x: x.startswith('"') and x.endswith('"')
74+
already_harmonized = lambda x: x.startswith("'") and x.endswith(",")
7675
harmonize_string = (
77-
lambda x: f'"{x}"' if isinstance(x, str) and not already_harmonized(x) else x
76+
lambda x: f"'{x}'" if isinstance(x, str) and not already_harmonized(x) else x
7877
)
7978

8079
if operator == "=" and isinstance(arg2, bool):
8180
expr = f"m.get({harmonize_string(arg1)}) == {arg2}"
8281
elif operator == "=":
83-
expr = f"m.get({harmonize_string(arg1)}) == {harmonize_string(arg2)}"
82+
expr = f"m.get({harmonize_string(arg1)}) == {arg2}"
8483
elif operator in ["<", ">", "<=", ">=", "="] and isinstance(arg2, float):
8584
expr = f"m.get({harmonize_string(arg1)}) {operator} {harmonize_string(arg2)}"
8685
elif operator == "in":
@@ -161,8 +160,12 @@ def filter(query, directory, abs_path):
161160
metayaml filter "score > 5"
162161
metayaml filter "djohn in users"
163162
metayaml filter "is_example = True"
163+
metayaml find "description = 'foo' "
164164
"""
165-
arg1, operator, arg2 = [x for x in query.split(" ") if len(x) > 0]
165+
166+
arg1, arg2 = map(lambda x: x.strip(), re.split("|".join(operators), query))
167+
operator = re.findall("|".join(operators), query)[0]
168+
166169
for l in create_rclone_rules(arg1, operator, arg2, directory, abs_path):
167170
print(l)
168171

@@ -194,10 +197,13 @@ def find(query, directory, abs_path):
194197
metayaml find "score > 5"
195198
metayaml find "djohn in users"
196199
metayaml find "is_example = True"
200+
metayaml find "description = 'foo' "
197201
"""
198202
# doing this for directories is ambiguous in the recursive mode: It would output the directory even if some children don't match
199203

200-
arg1, operator, arg2 = [x for x in query.split(" ") if len(x) > 0]
204+
arg1, arg2 = map(lambda x: x.strip(), re.split("|".join(operators), query))
205+
operator = re.findall("|".join(operators), query)[0]
206+
201207
rules = create_rclone_rules(arg1, operator, arg2, directory, abs_path)
202208

203209
with NamedTemporaryFile() as tmp:

0 commit comments

Comments
 (0)