bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
1 |
"""Classify a commit based on the types of files it changed."""
|
2 |
||
3 |
from bzrlib import urlutils |
|
4 |
||
5 |
def classify_filename(name): |
|
6 |
"""Classify a file based on its name. |
|
7 |
|
|
8 |
:param name: File path.
|
|
9 |
:return: One of code, documentation, translation or art.
|
|
10 |
None if determining the file type failed.
|
|
11 |
"""
|
|
12 |
# FIXME: Use mime types?
|
|
13 |
basename = urlutils.basename(name) |
|
14 |
try: |
|
15 |
extension = basename.split(".")[1] |
|
16 |
if extension in ("c", "py", "cpp", "rb"): |
|
17 |
return "code" |
|
18 |
if extension in ("html", "xml", "txt", "rst"): |
|
19 |
return "documentation" |
|
20 |
if extension in ("po"): |
|
21 |
return "translation" |
|
22 |
if extension in ("svg", "png", "jpg"): |
|
23 |
return "art" |
|
24 |
except IndexError: |
|
25 |
if basename in ("README", "NEWS", "TODO"): |
|
26 |
return "documentation" |
|
27 |
||
28 |
return None |
|
29 |
||
30 |
def classify_delta(delta): |
|
31 |
types = [] |
|
32 |
for d in delta.added + delta.modified: |
|
33 |
types.append(classify_filename(d[0])) |
|
34 |
return types |