comparison website/issues/detectors/patches.py @ 4024:c2d0d3e9099d website

svn repository setup
author Stefan Seefeld <stefan@users.sourceforge.net>
date Fri, 06 Feb 2009 13:16:31 +0000
parents
children 0942fe89e82e
comparison
equal deleted inserted replaced
4023:86c38b5aed66 4024:c2d0d3e9099d
1 # Auditor for patch files
2 # Patches should be declared as text/plain (also .py files),
3 # independent of what the browser says, and
4 # the "patch" keyword should get set automatically.
5
6 import posixpath
7
8 patchtypes = ('.diff', '.patch')
9 sourcetypes = ('.diff', '.patch', '.py')
10
11 def ispatch(file, types):
12 return posixpath.splitext(file)[1] in types
13
14 def patches_text_plain(db, cl, nodeid, newvalues):
15 if ispatch(newvalues['name'], sourcetypes):
16 newvalues['type'] = 'text/plain'
17
18 def patches_keyword(db, cl, nodeid, newvalues):
19 # Check whether there are any new files
20 newfiles = set(newvalues.get('files',()))
21 if nodeid:
22 newfiles -= set(db.issue.get(nodeid, 'files'))
23 # Check whether any of these is a patch
24 newpatch = False
25 for fileid in newfiles:
26 if ispatch(db.file.get(fileid, 'name'), patchtypes):
27 newpatch = True
28 break
29 if newpatch:
30 # Add the patch keyword if its not already there
31 patchid = db.keyword.lookup("patch")
32 oldkeywords = []
33 if nodeid:
34 oldkeywords = db.issue.get(nodeid, 'keywords')
35 if patchid in oldkeywords:
36 # This is already marked as a patch
37 return
38 if not newvalues.has_key('keywords'):
39 newvalues['keywords'] = oldkeywords
40 newvalues['keywords'].append(patchid)
41
42 def init(db):
43 db.file.audit('create', patches_text_plain)
44 db.issue.audit('create', patches_keyword)
45 db.issue.audit('set', patches_keyword)

Roundup Issue Tracker: http://roundup-tracker.org/