Fix handling of filename command line argument

This commit is contained in:
René Stadler 2007-11-28 10:27:45 +02:00 committed by Stefan Sauer
parent 480392b881
commit b948b7b6e5
3 changed files with 26 additions and 11 deletions

View file

@ -301,6 +301,9 @@ class OptionParser (object):
self.options = options
self.__remaining_args = []
self.__entries.append ((gobject.OPTION_REMAINING, "\0", 0, "", "",))
def add_option (self, long_name, short_name = None, description = None,
arg_name = None, arg_parser = None, hidden = False):
@ -326,6 +329,10 @@ class OptionParser (object):
def __handle_option (self, option, arg, group):
if option == gobject.OPTION_REMAINING:
self.__remaining_args.append (arg)
return
for entry in self.__entries:
long_name, short_name = entry[:2]
arg_name = entry[-1]
@ -340,6 +347,7 @@ class OptionParser (object):
else:
value = arg
self.options[attr] = value
break
def parse (self, argv):
@ -353,13 +361,13 @@ class OptionParser (object):
except gobject.GError, exc:
raise OptionError (exc.message)
self.handle_parse_complete ()
self.handle_parse_complete (self.__remaining_args)
def get_parameter_string (self):
raise NotImplementedError ("derived classes must override this method")
def handle_parse_complete (self):
def handle_parse_complete (self, remaining_args):
pass
@ -474,6 +482,6 @@ def main (option_parser = None, gettext_domain = None, paths = None):
_init_logging (log_level)
try:
options["main"] ()
options["main"] (options)
finally:
logging.shutdown ()

View file

@ -1524,18 +1524,22 @@ class TestParsingPerformance (object):
print "time spent in user mode: %.2f s" % (rusage.ru_utime,)
print "time spent in system mode: %.2f s" % (rusage.ru_stime,)
def main ():
def main (options):
if len (sys.argv) > 1 and sys.argv[1] == "benchmark":
test = TestParsingPerformance (sys.argv[2])
args = options["args"]
if len (args) > 1 and args[0] == "benchmark":
test = TestParsingPerformance (args[1])
test.start ()
return
app = App ()
# TODO: Once we support more than one window, open one window for each
# supplied filename.
window = app.windows[0]
if len (sys.argv) > 1:
window.set_log_file (sys.argv[-1])
if len (args) > 0:
window.set_log_file (args[0])
app.run ()

View file

@ -27,7 +27,7 @@ Common = GstDebugViewer.Common
GETTEXT_DOMAIN = "gst-debug-viewer"
def main_version ():
def main_version (options):
from GstDebugViewer import version
@ -44,14 +44,15 @@ class OptionParser (Common.Main.LogOptionParser):
Common.Main.LogOptionParser.__init__ (self, options)
options["main"] = None
options["args"] = []
self.add_option ("version", None, _("Display version and exit"))
def get_parameter_string (self):
return _("- Display and analyze debug log files")
return _("[FILENAME] - Display and analyze debug log files")
def handle_parse_complete (self):
def handle_parse_complete (self, remaining_args):
try:
version = self.options["version"]
@ -65,6 +66,8 @@ class OptionParser (Common.Main.LogOptionParser):
import GUI
self.options["main"] = GUI.main
self.options["args"][:] = remaining_args
def main ():
options = {}