author | Dario Sestito <darios@symbian.org> |
Tue, 09 Mar 2010 12:36:24 +0000 | |
changeset 187 | dbf40764ca6a |
parent 143 | 6e81c130aa29 |
permissions | -rw-r--r-- |
143
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
2 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
3 |
# Copyright (C) 2010 Mozilla Foundation |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
4 |
# Copyright (C) 2010 Symbian Foundation |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
5 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
6 |
# This program is free software; you can redistribute it and/or |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
7 |
# modify it under the terms of the GNU General Public License |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
8 |
# as published by the Free Software Foundation; either version 2 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
9 |
# of the License, or (at your option) any later version. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
10 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
11 |
# This program is distributed in the hope that it will be useful, |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
14 |
# GNU General Public License for more details. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
15 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU General Public License |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
17 |
# along with this program; if not, write to the Free Software |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
19 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
20 |
# Initial Contributors: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
21 |
# Pat Downey <patd@symbian.org> |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
22 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
23 |
# Contributors: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
24 |
# Your name here? |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
25 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
26 |
# Description: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
27 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
28 |
# An extension to mercurial that adds the ability to specify a blacklist for |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
29 |
# a repository. That is to deny a changeset from being pushed/pulled/unbundled |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
30 |
# if it matches one of a set of patterns. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
31 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
32 |
# At present it can deny nodes based on their changeset id, a regular expression |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
33 |
# matched against the user field, or a regular expression matched against the |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
34 |
# changeset's file list. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
35 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
36 |
# Note: With the regular expression rules, if you want to match a string anywhere |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
37 |
# with in a string, e.g. create a rule against files within directories called |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
38 |
# 'internal' the rule would need to be ..*/internal/.*'. That is you need to be |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
39 |
# explicit in specifying a set of any characters otherwise it will perform a |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
40 |
# direct string comparison. # |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
41 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
42 |
# Requires sqlite extension (included in python 2.5 onwards) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
43 |
# * Available for python 2.4 in python-sqlite2 package on RHEL5.2+ |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
44 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
45 |
# Ideas for implementation came strongly from: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
46 |
# http://hg.mozilla.org/users/bsmedberg_mozilla.com/hghooks/file/tip/mozhghooks/pushlog.py |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
47 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
48 |
# |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
49 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
50 |
'''manage repository changeset blacklist |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
51 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
52 |
''' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
53 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
54 |
from mercurial import demandimport |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
55 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
56 |
demandimport.disable() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
57 |
try: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
58 |
import sqlite3 as sqlite |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
59 |
except ImportError: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
60 |
from pysqlite2 import dbapi2 as sqlite |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
61 |
demandimport.enable() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
62 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
63 |
import binascii |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
64 |
import os |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
65 |
import os.path |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
66 |
import re |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
67 |
import stat |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
68 |
import sys |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
69 |
import time |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
70 |
from datetime import datetime |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
71 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
72 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
73 |
# changeset identifier 12-40 hex chars |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
74 |
NODE_RE='^[0-9|a-f]{12,40}' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
75 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
76 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
77 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
78 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
79 |
def blacklist(ui,repo,*args,**opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
80 |
'''manage repository changeset blacklist |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
81 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
82 |
This extension is used to manage a blacklist for the repository. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
83 |
Can blacklist changesets by changeset id, and regular expressions against |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
84 |
the user field of a changeset and also a changesets file list. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
85 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
86 |
Current rules can be viewed using the [-l|--list] operation. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
87 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
88 |
Each modification to a blacklist is logged. These can be viewed using the |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
89 |
--auditlog operation. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
90 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
91 |
Each time a changeset is blocked/denied it's logged. These can be viewed |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
92 |
using the --blocklog operation. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
93 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
94 |
Types of changeset blacklist rules can be defined implicitly or explicitly: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
95 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
96 |
If a rule definition contains between 12 and 40 hexadecimal characters |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
97 |
it is assumed to be a rule matched against changeset id. Can be set |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
98 |
explicitly set with the -n flag to the --add operation. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
99 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
100 |
If a rule definition contains a '@' it is assumed to be a rule matched |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
101 |
against a changeset's user property. Can be set explicitly with |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
102 |
the -u flag to the --add operation. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
103 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
104 |
Otherwise the rule is assumed to be matched against a changeset's file |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
105 |
list. Can be set explicitly with the -f flag to the --add operation. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
106 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
107 |
When this extension is enabled a hook is also added to the |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
108 |
'pretxnchangegroup' action that will block any incoming changesets |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
109 |
(via pull/push/unbundle) if they are blacklisted. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
110 |
It won't block any local commits. |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
111 |
''' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
112 |
conn = openconn(ui, repo ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
113 |
if 'list' in opts and opts['list'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
114 |
listblacklistrule(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
115 |
elif 'blocklog' in opts and opts['blocklog'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
116 |
listblacklistblocklog(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
117 |
elif 'auditlog' in opts and opts['auditlog'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
118 |
listblacklistauditlog(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
119 |
elif 'enable' in opts and opts['enable'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
120 |
enableblacklistrule(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
121 |
elif 'disable' in opts and opts['disable'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
122 |
disableblacklistrule(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
123 |
elif 'remove' in opts and opts['remove'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
124 |
removeblacklistrule(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
125 |
elif 'add' in opts and opts['add'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
126 |
addblacklistrule(ui,conn,args,opts) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
127 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
128 |
ui.warn( 'invalid operation specified\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
129 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
130 |
conn.close( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
131 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
132 |
####### Database setup methods |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
133 |
# this part derived from mozilla's pushlog.py hook |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
134 |
def openconn(ui,repo): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
135 |
blacklistdb = os.path.join(repo.path, 'blacklist.db') |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
136 |
createdb = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
137 |
if not os.path.exists(blacklistdb): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
138 |
createdb = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
139 |
conn = sqlite.connect(blacklistdb) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
140 |
if not createdb and not schemaexists(conn): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
141 |
createdb = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
142 |
if createdb: |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
143 |
createblacklistdb(ui,conn) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
144 |
st = os.stat(blacklistdb) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
145 |
os.chmod(blacklistdb, st.st_mode | stat.S_IWGRP) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
146 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
147 |
return conn |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
148 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
149 |
# Derived from mozilla's pushlog hook |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
150 |
def schemaexists(conn): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
151 |
return 3 == conn.execute("SELECT COUNT(*) FROM SQLITE_MASTER WHERE name IN ( ?, ?, ?)" , ['blacklist_rule','blacklist_auditlog','blacklist_blocklog']).fetchone()[0] |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
152 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
153 |
# Derived from mozilla's pushlog hook |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
154 |
def createblacklistdb(ui,conn): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
155 |
# record of different blacklist rule, type should be either 'node' or 'file' or 'user' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
156 |
# 'node' - compare pattern with changeset identifier |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
157 |
# 'file' - used as regular expression against changeset file manifest |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
158 |
# 'user' - used as regular expression against changeset author/user |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
159 |
# (id,pattern,type,enabled) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
160 |
conn.execute("CREATE TABLE IF NOT EXISTS blacklist_rule (id INTEGER PRIMARY KEY AUTOINCREMENT, pattern TEXT, type TEXT, enabled INTEGER,comment TEXT)") |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
161 |
conn.execute("CREATE UNIQUE INDEX IF NOT EXISTS blacklist_rule_idx ON blacklist_rule (pattern,type)" ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
162 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
163 |
# records additions and modifications to the blacklist_rule table |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
164 |
# (id, operation, rule_id, user, date, comment) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
165 |
conn.execute("CREATE TABLE IF NOT EXISTS blacklist_auditlog (id INTEGER PRIMARY KEY AUTOINCREMENT, operation TEXT, rule_id INTEGER, user TEXT, date INTEGER, comment TEXT)") |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
166 |
conn.execute("CREATE INDEX IF NOT EXISTS blacklist_auditlog_rule_idx ON blacklist_auditlog (rule_id)" ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
167 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
168 |
# log attempted pushes and the http users trying to push a blocked changeset |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
169 |
# (id,rule_id,cset_id, cset_user, cset_desc, user,date) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
170 |
conn.execute("CREATE TABLE IF NOT EXISTS blacklist_blocklog (id INTEGER PRIMARY KEY AUTOINCREMENT, rule_id INTEGER, cset_id TEXT, cset_user TEXT, cset_desc TEXT, user TEXT, date INTEGER)") |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
171 |
conn.execute("CREATE INDEX IF NOT EXISTS blacklist_blocklog_rule_idx ON blacklist_blocklog (rule_id)" ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
172 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
173 |
conn.commit() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
174 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
175 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
176 |
# Methods for extension commands |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
177 |
def __getblacklistruletype( ui, pattern, opts ): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
178 |
type=None |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
179 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
180 |
if opts['nodeType'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
181 |
type = 'node' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
182 |
elif opts['fileType'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
183 |
type = 'file' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
184 |
elif opts['userType'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
185 |
type = 'user' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
186 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
187 |
# try and work out type of blacklist if none specified |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
188 |
# default to regexp |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
189 |
if type == None : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
190 |
if re.match( NODE_RE, pattern ) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
191 |
type = 'node' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
192 |
elif '@' in pattern : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
193 |
type = 'user' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
194 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
195 |
type = 'file' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
196 |
ui.note( 'type implicitly set to \'%s\'\n' % type ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
197 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
198 |
return type |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
199 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
200 |
def addblacklistrule(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
201 |
ret = 1 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
202 |
if len(args) == 1 : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
203 |
createrule = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
204 |
pattern = args[0] |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
205 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
206 |
type = __getblacklistruletype( ui, pattern, opts ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
207 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
208 |
if type == 'node' : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
209 |
# if pattern has been specified as a node type |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
210 |
# check that pattern is a valid node |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
211 |
if not re.match( NODE_RE, pattern ) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
212 |
ui.warn( 'node should be 12 or 40 characters.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
213 |
createrule = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
214 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
215 |
if createrule : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
216 |
comment = None |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
217 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
218 |
if 'desc' in opts and opts['desc'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
219 |
if opts['desc'] != '' : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
220 |
comment = opts['desc'] |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
221 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
222 |
insertblacklistrule(ui,conn,pattern,type, comment=comment) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
223 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
224 |
ui.warn( 'missing pattern argument.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
225 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
226 |
return ret |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
227 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
228 |
def removeblacklistrule(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
229 |
if len(args) == 1 : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
230 |
deleteblacklistrule(ui,conn,args[0]) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
231 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
232 |
ui.warn( 'rule id argument required.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
233 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
234 |
return 0 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
235 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
236 |
def disableblacklistrule(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
237 |
if len(args) == 1 : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
238 |
updateblacklistrule(ui,conn,args[0],False) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
239 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
240 |
ui.warn( 'rule id argument required.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
241 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
242 |
return 0 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
243 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
244 |
def enableblacklistrule(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
245 |
if len(args) == 1 : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
246 |
updateblacklistrule(ui,conn,args[0],True) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
247 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
248 |
ui.warn( 'rule id argument required.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
249 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
250 |
return 0 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
251 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
252 |
def listblacklistrule(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
253 |
if len(args) in (0,1) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
254 |
res = selectblacklistrule(ui,conn,args) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
255 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
256 |
printblacklist(ui,res) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
257 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
258 |
ui.warn( 'too many arguments.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
259 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
260 |
return 0 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
261 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
262 |
def listblacklistauditlog(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
263 |
if len(args) in (0,1) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
264 |
res = selectblacklistauditlog(ui, conn, args ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
265 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
266 |
printauditlog(ui,res) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
267 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
268 |
ui.warn( 'too many arguments.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
269 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
270 |
return 0 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
271 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
272 |
def listblacklistblocklog(ui,conn,args,opts): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
273 |
if len(args) in (0,1) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
274 |
res = selectblacklistblocklog(ui, conn, args ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
275 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
276 |
printblocklog(ui,res) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
277 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
278 |
ui.warn( 'too many arguments.\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
279 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
280 |
return 0 |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
281 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
282 |
def insertblacklistaudit(ui, conn, operation, rule_id, comment=None ): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
283 |
user = __getenvuser( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
284 |
audit_date = int(time.time()) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
285 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
286 |
audit_sql = 'INSERT INTO blacklist_auditlog ( operation, rule_id, user, date, comment ) VALUES ( ?, ?, ?, ?, ? )' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
287 |
conn.execute( audit_sql, (operation, rule_id, user, audit_date, comment ) ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
288 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
289 |
def insertblacklistrule(ui, conn, pattern, type, enabled=True, comment=None): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
290 |
rule_sql = 'INSERT INTO blacklist_rule ( pattern, type, enabled,comment ) VALUES ( ?, ?, ?, ? )' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
291 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
292 |
res = conn.execute( rule_sql, (pattern,type,enabled,comment) ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
293 |
rule_id= res.lastrowid |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
294 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
295 |
insertblacklistaudit(ui, conn, 'add', rule_id,comment=comment ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
296 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
297 |
conn.commit( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
298 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
299 |
def __getenvuser( ): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
300 |
# look at REMOTE_USER first |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
301 |
# then look at LOGUSER |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
302 |
# then look at USER |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
303 |
for e in ['REMOTE_USER','SUDO_USER','LOGUSER','USER'] : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
304 |
if e in os.environ : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
305 |
user = '%s:%s' %( e, os.environ.get( e ) ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
306 |
break |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
307 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
308 |
return user |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
309 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
310 |
def insertblacklistblocklog( ui, conn, rule, ctx ): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
311 |
# (id, rule_id, user, date) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
312 |
rule_id=rule[0] |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
313 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
314 |
log_user = __getenvuser( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
315 |
audit_date = int(time.time()) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
316 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
317 |
ctx_node = binascii.hexlify(ctx.node()) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
318 |
ctx_user = ctx.user() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
319 |
ctx_desc = ctx.description() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
320 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
321 |
log_sql = 'INSERT INTO blacklist_blocklog (rule_id,user,date,cset_id,cset_user,cset_desc) VALUES (?,?,?,?,?,?)' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
322 |
conn.execute( log_sql, (rule_id,log_user,audit_date, ctx_node, ctx_user, ctx_desc)) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
323 |
conn.commit() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
324 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
325 |
def updateblacklistrule(ui, conn, rule_id, enabled): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
326 |
rule_sql = 'UPDATE blacklist_rule SET enabled=? WHERE id=?' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
327 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
328 |
conn.execute( rule_sql, [enabled, rule_id] ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
329 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
330 |
insertblacklistaudit(ui, conn, 'update', rule_id, 'enabled=%s' % enabled ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
331 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
332 |
conn.commit( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
333 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
334 |
def deleteblacklistrule(ui, conn, rule_id ): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
335 |
if rule_id != None : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
336 |
res = selectblacklistrule(ui, conn, rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
337 |
processed = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
338 |
for (id,pattern,type,enabled,comment) in res : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
339 |
comment = 'deleted: pattern=%s, type=%s, enabled=%s' % (pattern, type, enabled) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
340 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
341 |
rule_sql = 'DELETE FROM blacklist_rule WHERE id=?' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
342 |
conn.execute( rule_sql, [rule_id] ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
343 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
344 |
insertblacklistaudit(ui, conn, 'delete', rule_id, comment) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
345 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
346 |
conn.commit( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
347 |
processed = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
348 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
349 |
if not processed : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
350 |
ui.warn( 'no matching blacklist rule found with id %s\n' % rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
351 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
352 |
ui.warn( 'no rule id specified\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
353 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
354 |
def selectblacklistrule(ui, conn, rule_id ): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
355 |
# (id, operation, rule_id, user, date, comment) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
356 |
if rule_id : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
357 |
rule_sql = 'SELECT id,pattern,type,enabled,comment FROM blacklist_rule WHERE id=? ORDER BY id ASC' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
358 |
res = conn.execute( rule_sql, rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
359 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
360 |
rule_sql = 'SELECT id,pattern,type,enabled,comment FROM blacklist_rule ORDER BY id ASC' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
361 |
res = conn.execute( rule_sql ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
362 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
363 |
return res |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
364 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
365 |
def selectblacklistauditlog(ui,conn,rule_id=None) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
366 |
# (id, operation, rule_id, user, date, comment) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
367 |
if rule_id : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
368 |
rule_sql = 'SELECT id,operation,rule_id,user,date,comment FROM blacklist_auditlog WHERE rule_id=? ORDER BY date ASC' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
369 |
res = conn.execute( rule_sql, rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
370 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
371 |
rule_sql = 'SELECT id,operation,rule_id,user,date,comment FROM blacklist_auditlog ORDER BY date ASC' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
372 |
res = conn.execute( rule_sql ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
373 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
374 |
return res |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
375 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
376 |
def selectblacklistblocklog(ui,conn,rule_id=None) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
377 |
# (id, rule_id, node, user, date) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
378 |
if rule_id : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
379 |
rule_sql = 'SELECT id,rule_id,cset_id,cset_user,cset_desc,user,date FROM blacklist_blocklog WHERE rule_id=? ORDER BY date ASC' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
380 |
res = conn.execute( rule_sql, rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
381 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
382 |
rule_sql = 'SELECT id,rule_id,cset_id,cset_user,cset_desc,user,date FROM blacklist_blocklog ORDER BY date ASC' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
383 |
res = conn.execute( rule_sql ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
384 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
385 |
return res |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
386 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
387 |
def printblacklist(ui,res): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
388 |
for r in res : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
389 |
(id,pattern,type,enabled,comment) = r |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
390 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
391 |
if enabled == 1 : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
392 |
enabled = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
393 |
elif enabled == 0 : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
394 |
enabled = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
395 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
396 |
ui.write( 'rule: %d:%s\n' % (id,type) ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
397 |
ui.write( 'pattern: %s\n' % pattern ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
398 |
ui.write( 'enabled: %s\n' % enabled ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
399 |
if comment : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
400 |
ui.write( 'comment: %s\n' % comment ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
401 |
ui.write( '\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
402 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
403 |
def printauditlog(ui,res): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
404 |
for r in res : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
405 |
(id, operation, rule_id, user, date, comment) = r |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
406 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
407 |
date = datetime.utcfromtimestamp(date).isoformat() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
408 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
409 |
if not comment : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
410 |
comment = '' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
411 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
412 |
ui.write( 'date: %s\n' % date ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
413 |
ui.write( 'operation: %s\n' % operation ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
414 |
ui.write( 'user: %s\n' % user ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
415 |
ui.write( 'rule: %s\n' % rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
416 |
ui.write( 'comment: %s\n' % comment ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
417 |
ui.write( '\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
418 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
419 |
def printblocklog(ui,res): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
420 |
for r in res : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
421 |
(id, rule_id, cset_id, cset_user, cset_desc, user, date) = r |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
422 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
423 |
date = datetime.utcfromtimestamp(date).isoformat() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
424 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
425 |
ui.write( 'cset: %s\n' % cset_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
426 |
ui.write( 'cset-user: %s\n' % cset_user) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
427 |
ui.write( 'cset-desc: %s\n' % cset_desc ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
428 |
ui.write( 'rule: %s\n' % rule_id ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
429 |
ui.write( 'date: %s\n' % date ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
430 |
ui.write( 'user: %s\n' % user ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
431 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
432 |
ui.write( '\n' ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
433 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
434 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
435 |
# Hook specific functions follow |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
436 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
437 |
def excludecsetbyfile(ctx,pattern): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
438 |
exclude = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
439 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
440 |
file_re = re.compile( '%s' % pattern, re.I ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
441 |
for f in ctx.files() : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
442 |
if file_re.match( f ) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
443 |
exclude = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
444 |
break |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
445 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
446 |
return exclude |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
447 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
448 |
def excludecsetbynode(ctx,pattern): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
449 |
exclude = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
450 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
451 |
node = binascii.hexlify(ctx.node()) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
452 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
453 |
if node.startswith( pattern ) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
454 |
exclude = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
455 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
456 |
return exclude |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
457 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
458 |
def excludecsetbyuser(ctx,pattern): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
459 |
exclude = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
460 |
userStr = ctx.user() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
461 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
462 |
user_re = re.compile( '^.*%s.*$' % pattern, re.I ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
463 |
if user_re.match( userStr ) : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
464 |
exclude = True |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
465 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
466 |
return exclude |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
467 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
468 |
def excludeblacklistcset(ui,conn,ctx): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
469 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
470 |
bl_sql = 'SELECT id,pattern,type FROM blacklist_rule WHERE enabled=1' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
471 |
res = conn.execute( bl_sql ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
472 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
473 |
(exclude,rule) = (False,None) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
474 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
475 |
for (id,pattern,type) in res : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
476 |
if type == 'node' : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
477 |
exclude = excludecsetbynode(ctx,pattern) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
478 |
elif type == 'user' : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
479 |
exclude = excludecsetbyuser(ctx,pattern) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
480 |
elif type == 'file' : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
481 |
exclude = excludecsetbyfile(ctx,pattern) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
482 |
else : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
483 |
ui.warn('unrecognised rule type \'%s\'' % type ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
484 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
485 |
if exclude : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
486 |
rule = (id,pattern,type) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
487 |
break |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
488 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
489 |
return (exclude,rule) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
490 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
491 |
# The hook method that is used to block bad changesets from being introduced |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
492 |
# to the current repository |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
493 |
def pretxnchangegroup(ui,repo,hooktype,node,**args): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
494 |
start = repo[node].rev() |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
495 |
end = len(repo) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
496 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
497 |
conn = openconn(ui, repo ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
498 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
499 |
blocked = False |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
500 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
501 |
for rev in xrange(start, end): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
502 |
ctx = repo[rev] |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
503 |
(blocked,rule) = excludeblacklistcset( ui, conn, ctx) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
504 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
505 |
if blocked : |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
506 |
insertblacklistblocklog( ui, conn, rule, ctx ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
507 |
(id,pattern,type) = rule |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
508 |
ui.write( 'blocked: cset %s in changegroup blocked by blacklist\n' % str(ctx) ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
509 |
ui.write( 'blocked-reason: %s matched against \'%s\'\n' % ( type,pattern )) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
510 |
break |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
511 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
512 |
conn.close( ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
513 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
514 |
return blocked |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
515 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
516 |
def setupblacklisthook(ui): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
517 |
ui.setconfig('hooks', 'pretxnchangegroup.blacklist', pretxnchangegroup) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
518 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
519 |
def reposetup(ui,repo): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
520 |
# print 'in blacklist reposetup' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
521 |
setupblacklisthook( ui ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
522 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
523 |
def uisetup(ui): |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
524 |
# print 'in blacklist uisetup' |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
525 |
setupblacklisthook( ui ) |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
526 |
|
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
527 |
cmdtable = { |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
528 |
'blacklist': (blacklist, |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
529 |
[ |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
530 |
('l','list',None,'list blacklist entries'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
531 |
('','blocklog',None,'list blocked changesets'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
532 |
('','auditlog',None,'show audit log for blacklist'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
533 |
('a','add',None,'add node to blacklist'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
534 |
('d','disable',None,'disable blacklist rule'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
535 |
('e','enable',None,'enable blacklist rule'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
536 |
('r','remove',None,'remove node from blacklist'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
537 |
('n','nodeType',False,'parse argument as node to blacklist'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
538 |
('f','fileType',False,'parse argument as file path to blacklist'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
539 |
('u','userType',False,'parse argument as user regexp to blacklist'), |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
540 |
('','desc','','comment to attach to rule')], |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
541 |
"") |
6e81c130aa29
Add initial version of blacklist mercurial extension for use to exclude
Pat Downey <patd@symbian.org>
parents:
diff
changeset
|
542 |
} |