/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.140.26 by Jelmer Vernooij
Add copyright headers.
1
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
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.26 by Jelmer Vernooij
Add copyright headers.
18
from bzrlib import urlutils
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
19
from bzrlib.trace import mutter
20
0.140.15 by Jelmer Vernooij
Add code for classifying commits.
21
22
def classify_filename(name):
23
    """Classify a file based on its name.
24
    
25
    :param name: File path.
26
    :return: One of code, documentation, translation or art. 
27
        None if determining the file type failed.
28
    """
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
29
    # FIXME: Use mime types? Ohcount? 
0.140.26 by Jelmer Vernooij
Add copyright headers.
30
    extension = os.path.splitext(name)[1]
31
    if extension in (".c", ".h", ".py", ".cpp", ".rb", ".pm", ".pl", ".ac"):
32
        return "code"
33
    if extension in (".html", ".xml", ".txt", ".rst", ".TODO"):
34
        return "documentation"
35
    if extension in (".po",):
36
        return "translation"
37
    if extension in (".svg", ".png", ".jpg"):
38
        return "art"
39
    if not extension:
40
        basename = urlutils.basename(name)
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
41
        if basename in ("README", "NEWS", "TODO", 
42
                        "AUTHORS", "COPYING"):
0.140.15 by Jelmer Vernooij
Add code for classifying commits.
43
            return "documentation"
0.140.26 by Jelmer Vernooij
Add copyright headers.
44
        if basename in ("Makefile",):
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
45
            return "code"
0.140.15 by Jelmer Vernooij
Add code for classifying commits.
46
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
47
    mutter("don't know how to classify %s", name)
0.140.15 by Jelmer Vernooij
Add code for classifying commits.
48
    return None
49
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
50
0.140.15 by Jelmer Vernooij
Add code for classifying commits.
51
def classify_delta(delta):
0.140.18 by Jelmer Vernooij
Add credits command, test classify code by default, add comments to classify code.
52
    """Determine what sort of changes a delta contains.
53
54
    :param delta: A TreeDelta to inspect
55
    :return: List with classes found (see classify_filename)
56
    """
57
    # TODO: This is inaccurate, since it doesn't look at the 
58
    # number of lines changed in a file.
0.140.15 by Jelmer Vernooij
Add code for classifying commits.
59
    types = []
60
    for d in delta.added + delta.modified:
61
        types.append(classify_filename(d[0]))
62
    return types