/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/stats/classify.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2010 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
16
 
"""Classify a commit based on the types of files it changed."""
17
 
 
18
 
import os.path
19
 
 
20
 
from ... import urlutils
21
 
from ...trace import mutter
22
 
 
23
 
 
24
 
def classify_filename(name):
25
 
    """Classify a file based on its name.
26
 
 
27
 
    :param name: File path.
28
 
    :return: One of code, documentation, translation or art.
29
 
        None if determining the file type failed.
30
 
    """
31
 
    # FIXME: Use mime types? Ohcount?
32
 
    # TODO: It will be better move those filters to properties file
33
 
    # and have possibility to determining own types !?
34
 
    extension = os.path.splitext(name)[1]
35
 
    if extension in (".c", ".h", ".py", ".cpp", ".rb", ".pm", ".pl", ".ac",
36
 
                     ".java", ".cc", ".proto", ".yy", ".l"):
37
 
        return "code"
38
 
    if extension in (".html", ".xml", ".txt", ".rst", ".TODO"):
39
 
        return "documentation"
40
 
    if extension in (".po",):
41
 
        return "translation"
42
 
    if extension in (".svg", ".png", ".jpg"):
43
 
        return "art"
44
 
    if not extension:
45
 
        basename = urlutils.basename(name)
46
 
        if basename in ("README", "NEWS", "TODO",
47
 
                        "AUTHORS", "COPYING"):
48
 
            return "documentation"
49
 
        if basename in ("Makefile",):
50
 
            return "code"
51
 
 
52
 
    mutter("don't know how to classify %s", name)
53
 
    return None
54
 
 
55
 
 
56
 
def classify_delta(delta):
57
 
    """Determine what sort of changes a delta contains.
58
 
 
59
 
    :param delta: A TreeDelta to inspect
60
 
    :return: List with classes found (see classify_filename)
61
 
    """
62
 
    # TODO: This is inaccurate, since it doesn't look at the
63
 
    # number of lines changed in a file.
64
 
    types = []
65
 
    for d in delta.added + delta.modified:
66
 
        types.append(classify_filename(d.path[1] or d.path[0]))
67
 
    return types