/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Classify a commit based on the types of files it changed."""

from bzrlib import urlutils 

def classify_filename(name):
    """Classify a file based on its name.
    
    :param name: File path.
    :return: One of code, documentation, translation or art. 
        None if determining the file type failed.
    """
    # FIXME: Use mime types?
    basename = urlutils.basename(name)
    try:
        extension = basename.split(".")[1]
        if extension in ("c", "py", "cpp", "rb"):
            return "code"
        if extension in ("html", "xml", "txt", "rst"):
            return "documentation"
        if extension in ("po"):
            return "translation"
        if extension in ("svg", "png", "jpg"):
            return "art"
    except IndexError:
        if basename in ("README", "NEWS", "TODO"):
            return "documentation"

    return None

def classify_delta(delta):
    types = []
    for d in delta.added + delta.modified:
        types.append(classify_filename(d[0]))
    return types