From ce7a069af57071223cb48ab365931df19189db7b Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Tue, 17 Aug 2021 17:25:20 +0000 Subject: [PATCH] Add --jsonl option --- azure-storage-list | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/azure-storage-list b/azure-storage-list index 03bf8ff..424cecd 100755 --- a/azure-storage-list +++ b/azure-storage-list @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import html import http.client +import json import os import shlex import ssl @@ -14,6 +15,7 @@ withListUrls = False listUrlsFD = None startMarker = None format = '{url}' +jsonl = False args = [] while i < len(sys.argv): arg = sys.argv[i] @@ -22,6 +24,7 @@ while i < len(sys.argv): print('', file = sys.stderr) print('Options:', file = sys.stderr) print(f' --format FORMAT Modify the output format; FORMAT defaults to {format!r}; available fields: name, url, and all fields returned by Azure (e.g. Content-Length, Last-Modified)', file = sys.stderr) + print( ' --jsonl Output JSONL instead of formatted lines', file = sys.stderr) print( ' --marker MARKER Start with a marker instead of from the beginning', file = sys.stderr) print( ' --with-list-urls Enables printing the list URLs retrieved to FD 3', file = sys.stderr) sys.exit(1) @@ -38,6 +41,8 @@ while i < len(sys.argv): elif arg == '--format': format = sys.argv[i + 1] i += 1 + elif arg == '--jsonl': + jsonl = True else: args.append(arg) i += 1 @@ -101,7 +106,10 @@ while True: assert False try: - print(format.format(**fields, name = name, url = url)) + if not jsonl: + print(format.format(**fields, name = name, url = url)) + else: + print(json.dumps({'name': name, 'url': url, **fields})) except BrokenPipeError: sys.exit(0)