annotate argparse_modified.py @ 275:09a5bde70919 default tip master

minor fix in Participant Signed-off-by: Changaco <changaco ατ changaco δοτ net>
author Changaco <changaco ατ changaco δοτ net>
date Wed, 05 May 2010 23:36:13 +0200
parents 99f3dee1fad7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
1 #!/usr/bin/env python
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
3
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
4 # This program is free software: you can redistribute it and/or modify
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
6 # the Free Software Foundation, either version 3 of the License, or
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
7 # (at your option) any later version.
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
8 #
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
12 # GNU General Public License for more details.
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
13 #
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
16
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
17 from argparse import ArgumentParser as OriginalArgumentParser
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
18
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
19 class ArgumentParser(OriginalArgumentParser):
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
20
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 104
diff changeset
21 class ParseException(Exception): pass
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 104
diff changeset
22
104
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
23 def _print_message(self, message, file=None):
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
24 if not hasattr(self, 'ret'):
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
25 self.ret = ''
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
26 self.ret += message
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
27
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
28 def exit(self, status=0, message=''):
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
29 if hasattr(self, 'ret') and isinstance(self.ret, basestring):
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 104
diff changeset
30 raise self.ParseException(status, self.ret+message)
104
60cc60f0058d Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff changeset
31 else:
124
99f3dee1fad7 code cleaning
Charly COSTE <changaco@changaco.net>
parents: 104
diff changeset
32 raise self.ParseException(status, message)