From b948b7b6e5a6dca4f0a1a2f80a5cfe4417d0073f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Stadler?= Date: Wed, 28 Nov 2007 10:27:45 +0200 Subject: [PATCH] Fix handling of filename command line argument --- debug-viewer/GstDebugViewer/Common/Main.py | 14 +++++++++++--- debug-viewer/GstDebugViewer/GUI.py | 14 +++++++++----- debug-viewer/GstDebugViewer/Main.py | 9 ++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/debug-viewer/GstDebugViewer/Common/Main.py b/debug-viewer/GstDebugViewer/Common/Main.py index 414a0f75e1..cf6ab56cd1 100644 --- a/debug-viewer/GstDebugViewer/Common/Main.py +++ b/debug-viewer/GstDebugViewer/Common/Main.py @@ -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 () diff --git a/debug-viewer/GstDebugViewer/GUI.py b/debug-viewer/GstDebugViewer/GUI.py index 2763f3c1dc..5fc815f67e 100755 --- a/debug-viewer/GstDebugViewer/GUI.py +++ b/debug-viewer/GstDebugViewer/GUI.py @@ -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 () diff --git a/debug-viewer/GstDebugViewer/Main.py b/debug-viewer/GstDebugViewer/Main.py index 7c296d194a..bf0f3e20d5 100644 --- a/debug-viewer/GstDebugViewer/Main.py +++ b/debug-viewer/GstDebugViewer/Main.py @@ -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 = {}