[Python-checkins] r61014 - tracker/instances/python-dev/detectors/patches.py
martin.v.loewis
python-checkins at python.org
Sat Feb 23 21:47:23 CET 2008
Author: martin.v.loewis
Date: Sat Feb 23 21:47:22 2008
New Revision: 61014
Added:
tracker/instances/python-dev/detectors/patches.py (contents, props changed)
Log:
Set content type of .diff, .patch and .py to text/plain. Fixes #177.
Also add patch keyword for patches.
Added: tracker/instances/python-dev/detectors/patches.py
==============================================================================
--- (empty file)
+++ tracker/instances/python-dev/detectors/patches.py Sat Feb 23 21:47:22 2008
@@ -0,0 +1,45 @@
+# Auditor for patch files
+# Patches should be declared as text/plain (also .py files),
+# independent of what the browser says, and
+# the "patch" keyword should get set automatically.
+
+import posixpath
+
+patchtypes = ('.diff', '.patch')
+sourcetypes = ('.diff', '.patch', '.py')
+
+def ispatch(file, types):
+ return posixpath.splitext(file)[1] in types
+
+def patches_text_plain(db, cl, nodeid, newvalues):
+ if ispatch(newvalues['name'], sourcetypes):
+ newvalues['type'] = 'text/plain'
+
+def patches_keyword(db, cl, nodeid, newvalues):
+ # Check whether there are any new files
+ newfiles = set(newvalues.get('files',()))
+ if nodeid:
+ newfiles -= set(db.issue.get(nodeid, 'files'))
+ # Check whether any of these is a patch
+ newpatch = False
+ for fileid in newfiles:
+ if ispatch(db.file.get(fileid, 'name'), patchtypes):
+ newpatch = True
+ break
+ if newpatch:
+ # Add the patch keyword if its not already there
+ patchid = db.keyword.lookup("patch")
+ oldkeywords = []
+ if nodeid:
+ oldkeywords = db.issue.get(nodeid, 'keywords')
+ if patchid in oldkeywords:
+ # This is already marked as a patch
+ return
+ if not newvalues.has_key('keywords'):
+ newvalues['keywords'] = oldkeywords
+ newvalues['keywords'].append(patchid)
+
+def init(db):
+ db.file.audit('create', patches_text_plain)
+ db.issue.audit('create', patches_keyword)
+ db.issue.audit('set', patches_keyword)
More information about the Python-checkins
mailing list