author Dustin J. Mitchell <dustin@mozilla.com>
Tue, 31 Jan 2017 18:28:06 +0000
changeset 469652 6f6c2c0b2a3e1bdb0bd94bc7ff6c4967153f16b2
parent 464046 459fd779b23594486c258add76e68162e65b2d3c
child 469145 7f51e08ac3cc9513ca16a97b4f2d7e24a02e9608
permissions -rw-r--r--
Bug 1334167: calculate head revision with -r .; r?Callek MozReview-Commit-ID: 6tmdO5qwD4g

# -*- coding: utf-8 -*-

# 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/.

from __future__ import absolute_import, print_function, unicode_literals

import subprocess

def match_utc(params, hour=None, minute=None):
    """ Return True if params['time'] matches the given hour and minute.
    If hour is not specified, any hour will match.  If minute is not
    specified, then every multiple of fifteen minutes will match.  Times
    not an even multiple of fifteen minutes will result in an exception
    (since they would never run)."""
    if minute and minute % 15 != 0:
        raise Exception("cron jobs only run on multiples of 15 minutes past the hour")
    if hour and params['time'].hour != hour:
        return False
    if minute and params['time'].minute != minute:
        return False
    return True

def calculate_head_rev(options):
    # we assume that run-task has correctly checked out the revision indicated by
    # GECKO_HEAD_REF, so all that remains is to see what the current revision is.
    # Mercurial refers to that as `.`.
    return subprocess.check_output(['hg', 'log', '-r', '.', '-T', '{node}'])