From 5d339516dc217b948e76a659bec8781af5f820f8 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Wed, 9 Oct 2024 14:43:38 -0700 Subject: [PATCH] make some handling via uuid workable.. --- ui/fixtures/cmd.parent_obj.json | 15 +++++++++++++++ ui/medashare/cli.py | 18 +++++++++++------- ui/medashare/mdb.py | 6 ++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ui/fixtures/cmd.parent_obj.json b/ui/fixtures/cmd.parent_obj.json index b5d2b0d..da92713 100644 --- a/ui/fixtures/cmd.parent_obj.json +++ b/ui/fixtures/cmd.parent_obj.json @@ -49,5 +49,20 @@ "title": "search excludes newfile.txt ", "cmd": [ "search", "file", "+some=tag", "-ms:tag=random" ], "stdout_re": "^.*test.txt\n$" +}, +{ + "title": "that an obj can be modified by uuid", + "format": [ "cmd" ], + "cmd": [ "modify", "+another=tag", "uuid:{newuuid}" ] +}, +{ + "title": "and modification works", + "cmd": [ "search", "file", "+another=tag" ], + "stdout_re": "newfile.txt\n$" +}, +{ + "title": "that a parent obj can be dropped", + "format": [ "cmd" ], + "cmd": [ "drop", "{newuuid}" ] } ] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 5c0dabd..bd49441 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -554,7 +554,7 @@ class ObjectStore(object): session.execute(delete(orm.UUIDv5Table).where( orm.UUIDv5Table.uuid == obj.id)) - for j in obj.hashes: + for j in obj.get('hashes', []): h = self.makehash(j) session.execute(delete(orm.HashTable).where( orm.HashTable.hash == h and @@ -1039,12 +1039,16 @@ def cmd_modify(options, persona, objstr, cache): for i in options.files: #print('a:', repr(i), file=_real_stderr) - try: - objs = objstr.get_metadata(i, persona) - #print('d:', repr(i), repr(objs), file=_real_stderr) - except FileNotFoundError: - print('ERROR: file not found: %s, or invalid tag specification.' % repr(i), file=sys.stderr) - sys.exit(1) + if i.startswith('uuid:'): + obj = objstr.by_id(i[5:]) + objs = [ obj ] + else: + try: + objs = objstr.get_metadata(i, persona) + #print('d:', repr(i), repr(objs), file=_real_stderr) + except FileNotFoundError: + print('ERROR: file not found: %s, or invalid tag specification.' % repr(i), file=sys.stderr) + sys.exit(1) for j in objs: diff --git a/ui/medashare/mdb.py b/ui/medashare/mdb.py index a477d05..8130154 100644 --- a/ui/medashare/mdb.py +++ b/ui/medashare/mdb.py @@ -163,6 +163,12 @@ class MDBase(object): else: self._obj[k] = v + def get(self, key, default=None): + try: + return self[key] + except KeyError: + return default + def __getitem__(self, k): return self._obj[k]