Package pysql :: Module pysqloptionparser
[hide private]
[frames] | no frames]

Source Code for Module pysql.pysqloptionparser

 1  # -*- coding: utf-8 -*- 
 2  """ 
 3  An OptionParser which accepts a single string as input and raise an exception 
 4  instead of calling sys.exit() in case of error 
 5   
 6  Kindly borrowed from Yokadi Option parser (http://github.com/agateau/yokadi/) 
 7  @author: Aurélien Gâteau <aurelien.gateau@free.fr> 
 8  @author: Sébastien Renard <Sebastien.Renard@sigitalfox.org> 
 9   
10  @license: GNU GPL V3 
11  """ 
12  from optparse import OptionParser 
13  import sys 
14  from pysqlexception import PysqlException, PysqlOptionParserNormalExitException 
15   
16   
17 -class PysqlOptionParser(OptionParser):
18 - def __init__(self):
19 OptionParser.__init__(self, add_help_option=False)
20
21 - def parse_args(self, line):
22 argv = line.split(u" ") 23 # Splitting an empty line gives us [""], not an empty array 24 if argv == [u""]: 25 argv = [] 26 27 # Remove extra spaces 28 argv = [i for i in argv if i is not u""] 29 30 return OptionParser.parse_args(self, argv)
31
32 - def exit(self, status=0, msg=None):
33 if msg: 34 sys.stderr.write(msg) 35 if status == 0: 36 raise PysqlOptionParserNormalExitException() 37 else: 38 raise PysqlException(msg)
39
40 - def error(self, msg):
41 self.print_usage() 42 raise PysqlException(msg)
43