src/mercurialserver/servelog.py
author Paul Crowley <paul@lshift.net>
Tue, 10 Nov 2009 16:16:15 +0000
changeset 197 76a249a8b62d
parent 78 2a3407a14654
child 242 03d8f07230b3
permissions -rw-r--r--
Added tag release_0.8 for changeset 1ad9d5841a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     1
# Copyright 2008-2009 LShift Ltd
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     2
#
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     3
# Authors:
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     4
# Paul Crowley <paul@lshift.net>
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     5
#
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     6
# This software may be used and distributed according to the terms
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     7
# of the GNU General Public License, incorporated herein by reference.
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     8
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
     9
from mercurial.i18n import _
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    10
import mercurial.util
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    11
import mercurial.node
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    12
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    13
import os
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    14
import time
78
2a3407a14654 Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents: 67
diff changeset
    15
from mercurialserver import ruleset, changes
2a3407a14654 Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents: 67
diff changeset
    16
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    17
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
55
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    18
    if hooktype == 'changegroup':
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    19
        op = "push"
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    20
    elif hooktype == 'outgoing':
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    21
        op = "pull"
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    22
    else:
59
f96de2d99f00 give logging module a more specific name
Paul Crowley <paul@lshift.net>
parents: 56
diff changeset
    23
        raise mercurial.util.Abort(_('servelog installed as wrong hook type,'
55
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    24
            ' must be changegroup or outgoing but is %s') % hooktype)
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    25
    t = time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())
78
2a3407a14654 Replaced env vars with Python globals
Paul Crowley <paul@lshift.net>
parents: 67
diff changeset
    26
    user = ruleset.rules.get('user')
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    27
    # FIXME: lock it
56
9ea9a30cd060 Give log more appropriate name now it has pulls too
Paul Crowley <paul@lshift.net>
parents: 55
diff changeset
    28
    log = open(repo.join("serve-log"), "a+")
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    29
    try:
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    30
        for ctx in changes.changes(repo, node):
55
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    31
            log.write("%s %s key=%s changeset=%s\n" % 
2661b21688d4 Log pulls too
Paul Crowley <paul@lshift.net>
parents: 54
diff changeset
    32
                (t, op, user, mercurial.node.hex(ctx.node())))
54
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    33
    finally:
e2ca551c2822 Add push logging
Paul Crowley <paul@lshift.net>
parents:
diff changeset
    34
        log.close()