From eff8493baf4e5e3ea1d5ec6446dd59dd3676390c Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Fri, 27 Sep 2024 15:21:43 -0700 Subject: [PATCH] add ability to search tags.. giving a tag, return all the tag=value pairs.. not sure how I want to handle spaces or escaping other characters. for now, don't --- ui/fixtures/cmd.search.json | 15 +++++++++++++++ ui/medashare/cli.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/ui/fixtures/cmd.search.json b/ui/fixtures/cmd.search.json index ad1a7dc..6dbe8b2 100644 --- a/ui/fixtures/cmd.search.json +++ b/ui/fixtures/cmd.search.json @@ -78,5 +78,20 @@ "title": "search other, mapped properly", "cmd": [ "search", "file", "+other" ], "stdout_re": "^/foobar/test.txt\n$" +}, +{ + "title": "add tag with space", + "cmd": [ "modify", "+tag=car baz", "test.txt" ] +}, +{ + "title": "search tags", + "cmd": [ "search", "tags", "tag" ], + "stdout": "tag=bar\ntag=car baz\ntag=foo\n" +}, +{ + "title": "search bogus", + "cmd": [ "search", "lskdjflaskjdoijef", "tag" ], + "exit": 1, + "stderr": "unknown search type: 'lskdjflaskjdoijef'\n" } ] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 78fa7cf..656a28f 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -1574,6 +1574,23 @@ def cmd_search(options, persona, objstr, cache): _type = args.pop(0) + if _type == 'tags': + propmap = aliased(orm.PropertyMapping) + skeymap = aliased(orm.StringTable) + svaluemap = aliased(orm.StringTable) + + q = select(skeymap.str, svaluemap.str).where(propmap.keyid == skeymap.id).where(skeymap.str == args[0]).where(propmap.valueid == svaluemap.id).distinct().order_by(svaluemap.str) + _debprint(repr(q)) + with objstr._ses() as session: + for k, v in session.execute(q): + print('%s=%s' % (k, v)) + return + + if _type != 'file': + print('unknown search type: %s' % repr(_type), + file=sys.stderr) + sys.exit(1) + searches = [ (x[0], ) + tuple(x[1:].split('=', 1)) for x in args ] #_debprint(repr(searches))