~5-a-day/five-a-day/trunk

« back to all changes in this revision

Viewing changes to fiveaday/parser.py

  • Committer: Daniel Holbach
  • Date: 2009-02-27 09:27:36 UTC
  • Revision ID: daniel.holbach@canonical.com-20090227092736-lnndwvl2wansln5y
* Probably the last release of this package.
* Deprecate almost everything. The client and applet are not necessary any 
  more, just sign up for the ~5-a-day-participants team in Launchpad.
* Only leave "5-a-day --update" to generate a nice signature for you.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from gettext import gettext as _
18
18
import getopt
 
19
import glob
19
20
import os
20
21
import sys
21
22
 
24
25
 
25
26
 
26
27
def usage():
27
 
    # TODO: update usage string
28
 
    print _("""5-a-day --add <bug numbers>        add <bug numbers> to your 5-a-day
29
 
    -f | --force                   force commit to the remote branch
30
 
    --local                        only commit locally
31
 
 
32
 
5-a-day --update                   update ~/.signature with the bugs you've worked on
 
28
    print _("""5-a-day --update                   update ~/.signature with the bugs you've worked on
33
29
    --html                         update ~/.signature and print HTML signature
34
30
    --yesterday                    update ~/.signature with yesterdays bugs
35
31
 
36
 
5-a-day --add-team(s) <team(s)>    add your LoCo team
37
 
5-a-day --remove-team(s) <team(s)> remove <tag> from your team list
38
 
5-a-day --show-team(s)             show current team(s)
39
 
 
40
 
5-a-day --add-tag(s) <tag(s)>      tag subsequent bugs with <tag>
41
 
5-a-day --remove-tag(s) <tag(s)>   remove <tag> from your tag list
42
 
5-a-day --show-tag(s)              show current tag(s)""")
43
 
 
44
 
 
45
 
# TODO: Option "-n"/"--no-remote" to never update/commit the branch
 
32
Instructions:
 
33
 - join https://launchpad.net/~5-a-day-participants
 
34
 - run  bzr launchpad-login <your Launchpad ID>""")
 
35
    if glob.glob(os.path.expanduser("~")+"/.5-a-day*"):
 
36
        print _(" - it's safe to remove all ~/.5-a-day*""")
46
37
 
47
38
 
48
39
def parse_args():
55
46
 
56
47
    try:
57
48
        long_opts = [
58
 
            "add",
59
 
            "add-tag",
60
 
            "add-tags",
61
 
            "add-team",
62
 
            "add-teams",
63
 
            "force",
64
 
            "local",
65
49
            "help",
 
50
            "update",
66
51
            "html",
67
 
            "remove-tag",
68
 
            "remove-tags",
69
 
            "remove-team",
70
 
            "remove-teams",
71
 
            "show-tag",
72
 
            "show-tags",
73
 
            "show-team",
74
 
            "show-teams",
75
 
            "update",
76
 
            "verbose",
77
52
            "yesterday"
78
53
        ]
79
54
        opts, args = getopt.gnu_getopt(sys.argv[1:], "afhuv", long_opts)
85
60
 
86
61
    commands = set()
87
62
    flags = {
88
 
        "force": False,
89
 
        "local": False,
90
63
        "html": False,
91
 
        "show-tags": False,
92
 
        "show-teams": False,
93
 
        "update": False,
94
 
        "verbose": False,
95
64
        "yesterday": False,
96
65
    }
97
66
 
98
67
    for o, a in opts:
99
 
        if o in ("-a", "--add"):
100
 
            commands.add("add")
101
 
        elif o in ("--add-tag", "--add-tags"):
102
 
            commands.add("add-tags")
103
 
        elif o in ("--add-team", "--add-teams"):
104
 
            commands.add("add-teams")
105
 
        elif o in ("-f", "--force"):
106
 
            flags["force"] = True
107
 
        elif o in ("--local"):
108
 
            flags["local"] = True
109
 
        elif o in ("-h", "--help"):
 
68
        if o in ("-h", "--help"):
110
69
            usage()
111
70
            sys.exit(0)
112
71
        elif o in ("--html"):
113
72
            flags["html"] = True
114
 
        elif o in ("--remove-tag", "--remove-tags"):
115
 
            commands.add("remove-tags")
116
 
        elif o in ("--remove-team", "--remove-teams"):
117
 
            commands.add("remove-teams")
118
 
        elif o in ("--show-tag", "--show-tags"):
119
 
            flags["show-tags"] = True
120
 
        elif o in ("--show-team", "--show-teams"):
121
 
            flags["show-teams"] = True
122
73
        elif o in ("-u", "--update"):
123
74
            flags["update"] = True
124
 
        elif o in ("-v", "--verbose"):
125
 
            flags["verbose"] = True
126
75
        elif o in ("--yesterday"):
127
76
            flags["yesterday"] = True
128
77
        else:
129
78
            assert False, _("unhandled option")
130
79
 
131
 
    if program_name == 'add-5-a-day':
132
 
        commands.add("add")
133
80
    if program_name == 'update-signatures':
134
81
        flags["update"] = True
135
82
 
136
 
    if flags["local"] and flags["force"]:
137
 
        print _("E: The options --force (or -f) and --local exclude each other.")
138
 
        sys.exit(COMMAND_LINE_SYNTAX_ERROR)
139
 
 
140
83
    if len(commands) == 1 and len(args) == 0:
141
84
        print _("E: You have to specify at least one argument.")
142
85
        sys.exit(COMMAND_LINE_SYNTAX_ERROR)
143
86
 
144
 
    if len(commands) > 1:
145
 
        print _("E: You must not specify more than one of those tags: --add,"
146
 
                " --add-tag, --add-team, --remove-tag, --remove-team")
147
 
        return COMMAND_LINE_SYNTAX_ERROR
148
 
 
149
 
    # data belongs to --add, --add-tag, --add-team, --remove-tag or --remove-team
150
87
    return commands, flags, args