bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
1 |
# Copyright (C) 2008, 2010 Jelmer Vernooij <jelmer@samba.org>
|
|
0.140.26
by Jelmer Vernooij
Add copyright headers. |
2 |
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
||
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
||
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
16 |
"""Classify a commit based on the types of files it changed."""
|
17 |
||
|
0.140.49
by Jelmer Vernooij
use absolute_import everywhere. |
18 |
from __future__ import absolute_import |
19 |
||
|
0.150.1
by Lukáš Lalinský
Minor classify_filename fixes |
20 |
import os.path |
|
0.140.27
by Vincent Ladeuil
Fix missing import. |
21 |
|
|
6645.1.1
by Jelmer Vernooij
Bundle the stats plugin. |
22 |
from ... import urlutils |
23 |
from ...trace import mutter |
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
24 |
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
25 |
|
26 |
def classify_filename(name): |
|
27 |
"""Classify a file based on its name. |
|
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
28 |
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
29 |
:param name: File path.
|
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
30 |
:return: One of code, documentation, translation or art.
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
31 |
None if determining the file type failed.
|
32 |
"""
|
|
|
0.149.1
by vitaliy.kulikov
Java type added |
33 |
# FIXME: Use mime types? Ohcount?
|
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
34 |
# TODO: It will be better move those filters to properties file
|
|
0.149.1
by vitaliy.kulikov
Java type added |
35 |
# and have possibility to determining own types !?
|
|
0.140.26
by Jelmer Vernooij
Add copyright headers. |
36 |
extension = os.path.splitext(name)[1] |
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
37 |
if extension in (".c", ".h", ".py", ".cpp", ".rb", ".pm", ".pl", ".ac", |
|
0.140.43
by Stewart Smith
classify .cc, .proto, .yy and .l as code (c++, protobuf, yacc and flex) |
38 |
".java", ".cc", ".proto", ".yy", ".l"): |
|
0.140.26
by Jelmer Vernooij
Add copyright headers. |
39 |
return "code" |
40 |
if extension in (".html", ".xml", ".txt", ".rst", ".TODO"): |
|
41 |
return "documentation" |
|
42 |
if extension in (".po",): |
|
43 |
return "translation" |
|
44 |
if extension in (".svg", ".png", ".jpg"): |
|
45 |
return "art" |
|
46 |
if not extension: |
|
47 |
basename = urlutils.basename(name) |
|
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
48 |
if basename in ("README", "NEWS", "TODO", |
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
49 |
"AUTHORS", "COPYING"): |
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
50 |
return "documentation" |
|
0.140.26
by Jelmer Vernooij
Add copyright headers. |
51 |
if basename in ("Makefile",): |
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
52 |
return "code" |
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
53 |
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
54 |
mutter("don't know how to classify %s", name) |
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
55 |
return None |
56 |
||
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
57 |
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
58 |
def classify_delta(delta): |
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
59 |
"""Determine what sort of changes a delta contains. |
60 |
||
61 |
:param delta: A TreeDelta to inspect
|
|
62 |
:return: List with classes found (see classify_filename)
|
|
63 |
"""
|
|
|
0.140.34
by John Arbash Meinel
Merge vitaliy.kulikov's .java addition |
64 |
# TODO: This is inaccurate, since it doesn't look at the
|
|
0.140.18
by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code. |
65 |
# number of lines changed in a file.
|
|
0.140.15
by Jelmer Vernooij
Add code for classifying commits. |
66 |
types = [] |
67 |
for d in delta.added + delta.modified: |
|
68 |
types.append(classify_filename(d[0])) |
|
69 |
return types |