/ docimport.py
docimport.py
 1  #!/usr/bin/python3
 2  import argparse
 3  import glob
 4  import os
 5  import subprocess
 6  import sys
 7  
 8  
 9  parser = argparse.ArgumentParser()
10  parser.add_argument("branch", default="gh-pages", nargs="?")
11  args = parser.parse_args()
12  
13  version = subprocess.getoutput("git describe --always")
14  
15  fd = os.fdopen(sys.stdout.fileno(), 'wb')
16  
17  fd.write(b"commit refs/heads/" + args.branch.encode('utf-8') + b"\n")
18  fd.write(b"committer Doc Man <noreply@example.com> now" + b"\n")
19  fd.write(b"data <<EOF" + b"\n")
20  fd.write(b"Docs built at " + version.encode('utf-8') + b"\n")
21  fd.write(b"EOF" + b"\n")
22  
23  files = glob.glob("doc/*")
24  for fn in files:
25      with open(fn, 'rb') as f: contents = f.read()
26      fd.write(b"M 644 inline " + os.path.basename(fn).encode('utf-8') + b"\n")
27      fd.write(b"data " + str(len(contents)).encode("utf-8") + b"\n")
28      fd.write(contents)
29  fd.write(b"done\n")
30