aboutsummaryrefslogblamecommitdiff
path: root/build-package.py
blob: 494011e36f982225dba520ab59eaced900e49ab4 (plain) (tree)
1
2
3
4
5
6
7
8
9







                     
         

                                  

                                                                                                              

                          




                                                                                                         
 


                                                         
                                     

                                        
                                                                                             
                                                               
                                                                                                         
                     


                                                                  
#!/usr/bin/env python

import subprocess
import tempfile
import argparse
import hashlib
import tarfile
import json
import os

parser = argparse.ArgumentParser()
parser.add_argument("tarfile", type = argparse.FileType("wb"),  help = "tarball to create")
parser.add_argument("firmware", nargs = "+",                    help = "firmware files to stuff into tarball")
args = parser.parse_args()

tar     = tarfile.TarFile(mode = "w", fileobj = args.tarfile)
head    = subprocess.check_output(("git", "rev-parse", "HEAD")).strip()
time    = subprocess.check_output(("git", "show", "-s", "--format=%ct", "HEAD")).strip()
commits = [line.split() for line in subprocess.check_output(("git", "submodule", "status")).splitlines()]
sha256  = {}

for fn in args.firmware:
    with open(fn, "rb") as f:
        sha256[fn] = hashlib.sha256(f.read()).hexdigest()
    tar.add(fn, os.path.basename(fn))

with tempfile.NamedTemporaryFile() as f:
    gpg = subprocess.Popen(("gpg", "--clearsign", "--personal-digest-preferences", "SHA256"),
                           stdin = subprocess.PIPE, stdout = f)
    json.dump(dict(head = head, time = time, commits = commits, sha256  = sha256), gpg.stdin, indent = 2)
    gpg.stdin.close()
    if gpg.wait():
        raise subprocess.CalledProcessError(gpg.returncode, "gpg")
    tar.add(f.name, "MANIFEST")