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