1
+ #!/usr/bin/python3
2
+ import os
3
+ import sys
4
+ __dir__ = os .path .dirname (__file__ )
5
+ sys .path .insert (0 , os .path .join (__dir__ , ".." ))
6
+
7
+ import sphinx .cmd .build
8
+ import ipfshttpclient
9
+
10
+ # Ensure working directory is script directory
11
+ os .chdir (__dir__ )
12
+
13
+ def main (argv = sys .argv [1 :], program = sys .argv [0 ]):
14
+ if len (argv ) != 1 :
15
+ print ("Usage: {0} [IPNS-key]" .format (os .path .basename (program )))
16
+ print ()
17
+ print ("!! Continuing without publishing to IPNS !!" )
18
+ print ()
19
+
20
+ # Invoke Sphinx like the Makefile does
21
+ result = sphinx .cmd .build .build_main (["-b" , "html" , "-d" , "build/doctrees" , "." , "build/html" ])
22
+ if result != 0 :
23
+ return result
24
+
25
+ print ()
26
+ print ("Exporting files to IPFS…" )
27
+ client = ipfshttpclient .connect ()
28
+ hash_docs = client .add ("build/html" , recursive = True , raw_leaves = True , pin = False )[- 1 ]["Hash" ]
29
+ hash_main = client .object .new ("unixfs-dir" )["Hash" ]
30
+ hash_main = client .object .patch .add_link (hash_main , "docs" , hash_docs )["Hash" ]
31
+ client .pin .add (hash_main )
32
+ print ("Final IPFS path: /ipfs/{0}" .format (hash_main ))
33
+
34
+ if len (argv ) == 1 :
35
+ key = argv [0 ]
36
+ print ()
37
+ print ("Exporting files to IPNS…" )
38
+ name_main = client .name .publish (hash_main , key = key )["Name" ]
39
+ print ("Final IPNS path: /ipns/{0}" .format (name_main ))
40
+
41
+ print ()
42
+ print ("Run the following commandline on all systems that mirror this documentation:" )
43
+ print (" ipfs pin add {0} && ipfs name publish -k {1} /ipfs/{0}" .format (hash_main , name_main ))
44
+
45
+ return 0
46
+
47
+ if __name__ == "__main__" :
48
+ sys .exit (main ())
0 commit comments