Mercurial > hg
annotate tests/printenv.py @ 4288:8a3e12426c03
test-push-http: use printenv.py
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Mon, 26 Mar 2007 23:50:00 -0300 |
parents | 4fd6f7e60894 |
children | a39cec1d5cb8 |
rev | line source |
---|---|
4285
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
1 # simple script to be used in hooks |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
2 # copy it to the current directory when the test starts: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
3 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
4 # cp "$TESTDIR"/printenv.py . |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
5 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
6 # put something like this in the repo .hg/hgrc: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
7 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
8 # [hooks] |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
9 # changegroup = python ../printenv.py <hookname> [exit] [output] |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
10 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
11 # - <hookname> is a mandatory argument (e.g. "changegroup") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
12 # - [exit] is the exit code of the hook (default: 0) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
13 # - [output] is the name of the output file (default: use sys.stdout) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
14 # the file will be opened in append mode. |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
15 # |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
16 import os |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
17 import sys |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
18 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
19 exitcode = 0 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
20 out = sys.stdout |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
21 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
22 name = sys.argv[1] |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
23 if len(sys.argv) > 2: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
24 exitcode = int(sys.argv[2]) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
25 if len(sys.argv) > 3: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
26 out = open(sys.argv[3], "ab") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
27 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
28 env = [v for v in os.environ if v.startswith("HG_")] |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
29 env.sort() |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
30 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
31 # edit the variable part of the variable |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
32 url = os.environ.get("HG_URL", "") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
33 if url.startswith("file:"): |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
34 os.environ["HG_URL"] = "file:" |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
35 elif url.startswith("remote:http"): |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
36 os.environ["HG_URL"] = "remote:http" |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
37 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
38 out.write("%s hook: " % name) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
39 for v in env: |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
40 out.write("%s=%s " % (v, os.environ[v])) |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
41 out.write("\n") |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
42 out.close() |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
43 |
4fd6f7e60894
Add tests/printenv.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff
changeset
|
44 sys.exit(exitcode) |