scripts/outputif
author Gregory Szorc <gps@mozilla.com>
Fri, 29 May 2015 09:15:09 -0700
changeset 360844 a454a3112d7c58f6b2613c6847c2112126d69c39
permissions -rwxr-xr-x
ansible: install CRON to periodically generate repository bundles (bug 1041173); r=bkero Now that we support generating Mercurial bundles and uploading them to S3, let's make generating them part of our standard operating procedure. This commit installs daily CRON entries to do the bundle generation. We introduce the "outputif" script to execute a process and only print its output if it exits with an error. This makes CRON email tolerable by not sending it if everything is OK.

#!/usr/bin/env python2
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# A script that executes its arguments as a new process and only
# prints its output if the executed command exited non-zero.

import subprocess
import sys

p = subprocess.Popen(sys.argv[1:], stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)
out, err = p.communicate()
ret = p.poll()
if ret:
    print(out)
    sys.exit(ret)

sys.exit(0)