Browse Source

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
main
John-Mark Gurney 2 months ago
parent
commit
eff8493baf
2 changed files with 32 additions and 0 deletions
  1. +15
    -0
      ui/fixtures/cmd.search.json
  2. +17
    -0
      ui/medashare/cli.py

+ 15
- 0
ui/fixtures/cmd.search.json View File

@@ -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"
}
]

+ 17
- 0
ui/medashare/cli.py View File

@@ -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))



Loading…
Cancel
Save