Trees | Indices | Help |
---|
|
1 # -*- Mode: Python; test-case-name: flumotion.test.test_options -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 # 4 # Flumotion - a streaming media server 5 # Copyright (C) 2007,2008 Fluendo, S.L. (www.fluendo.com). 6 # All rights reserved. 7 8 # This file may be distributed and/or modified under the terms of 9 # the GNU General Public License version 2 as published by 10 # the Free Software Foundation. 11 # This file is distributed without any warranty; without even the implied 12 # warranty of merchantability or fitness for a particular purpose. 13 # See "LICENSE.GPL" in the source distribution for more information. 14 15 # Licensees having purchased or holding a valid Flumotion Advanced 16 # Streaming Server license may use this file in accordance with the 17 # Flumotion Advanced Streaming Server Commercial License Agreement. 18 # See "LICENSE.Flumotion" in the source distribution for more information. 19 20 # Headers in this file shall remain intact. 21 22 """command-line parsing and options 23 """ 24 25 from flumotion.common import common 26 from flumotion.common import log 27 28 # Disable optionparser, it needs more upstream 29 # changes to work properly 30 from flumotion.common import boot 31 32 __version__ = "$Rev$" 33 34 boot.USE_GOPTION_PARSER = False 35 3638 from optparse import OptionParser as BaseOP 39 40 class OptionParser(BaseOP): 41 42 def __init__(self, usage, description, domain): 43 self.domain = domain 44 BaseOP.__init__(self, usage=usage, description=description)45 return OptionParser 46 4749 from optparse import OptionGroup as BaseOG 50 51 class OptionGroup(BaseOG): 52 53 def __init__(self, parser, title, description=None, **kwargs): 54 BaseOG.__init__(self, parser, title, description, 55 **kwargs)56 return OptionGroup 57 5860 from gobject.option import OptionParser as BaseOP 61 62 class OptionParser(BaseOP): 63 64 def __init__(self, usage, description, domain): 65 self.domain = domain 66 BaseOP.__init__(self, usage=usage, description=description) 67 if use_gst: 68 try: 69 import pygst 70 pygst.require('0.10') 71 import gstoption 72 self.add_option_group(gstoption.get_group()) 73 except ImportError: 74 pass75 return OptionParser 76 7779 from goption.option import OptionGroup as BaseOG 80 81 class OptionGroup(BaseOG): 82 83 def __init__(self, parser, title, description=None, **kwargs): 84 if not description: 85 description = title.capitalize() + " options" 86 BaseOG.__init__(self, title, description, 87 option_list=[], **kwargs)88 return OptionGroup 89 9092 """I have two responsibilities: 93 - provide a generic interface to OptionParser on top of the optparse 94 implementation and the GOption variant. 95 - abstract the common command line arguments used by all flumotion 96 binaries 97 """ 98 from flumotion.common.boot import USE_GOPTION_PARSER, USE_GST 99 if USE_GOPTION_PARSER: 100 OptionParser = GOptionOptionParserClass(USE_GST) 101 else: 102 OptionParser = OptparseOptionParserClass() 103 104 class FOptionParser(OptionParser): 105 106 def __init__(self, usage, description, domain): 107 OptionParser.__init__(self, usage, description, domain) 108 self._add_common_options()109 110 def _add_common_options(self): 111 self.add_option('-d', '--debug', 112 action="store", type="string", dest="debug", 113 help="set debug levels") 114 self.add_option('-v', '--verbose', 115 action="store_true", dest="verbose", 116 help="be verbose") 117 self.add_option('', '--version', 118 action="store_true", dest="version", 119 default=False, 120 help="show version information") 121 122 def parse_args(self, args): 123 options, args = OptionParser.parse_args(self, args) 124 125 if options.verbose: 126 log.setFluDebug("*:3") 127 128 if options.version: 129 print common.version(self.domain) 130 import sys 131 sys.exit(0) 132 133 if options.debug: 134 log.setFluDebug(options.debug) 135 136 return options, args 137 138 return FOptionParser(usage, description, domain) 139 140142 from flumotion.common.boot import USE_GOPTION_PARSER 143 if USE_GOPTION_PARSER: 144 OptionGroup = GOptionOptionGroupClass() 145 else: 146 OptionGroup = OptparseOptionGroupClass() 147 148 class FOptionGroup(OptionGroup): 149 pass150 return FOptionGroup(parser, title, description, **kwargs) 151
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu May 5 05:31:22 2011 | http://epydoc.sourceforge.net |