author | Paul Crowley <paul@lshift.net> |
Tue, 06 Sep 2011 11:47:55 +0100 | |
branch | debian |
changeset 319 | eda87019bda9 |
parent 312 | 4e65f8242c0b |
child 373 | a286d6c6b19c |
permissions | -rw-r--r-- |
242
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
78
diff
changeset
|
1 |
""" |
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
78
diff
changeset
|
2 |
Hook to log changesets pushed and pulled |
03d8f07230b3
Tidy up file prologues; move credits to CREDITS
Paul Crowley <paul@lshift.net>
parents:
78
diff
changeset
|
3 |
""" |
54 | 4 |
|
5 |
from mercurial.i18n import _ |
|
6 |
import mercurial.util |
|
7 |
import mercurial.node |
|
8 |
||
9 |
import os |
|
10 |
import time |
|
262
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
11 |
import fcntl |
296
6feeef02c057
Prefer import json over import simplejson
Paul Crowley <paul@lshift.net>
parents:
295
diff
changeset
|
12 |
|
311 | 13 |
try: |
296
6feeef02c057
Prefer import json over import simplejson
Paul Crowley <paul@lshift.net>
parents:
295
diff
changeset
|
14 |
import json |
312
4e65f8242c0b
Oops, test for the right attribute of json
Paul Crowley <paul@lshift.net>
parents:
311
diff
changeset
|
15 |
json.dumps |
311 | 16 |
except ImportError: |
296
6feeef02c057
Prefer import json over import simplejson
Paul Crowley <paul@lshift.net>
parents:
295
diff
changeset
|
17 |
import simplejson as json |
6feeef02c057
Prefer import json over import simplejson
Paul Crowley <paul@lshift.net>
parents:
295
diff
changeset
|
18 |
|
78
2a3407a14654
Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents:
67
diff
changeset
|
19 |
from mercurialserver import ruleset, changes |
2a3407a14654
Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents:
67
diff
changeset
|
20 |
|
54 | 21 |
def hook(ui, repo, hooktype, node=None, source=None, **kwargs): |
55 | 22 |
if hooktype == 'changegroup': |
23 |
op = "push" |
|
24 |
elif hooktype == 'outgoing': |
|
25 |
op = "pull" |
|
26 |
else: |
|
59
f96de2d99f00
give logging module a more specific name
Paul Crowley <paul@lshift.net>
parents:
56
diff
changeset
|
27 |
raise mercurial.util.Abort(_('servelog installed as wrong hook type,' |
55 | 28 |
' must be changegroup or outgoing but is %s') % hooktype) |
262
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
29 |
log = open(repo.join("mercurial-server.log"), "a+") |
54 | 30 |
try: |
262
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
31 |
fcntl.flock(log.fileno(), fcntl.LOCK_EX) |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
32 |
log.seek(0, os.SEEK_END) |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
33 |
# YAML log file format |
295
9741d82e5b1e
servelog: use simplejson and the % operator for python versions < 2.6
Dale Wijnand <dale.wijnand@gmail.com>
parents:
262
diff
changeset
|
34 |
log.write("- %s\n" % json.dumps(dict( |
262
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
35 |
timestamp=time.strftime("%Y-%m-%d_%H:%M:%S Z", time.gmtime()), |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
36 |
op=op, |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
37 |
key=ruleset.rules.get('user'), |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
38 |
ssh_connection=os.environ['SSH_CONNECTION'], |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
39 |
nodes=[mercurial.node.hex(ctx.node()) |
675474f5be32
New log file format based on JSON/YAML
Paul Crowley <paul@lshift.net>
parents:
242
diff
changeset
|
40 |
for ctx in changes.changes(repo, node)], |
295
9741d82e5b1e
servelog: use simplejson and the % operator for python versions < 2.6
Dale Wijnand <dale.wijnand@gmail.com>
parents:
262
diff
changeset
|
41 |
))) |
54 | 42 |
finally: |
43 |
log.close() |