From: Vladimír Vondruš Date: Tue, 10 Sep 2019 17:47:43 +0000 (+0200) Subject: m.sphinx: add an option to repack a decompressed inventory file. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=5f403b5f92fbdb6fc41411f9d974a78e164bddb8;p=blog.git m.sphinx: add an option to repack a decompressed inventory file. --- diff --git a/plugins/m/sphinx.py b/plugins/m/sphinx.py index 61d83064..3446581e 100755 --- a/plugins/m/sphinx.py +++ b/plugins/m/sphinx.py @@ -661,14 +661,25 @@ if __name__ == '__main__': # pragma: no cover parser.add_argument('file', help="inventory file to print") parser.add_argument('--raw', help="show raw content", action='store_true') parser.add_argument('--types', help="list all type keys", action='store_true') + parser.add_argument('--repack', help="repack raw content back into a compressed file", action='store_true') args = parser.parse_args() - if args.raw or not args.types: - with open(args.file, 'rb') as f: - print(pretty_print_intersphinx_inventory(f)) - if args.types: with open(args.file, 'rb') as f: inventory = {} parse_intersphinx_inventory(f, '', inventory, []) print(inventory.keys()) + elif args.repack: + with open(args.file, 'rb') as f: + # Sphinx inventory version 2 + sys.stdout.buffer.write(f.readline()) + # Project and version + sys.stdout.buffer.write(f.readline()) + sys.stdout.buffer.write(f.readline()) + # Zlib compression line + sys.stdout.buffer.write(f.readline()) + # The rest, zlib-compressed + sys.stdout.buffer.write(zlib.compress(f.read())) + else: + with open(args.file, 'rb') as f: + print(pretty_print_intersphinx_inventory(f))