hg_hooks/filecheck/filecheck.py
author Simon Howkins <simonh@symbian.org>
Fri, 06 Nov 2009 12:10:52 +0000
changeset 99 5adea361d896
parent 22 f55ca49f7f44
permissions -rw-r--r--
Bug 881: "Automatic creation of release note content broken by config change" Added a new option to allow the caller to specify where the publish location is. Minor improvements to formatting of output. Turned on warnings, and fixed most of those that appeared. Greatly simplified the checking of the script arguments. Removed code which was noted to be unnecessary, and was. Declared some variables more closely to the code that uses them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     1
# filecheck.py - changeset filename check for mercurial
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     2
#
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     3
# should be configured as pretxnchangegroup to vet incoming changesets
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     4
# and as pretxncommit to vet local commit
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     5
#
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     6
# will receive a group of changesets from provided node to tip
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     7
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     8
from mercurial import util
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
     9
from mercurial.i18n import _
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    10
import re
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    11
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    12
badpatterns = ('.*\.ttt\s*$','c.ttf','.*\.ttf\s*$','.*\.bbb\s*$',
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    13
               '.*\.bbb\s*$','.*\.ccc\s*$','.*\.ddd\s*$','.*\.eee\s*$','.*\.fff\s*$','.*\.ggg\s*$')
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    14
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    15
badexpr=[]
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    16
runonce=0
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    17
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    18
def init():
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    19
    global badexpr
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    20
    for p in badpatterns:
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    21
        badexpr.append((re.compile((p),re.IGNORECASE)))
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    22
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    23
def deny(f):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    24
    global runonce
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    25
    if (not runonce):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    26
        init()
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    27
        runonce =1
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    28
      
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    29
    for pat in badexpr:
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    30
        if(pat.match(f)):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    31
            return(1)
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    32
    
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    33
    return(0)
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    34
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    35
def push_hook(ui, repo, hooktype, node=None, source=None, **kwargs):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    36
    if hooktype != 'pretxnchangegroup':
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    37
        raise util.Abort(_('config error - hook type "%s" cannot stop '
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    38
                           'incoming changesets') % hooktype)
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    39
    
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    40
    # iterate over all the added changesets between node and tip
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    41
    for rev in xrange(repo[node], len(repo)):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    42
        ctx = repo[rev]
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    43
        for f in ctx.files():
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    44
            if deny(f):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    45
                ui.debug(_('filecheck: file %s not allowed \n') % (f))
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    46
                raise util.Abort(_('filecheck: access denied for changeset %s file %s blocked') % (ctx,f))
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    47
        ui.debug(_('filecheck: allowing changeset %s\n') % ctx)
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    48
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    49
def commit_hook(ui, repo, hooktype, node=None, source=None, **kwargs):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    50
    # iterate over all the files in added changeset
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    51
    ctx = repo[node]
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    52
    for f in ctx.files():
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    53
        if deny(f):
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    54
            ui.debug(_('filecheck: file %s not allowed \n') % (f))
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    55
            raise util.Abort(_('filecheck: access denied for changeset %s file %s blocked') % (ctx,f))
f55ca49f7f44 Added initial versions of filecheck and hg tags to bugzilla version hooks
tahirm@symbian.org
parents:
diff changeset
    56
    ui.debug(_('filecheck: allowing changeset %s\n') % ctx)