File: commit-block-joke.py

package info (click to toggle)
subversion 1.5.1dfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 41,860 kB
  • ctags: 43,900
  • sloc: ansic: 522,648; python: 64,596; sh: 12,784; ruby: 11,838; cpp: 9,584; java: 8,130; lisp: 7,131; perl: 5,686; makefile: 895; xml: 759
file content (60 lines) | stat: -rwxr-xr-x 2,147 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# ====================================================================
# Copyright (c) 2004 CollabNet.  All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.  The terms
# are also available at http://subversion.tigris.org/license.html.
# If newer versions of this license are posted there, you may use a
# newer version instead, at your option.
#
# This software consists of voluntary contributions made by many
# individuals.  For exact contribution history, see the revision
# history and logs, available at http://subversion.tigris.org/.
# ====================================================================

import sys, os, string

SVNLOOK='/usr/local/bin/svnlook'
MESSAGE="""
Dear {AUTHOR}:

We're sorry, but we just couldn't allow you to have the
revision {REVISION} commit.

       -- Love, Your Administrator(s).
"""

if len(sys.argv) < 5:
    sys.stderr.write(
        "Usage: %s REPOS AUTHOR BLOCKED_REV BLOCKED_AUTHOR [...]\n"
        "\n"
        "Disallow a set BLOCKED_AUTHORS from committing the revision\n"
        "expected to bring REPOS to a youngest revision of BLOCKED_REV.\n"
        "Written as a prank for use as a start-commit hook (which provides\n"
        "REPOS and AUTHOR for you).\n"
        "\n"
        "NOTE: There is a small chance that while HEAD is BLOCKED_REV - 2,\n"
        "a commit could slip in between the time we query the youngest\n"
        "revision and the time this commit-in-progress actually occurs.\n"
        "\n"
        % sys.argv[0])
    sys.exit(1)

repos = sys.argv[1]
author = sys.argv[2]
blocked_rev = sys.argv[3]
blocked_authors = sys.argv[4:]

if author in blocked_authors:
    youngest_cmd = '%s youngest %s' % (SVNLOOK, repos)
    youngest = os.popen(youngest_cmd, 'r').readline().rstrip('\n')

    # See if this is the blocked revision
    if int(youngest) == int(blocked_rev) - 1:
        MESSAGE = MESSAGE.replace('{AUTHOR}', author)
        MESSAGE = MESSAGE.replace('{REVISION}', blocked_rev)
        sys.stderr.write(MESSAGE)
        sys.exit(1)

sys.exit(0)