~yasumoto7/five-a-day/icon_countdown

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python

# Copyright 2008 (C) Canonical Ltd.

import os
import sys
import locale
from gettext import gettext as _
import gettext

from fiveaday import bzr, files, parser, signature


def main():
    gettext.textdomain("5-a-day")
    commands, flags, data = parser.parse_args()
    first_run = False

    # TODO: use verbose option
    username = files.get_lpid()
    if not username:
        return 102 #102: username not defined

    if not os.path.exists(files.local_branch()):
        bzr.update_branch()
        first_run = True

    if "add" in commands:
        if not first_run:
            bzr.update_branch()
            return bzr.add(data, force_push=True)
        return bzr.add(data, flags["force"])

    if flags["update"]:
        if not first_run:
            err = bzr.update_branch()
            if err:
                # stop if creating/updating branch was not successful
                print >> sys.stderr, _("bzr failed with error code"), err
                return 103 #103: error while updating bzr branch
        return signature.update(flags["html"], flags["yesterday"])

    if "add-tags" in commands:
        files.add_tags(data)

    if "remove-tags" in commands:
        files.remove_tags(data)

    if "add-teams" in commands:
        if files.add_teams(data):
            bzr.add_if_not_in_inventory(files.local_branch(), 
                                        os.path.basename(files.team_file()))
            bzr.commit_changes(force=True)
            return 0
        return 1
    if "remove-teams" in commands:
        if files.remove_teams(data):
            bzr.add_if_not_in_inventory(files.local_branch(), 
                                        os.path.basename(files.team_file()))
            bzr.commit_changes(force=True)
            return 0
        return 1

    if flags["show-teams"]:
        files.show_teams()
        return 0
    
    if flags["show-tags"]:
        files.show_tags()
        return 0


if __name__ == "__main__":
    sys.exit(main())