mozreview
author Gregory Szorc <gps@mozilla.com>
Thu, 05 Mar 2015 17:27:39 -0800
changeset 360505 779cf88d244327cf8dadbe15aa8b31f5281704b4
parent 360276 7db4622ae530570abaf69b6ce2ffc6b08bdaa3d8
permissions -rwxr-xr-x
pash: store user in a variable; r=bkero os.getenv('USER') was used multiple times in this file. The content of the environment variable doesn't change during execution. So get the value once and store it in a variable. Also, os.environ is the preferred mechanism to access environment variables from Python. os.getenv is a low-level API into the POSIX function of the same name. The difference doesn't matter in this use case, so use the method that is more accepted by the Python community.

#!/usr/bin/env python
# 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/.

import os
import sys

HERE = os.path.abspath(os.path.dirname(__file__))

def main(args):
    if 'VIRTUAL_ENV' not in os.environ:
        activate = os.path.join(HERE, 'venv', 'bin', 'activate_this.py')
        execfile(activate, dict(__file__=activate))
        sys.executable = os.path.join(HERE, 'venv', 'bin', 'python')

    from mach.main import Mach

    m = Mach(os.getcwd())

    m.define_category('mozreview', 'MozReview',
        'Control and Interact with the Mozilla Code Review Service', 50)
    import vcttesting.mozreview_mach_commands

    return m.run(args)

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))