Browse Source

add support for outputing json objects from list

main
John-Mark Gurney 2 months ago
parent
commit
9ee1e459b4
2 changed files with 13 additions and 3 deletions
  1. +5
    -0
      ui/fixtures/cmd.basic.json
  2. +8
    -3
      ui/medashare/cli.py

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

@@ -67,6 +67,11 @@
"cmd": [ "list", "newfile.txt" ],
"stdout_re": "dc:creator:\tJohn-Mark Gurney\nhashes:\tsha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\nsig:\t.*\ntag:\t\n"
},
{
"title": "verify --json works",
"cmd": [ "list", "--json", "newfile.txt" ],
"stdout_check": [ { "dc:creator": [ "John-Mark Gurney" ], "hashes": [ "sha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c" ], "tag": [ "" ], "type": "metadata" } ]
},
{
"title": "add duplicate ms:tag's",
"cmd": [ "modify", "+ms:tag=foo", "+ms:tag=foo", "newfile.txt" ]


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

@@ -1426,8 +1426,11 @@ def cmd_list(options, persona, objstr, cache):
continue

for j in objstr.by_file(i):
for k, v in _iterdictlist(j):
print('%s:\t%s' % (k, v))
if options.json:
print(j.encode('json'))
else:
for k, v in _iterdictlist(j):
print('%s:\t%s' % (k, v))

if exit:
sys.exit(exit)
@@ -1810,6 +1813,8 @@ def main():
parser_auto.set_defaults(func=cmd_auto)

parser_list = subparsers.add_parser('list', help='list tags on file(s)')
parser_list.add_argument('--json', action='store_true',
help='output data as series of JSON objects')
parser_list.add_argument('files', nargs='+',
help='files to modify')
parser_list.set_defaults(func=cmd_list)
@@ -2478,7 +2483,7 @@ class _TestCases(unittest.TestCase):

def objcompare(self, fullobjs, partialobjs):
fullobjs = list(fullobjs)
#_debprint('objs:', repr(fullobjs))
#_debprint('objs:', repr(fullobjs), repr(partialobjs))
self.assertEqual(len(fullobjs), len(partialobjs))

missing = []


Loading…
Cancel
Save