python/mozbuild/mozbuild/util.py
author Gregory Szorc <gps@mozilla.com>
Wed, 28 Jan 2015 13:37:00 -0800
branchGECKO170_2012103106_RELBRANCH
changeset 110546 6ed4715ca6580d572af43aa6ec2d2270fd77521f
parent 106844 d6deca9f6666164191d114e10fb4c80366aa3545
permissions -rw-r--r--
Close old release branch GECKO170_2012103106_RELBRANCH

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

# This file contains miscellaneous utility functions that don't belong anywhere
# in particular.

import hashlib


def hash_file(path):
    """Hashes a file specified by the path given and returns the hex digest."""

    # If the hashing function changes, this may invalidate lots of cached data.
    # Don't change it lightly.
    h = hashlib.sha1()

    with open(path, 'rb') as fh:
        while True:
            data = fh.read(8192)

            if not len(data):
                break

            h.update(data)

    return h.hexdigest()