chiark / gitweb /
m.sphinx: add an option to repack a decompressed inventory file.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 10 Sep 2019 17:47:43 +0000 (19:47 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 10 Sep 2019 20:10:14 +0000 (22:10 +0200)
plugins/m/sphinx.py

index 61d830649488e3add8f61caef04f40846504e778..3446581e4fcb6a47d9f822b8203d0e774402f5aa 100755 (executable)
@@ -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))