Mercurial > xib
comparison argparse_modified.py @ 104:60cc60f0058d
Oops, forgot to add this file in the new command system commit
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sat, 21 Nov 2009 16:54:22 +0100 |
parents | |
children | 99f3dee1fad7 |
comparison
equal
deleted
inserted
replaced
103:23416c27b592 | 104:60cc60f0058d |
---|---|
1 #!/usr/bin/env python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # This program is free software: you can redistribute it and/or modify | |
5 # it under the terms of the GNU General Public License as published by | |
6 # the Free Software Foundation, either version 3 of the License, or | |
7 # (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
17 from argparse import ArgumentParser as OriginalArgumentParser | |
18 | |
19 class ParseException(Exception): pass | |
20 | |
21 class ArgumentParser(OriginalArgumentParser): | |
22 | |
23 def _print_message(self, message, file=None): | |
24 if not hasattr(self, 'ret'): | |
25 self.ret = '' | |
26 self.ret += message | |
27 | |
28 def exit(self, status=0, message=''): | |
29 if hasattr(self, 'ret') and isinstance(self.ret, basestring): | |
30 raise ParseException(status, self.ret+message) | |
31 else: | |
32 raise ParseException(status, message) |