Skip to content
This repository
tree: 973e8e1781
Fetching contributors…

Cannot retrieve contributors at this time

executable file 56 lines (48 sloc) 1.509 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/usr/bin/python
# requires an ApiUser (corehq.apps.api.models.ApiUser) on the remote_host with username/password given

import os
import shlex

import subprocess
from subprocess import PIPE
import sys

def submit_build(environ):
    target_url="{remote_host}/builds/post/".format(**environ)

    command = (
        'curl -v '
        '-H "Expect:" '
        '-F "artifacts=@{artifacts}" '
        '-F "username={username}" '
        '-F "password={password}" '
        '-F "build_number={build_number}" '
        '-F "version={version}" '
        '{target_url}'
    ).format(target_url=target_url, **environ)

    p = subprocess.Popen(shlex.split(command), stdout=PIPE, stderr=None, shell=False)
    return command, p.stdout.read(), "" #p.stderr.read()


if __name__ == "__main__":
    variables = [
        "username",
        "password",
        "artifacts",
        "remote_host",
        "version",
        "build_number",
    ]
    args = sys.argv[1:]
    environ = None
    try:
        environ = dict([(var, os.environ[var]) for var in variables])
    except KeyError:
        if len(args) == len(variables):
            environ = dict(zip(variables, args))

    if environ:
        command, out, err = submit_build(environ)
        print command
        if out.strip():
            print "--------STDOUT--------"
            print out
        if err.strip():
            print "--------STDERR--------"
            print err
    else:
        print("submit_build.py <%s>" % ("> <".join(variables)))
Something went wrong with that request. Please try again.