Show More
@@ -1,45 +1,47 | |||
|
1 | 1 | # simple script to be used in hooks |
|
2 | 2 | # |
|
3 | 3 | # put something like this in the repo .hg/hgrc: |
|
4 | 4 | # |
|
5 | 5 | # [hooks] |
|
6 | 6 | # changegroup = python "$TESTDIR"/printenv.py <hookname> [exit] [output] |
|
7 | 7 | # |
|
8 | 8 | # - <hookname> is a mandatory argument (e.g. "changegroup") |
|
9 | 9 | # - [exit] is the exit code of the hook (default: 0) |
|
10 | 10 | # - [output] is the name of the output file (default: use sys.stdout) |
|
11 | 11 | # the file will be opened in append mode. |
|
12 | 12 | # |
|
13 | 13 | import os |
|
14 | 14 | import sys |
|
15 | 15 | |
|
16 | 16 | try: |
|
17 | 17 | import msvcrt |
|
18 | 18 | msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
|
19 | 19 | msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
20 | 20 | msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
|
21 | 21 | except ImportError: |
|
22 | 22 | pass |
|
23 | 23 | |
|
24 | 24 | exitcode = 0 |
|
25 | 25 | out = sys.stdout |
|
26 | 26 | |
|
27 | 27 | name = sys.argv[1] |
|
28 | 28 | if len(sys.argv) > 2: |
|
29 | 29 | exitcode = int(sys.argv[2]) |
|
30 | 30 | if len(sys.argv) > 3: |
|
31 | 31 | out = open(sys.argv[3], "ab") |
|
32 | 32 | |
|
33 | 33 | # variables with empty values may not exist on all platforms, filter |
|
34 | 34 | # them now for portability sake. |
|
35 | env = [k for k, v in os.environ.iteritems() | |
|
35 | env = [(k, v) for k, v in os.environ.iteritems() | |
|
36 | 36 | if k.startswith("HG_") and v] |
|
37 | 37 | env.sort() |
|
38 | 38 | |
|
39 | 39 | out.write("%s hook: " % name) |
|
40 | for v in env: | |
|
41 | out.write("%s=%s " % (v, os.environ[v])) | |
|
40 | for k, v in env: | |
|
41 | if os.name == 'nt': | |
|
42 | v = v.replace('\\', '/') | |
|
43 | out.write("%s=%s " % (k, v)) | |
|
42 | 44 | out.write("\n") |
|
43 | 45 | out.close() |
|
44 | 46 | |
|
45 | 47 | sys.exit(exitcode) |
General Comments 0
You need to be logged in to leave comments.
Login now