Browse Source

make ms:tag unique, drop dups..

main
John-Mark Gurney 2 years ago
parent
commit
0d0ae8ead4
2 changed files with 21 additions and 0 deletions
  1. +13
    -0
      ui/fixtures/cmd.basic.json
  2. +8
    -0
      ui/medashare/cli.py

+ 13
- 0
ui/fixtures/cmd.basic.json View File

@@ -67,6 +67,19 @@
"cmd": [ "list", "newfile.txt" ],
"stdout_re": "dc:creator:\tJohn-Mark Gurney\nhashes:\tsha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\nsig:\t.*\ntag:\t\n"
},
{
"title": "add duplicate ms:tag's",
"cmd": [ "modify", "+ms:tag=foo", "+ms:tag=foo", "newfile.txt" ]
},
{
"title": "but dup tags are not dup'd",
"cmd": [ "list", "newfile.txt" ],
"stdout_re": "dc:creator:\tJohn-Mark Gurney\nhashes:\tsha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\nms:tag:\tfoo\nsig:\t.*\ntag:\t\n"
},
{
"title": "drop ms:tag",
"cmd": [ "modify", "-ms:tag=foo", "newfile.txt" ]
},
{
"title": "add tag",
"cmd": [ "modify", "+dc:creator=Another user", "newfile.txt" ]


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

@@ -253,6 +253,8 @@ class MDBase(object):
class MetaData(MDBase):
_type = 'metadata'

_uniq_properties = set([ 'ms:tag' ])

class Identity(MDBase):
_type = 'identity'

@@ -873,8 +875,14 @@ def cmd_modify(options):
obj[key].remove(v)

# add tags
uniqify = set()
for k, v in adds:
obj.setdefault(k, []).append(v)
if k in j._uniq_properties:
uniqify.add(k)

for k in uniqify:
obj[k] = list(set(obj[k]))

#print('a:', repr(obj), file=_real_stderr)
del obj['modified']


Loading…
Cancel
Save