From 71128c17671a802d8da79234156dfe9e1cc67380 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Thu, 30 May 2024 18:17:44 -0700 Subject: [PATCH] fix two bugs, first is deleting tag that didn't exist was an error second is auto was applying to all files if multiple were specified on the command line resulting in all the mimetypes applied to all the files... --- ui/fixtures/cmd.auto.json | 12 ++++++++++++ ui/medashare/cli.py | 10 +++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ui/fixtures/cmd.auto.json b/ui/fixtures/cmd.auto.json index 9cd208f..cab9672 100644 --- a/ui/fixtures/cmd.auto.json +++ b/ui/fixtures/cmd.auto.json @@ -27,5 +27,17 @@ "cmd": [ "list", "z.jpg" ], "stdin": "y\n", "stdout_re": "mimetype:\timage/jpeg" +}, +{ + "title": "Test auto detection of two files", + "cmd": [ "auto", "z.jpg", "test.txt" ], + "stdin": "y\ny\n", + "stdout": "Set:\n\tmimetype:\timage/jpeg\n\nApply (y/N)?\nSet:\n\tmimetype:\ttext/plain; charset=us-ascii\n\nApply (y/N)?\n" +}, +{ + "title": "Verify modification", + "cmd": [ "list", "z.jpg", "test.txt" ], + "stdin": "y\n", + "stdout_re": "hashes:.*\nmimetype:\timage/jpeg.*\nsig:.*\nhashes:.*\nmimetype:\ttext/plain.*\nsig:.*\n" } ] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index dea2760..78fa7cf 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -1030,7 +1030,10 @@ def cmd_modify(options, persona, objstr, cache): try: key, v = k except ValueError: - del obj[k[0]] + try: + del obj[k[0]] + except KeyError: + pass else: obj[key].remove(v) @@ -1372,7 +1375,7 @@ def cmd_dump(options, persona, objstr, cache): print(i.encode('json')) def cmd_auto(options): - for i in options.files: + for i in options.files[:]: mf = detect_from_filename(i) primary = mf[0].split('/', 1)[0] @@ -1388,7 +1391,8 @@ def cmd_auto(options): inp = sys.stdin.readline() if inp.strip().lower() in ('y', 'yes'): - options.modtagvalues = [ '+mimetype=%s' % mt ] + options.modtagvalues = [ '-mimetype', '+mimetype=%s' % mt ] + options.files = [ i ] cmd_modify(options) @init_datastructs