~ubuntu-branches/ubuntu/wily/xmms2/wily

« back to all changes in this revision

Viewing changes to waftools/gittools.py

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2008-05-29 10:14:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080529101425-ycw1nbd980uhvzfp
Tags: 0.4DrKosmos-4ubuntu1
* Merge from debian unstable (LP: #178477), remaining changes:
  - debian/control: Update Maintainer field
  - debian/control: add lpia to xmms2-plugin-alsa supported architectures
* This version reads AAC files (LP: #156359)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import sha
3
3
 
4
4
def gitsha(path):
5
 
        h = sha.sha()
6
 
        data = file(path).read()
7
 
        h.update("blob %d\0" % len(data))
8
 
        h.update(data)
9
 
        return h.hexdigest()
 
5
    h = sha.sha()
 
6
    data = file(path, 'rb').read()
 
7
    h.update("blob %d\0" % len(data))
 
8
    h.update(data)
 
9
    return h.hexdigest()
10
10
 
11
11
def git_info():
12
 
        commithash = os.popen('git-rev-parse --verify HEAD 2>/dev/null').read().strip()
13
 
        if not commithash:
14
 
                raise ValueError("Couldn't get hash")
15
 
        if os.getuid() == os.stat(".git/index").st_uid:
16
 
                os.system('git-update-index --refresh >/dev/null')
17
 
        else:
18
 
                print "NOT updating git cache, local changes might not be detected"
19
 
        changed = bool(os.popen('git-diff-index -r HEAD').read())
20
 
        return commithash, changed
 
12
    commithash = os.popen('git-rev-parse --verify HEAD 2>/dev/null').read().strip()
 
13
    if not commithash:
 
14
        raise ValueError("Couldn't get hash")
 
15
    if os.getuid() == os.stat(".git/index").st_uid:
 
16
        os.system('git-update-index --refresh >/dev/null')
 
17
    else:
 
18
        print "NOT updating git cache, local changes might not be detected"
 
19
    changed = bool(os.popen('git-diff-index -r HEAD').read())
 
20
    return commithash, changed
21
21
 
22
22
def snapshot_info():
23
 
        info = file('commithash').read().split('\n')
24
 
        
25
 
        commithash = info[0]
26
 
 
27
 
        changed = False
28
 
        for line in [a for a in info[2:] if a]:
29
 
                [mode, tag, sha, path] = line.split(None, 4)
30
 
                if tag != 'blob':
31
 
                        continue
32
 
                if gitsha(path) != sha:
33
 
                        changed = True
34
 
                        break
35
 
        return commithash, changed
 
23
    info = file('commithash').read().split('\n')
 
24
 
 
25
    commithash = info[0]
 
26
 
 
27
    changed = False
 
28
    for line in [a for a in info[2:] if a]:
 
29
        [mode, tag, sha, path] = line.split(None, 4)
 
30
        if tag != 'blob':
 
31
            continue
 
32
        if gitsha(path) != sha:
 
33
            changed = True
 
34
            break
 
35
    return commithash, changed
36
36
 
37
37
def get_info():
38
 
        try:
39
 
                return git_info()
40
 
        except:
41
 
                try:
42
 
                        return snapshot_info()
43
 
                except:
44
 
                        return 'Unknown', False
 
38
    try:
 
39
        return git_info()
 
40
    except:
 
41
        try:
 
42
            return snapshot_info()
 
43
        except:
 
44
            return 'Unknown', False
45
45
 
46
46
def get_info_str():
47
 
        commithash, changed = get_info()
48
 
        if changed:
49
 
                changed = " + local changes"
50
 
        else:
51
 
                changed = ""
 
47
    commithash, changed = get_info()
 
48
    if changed:
 
49
        changed = " + local changes"
 
50
    else:
 
51
        changed = ""
52
52
 
53
 
        return "%s%s" % (commithash, changed)
 
53
    return "%s%s" % (commithash, changed)