anagram/import
2016-05-15 14:59:31 -05:00

37 lines
1.1 KiB
Python
Executable file

#!/usr/bin/python3
import argparse
import glob
import os
import subprocess
import sys
parser = argparse.ArgumentParser()
parser.add_argument("--branch", metavar='branch', default="gh-pages",
help="branch to use (any old contents are destroyed)")
parser.add_argument('files', metavar='files', nargs='+',
help='files to be committed')
args = parser.parse_args()
version = subprocess.getoutput("git describe --always --dirty")
fd = os.fdopen(sys.stdout.fileno(), 'wb')
fd.write(b"commit refs/heads/" + args.branch.encode('utf-8') + b"\n")
fd.write(b"committer Doc Man <noreply@example.com> now" + b"\n")
fd.write(b"data <<EOF" + b"\n")
fd.write(b"Docs built at " + version.encode('utf-8') + b"\n")
fd.write(b"EOF" + b"\n")
for fn in args.files:
if '=' in fn:
dest, src = fn.split('=', 1)
else:
dest = src = fn
with open(src, 'rb') as f: contents = f.read()
fd.write(b"M 644 inline " + os.path.basename(dest).encode('utf-8') + b"\n")
fd.write(b"data " + str(len(contents)).encode("utf-8") + b"\n")
fd.write(contents)
fd.write(b"done\n")