view tests/printenv.py @ 21229:54d7657d7d1e stable

setup.py, make: avoid problems with outdated, existing hgext/__index__.py* "make clean" already removed __index__.py[cdo], but not the __index__.py (automatically generated by "python setup.py build_hgextindex"). "setup.py build_hgextindex" did not generate a new index if file __index__.py[cdo] already existed, because if __index__.py was removed, the compiled file containing the old information was imported and used. Generate an empty file (with a new timestamp to generate a new .py[cdo]) instead and make mercurial.extensions ignore the unset docs attribute. One of the problems was a failed test-help.t, to reproduce: $ rm hgext/__index__.py* $ echo 'docs = {"mq": "dummy"}' > hgext/__index__.py $ make test-help.t With this a "make clean" or "python setup.py build_hgextindex" helps.
author Thomas Arendsen Hein <thomas@intevation.de>
date Mon, 05 May 2014 16:54:15 +0200
parents e7fdfc702d9f
children a372f7b4463b
line wrap: on
line source

# simple script to be used in hooks
#
# put something like this in the repo .hg/hgrc:
#
#     [hooks]
#     changegroup = python "$TESTDIR/printenv.py" <hookname> [exit] [output]
#
#   - <hookname> is a mandatory argument (e.g. "changegroup")
#   - [exit] is the exit code of the hook (default: 0)
#   - [output] is the name of the output file (default: use sys.stdout)
#              the file will be opened in append mode.
#
import os
import sys

try:
    import msvcrt
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
except ImportError:
    pass

exitcode = 0
out = sys.stdout

name = sys.argv[1]
if len(sys.argv) > 2:
    exitcode = int(sys.argv[2])
    if len(sys.argv) > 3:
        out = open(sys.argv[3], "ab")

# variables with empty values may not exist on all platforms, filter
# them now for portability sake.
env = [(k, v) for k, v in os.environ.iteritems()
       if k.startswith("HG_") and v]
env.sort()

out.write("%s hook: " % name)
if os.name == 'nt':
    filter = lambda x: x.replace('\\', '/')
else:
    filter = lambda x: x
vars = ["%s=%s" % (k, filter(v)) for k, v in env]
out.write(" ".join(vars))
out.write("\n")
out.close()

sys.exit(exitcode)