Пример #1
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-v',
        '--version',
        action='version',
        version='Galicaster {version}'.format(version=__version__))
    parser.parse_args(args=args[1:])
    try:
        Gst.init(None)
        gc = core.Main()

        # Bug with Gtk.main() not raising a KeyboardInterrupt(SIGINT) exception
        # https://bugzilla.gnome.org/show_bug.cgi?id=622084
        # Calling GObject.MainLoop.run() instead could be an option.
        # Sadly, Gtk.main_quit() does not work with it.
        # This workaround will stay until a better solution
        # is found or the bug is fixed.

        def handler(gc):
            print("SIGINT sent. Interrupted by user!")
            gc.quit()

        GLib.unix_signal_add(GLib.PRIORITY_HIGH, 2, handler, gc)  # 2 = SIGINT
        Gtk.main()
    except KeyboardInterrupt:
        gc.emit_quit()
        print("Interrupted by user!")

    except AlreadyRunning as exc:
        #Added custom exception when galicaster it's already running
        msg = "Error starting Galicaster: {0}".format(exc)
        print(msg)

        d = context.get_dispatcher()
        d.emit("quit")
        return -2

    except Exception as exc:
        # debug
        # print traceback.format_exc()

        msg = "Error starting Galicaster: {0}".format(exc)
        print(msg)

        logger = context.get_logger()
        logger and logger.error(msg)

        d = context.get_dispatcher()
        d.emit("quit")
        return -1

    return 0
Пример #2
0
def main(args):
    def usage():
        sys.stderr.write("usage: %s\n" % args[0])
        return 1

    if len(args) != 1:
        return usage()
    try:
        gc = core.Main()
        gtk.main()
    except KeyboardInterrupt:
        gc.emit_quit()
        print "Interrupted by user!"

    return 0
Пример #3
0
def main(args):
    def usage():
        sys.stderr.write("usage: %s\n" % args[0])
        return 1

    if len(args) != 1:
        return usage()
    try:
        Gst.init(None)
        gc = core.Main()

        # Bug with Gtk.main() not raising a KeyboardInterrupt(SIGINT) exception
        # https://bugzilla.gnome.org/show_bug.cgi?id=622084
        # Calling GObject.MainLoop.run() instead could be an option.
        # Sadly, Gtk.main_quit() does not work with it.
        # This workaround will stay until a better solution
        # is found or the bug is fixed.

        def handler(gc):
            print("SIGINT sent. Interrupted by user!")
            gc.quit()

        GLib.unix_signal_add(GLib.PRIORITY_HIGH, 2, handler, gc)  # 2 = SIGINT
        Gtk.main()
    except KeyboardInterrupt:
        gc.emit_quit()
        print("Interrupted by user!")
    except Exception as exc:
        # debug
        # print traceback.format_exc()

        msg = "Error starting Galicaster: {0}".format(exc)
        print(msg)

        from galicaster.core import context
        logger = context.get_logger()
        logger and logger.error(msg)

        d = context.get_dispatcher()
        d.emit("quit")
        return -1

    return 0