#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Copyright 2009, Florent Thiery, under the terms of LGPL
"""
import os
os.environ['GST_DEBUG_DUMP_DOT_DIR'] = '/tmp/'

import logging
logger = logging.getLogger('gst-gengui')

import gobject
gobject.threads_init()

from gstmanager import PipelineManager

if __name__ == '__main__':

    import logging, sys

    logging.basicConfig(
        level=getattr(logging, "DEBUG"),
        format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
        stream=sys.stderr
    )

    def parse_argv(args):
        cmd = ""
        for n in range(1, len(args)):
            cmd+="%s " %args[n]
        logger.info("gst-launch pipeline is: %s" %cmd)
        return cmd
   
    from sys import argv
    if len(argv) <= 1:
        logger.info("No gst-launch syntax detected, using config file")
        import gstgengui.config
        string = gstgengui.config.pipeline_desc
    else:
        string = parse_argv (argv)
    pipeline_launcher = PipelineManager(string)

    from gtk_controller import GtkGstController
    controller = GtkGstController(pipeline_launcher)

    controller.main()

@@ -262,74 +262,444 @@
 ()%0A%0A
-from gstmanager import PipelineManager%0A%0Aif __name__ == '__main__':
+%0Aif __name__ == '__main__':%0A%0A    from optparse import OptionParser%0A    parser = OptionParser(usage=%22%25prog %5Boptions%5D %5Bpipeline description%5D%22)%0A    parser.add_option(%22-v%22, %22--verbose%22, action=%22store_true%22, dest=%22verbose%22, default=False, help=%22don't print status messages to stdout%22)%0A%0A    (options, args) = parser.parse_args()%0A    print options, args%0A%0A    if options.verbose:%0A        verbosity = 'DEBUG'%0A    else:%0A        verbosity = 'INFO'
 %0A%0A  
@@ -781,15 +781,17 @@
 ng, 
-%22DEBUG%22
+verbosity
 ),%0A 
@@ -909,17 +909,17 @@
 arse_arg
-v
+s
 (args):%0A
@@ -926,19 +926,20 @@
         
-cmd
+desc
  = %22%22%0A  
@@ -952,32 +952,19 @@
 for 
-n in range(1, len(
+arg in 
 args
-))
 :%0A  
@@ -977,27 +977,23 @@
     
-cmd+=%22%25s %22 %25
+desc += %22 %22+
 arg
-s%5Bn%5D
 %0A   
@@ -1004,20 +1004,21 @@
  logger.
-info
+debug
 (%22gst-la
@@ -1040,19 +1040,20 @@
 s: %25s%22 %25
-cmd
+desc
 )%0A      
@@ -1065,40 +1065,15 @@
 urn 
-cmd%0A   %0A    from sys import argv
+desc %0A 
 %0A   
@@ -1087,15 +1087,15 @@
 (arg
-v) %3C= 1
+s) == 0
 :%0A  
@@ -1111,189 +1111,222 @@
 ger.
-info(%22No gst-launch syntax detected, using config file%22)%0A        import gstgengui.config%0A        string = gstgengui.config.pipeline_desc%0A    else:%0A        string = parse_argv (argv)
+error(%22Empty pipeline unauthorized, quitting%22)%0A        sys.exit(1)%0A    else:%0A        string = parse_args(args)%0A%0A    # We import it later on otherwise it messes up optparse%0A    from gstmanager import PipelineManager
 %0A   

add -v option using optparse