Пример #1
0
def main():
    """
    Launch ``turses``.
    """
    set_title(__name__)
    set_encoding('utf8')

    args = parse_arguments()

    # check if stdout has to be restored after program exit
    if any([args.debug,
            args.offline,
            getattr(args, 'help', False),
            getattr(args, 'version', False)]):
        # we are going to print information to stdout
        save_and_restore_stdout = False
    else:
        save_and_restore_stdout = True

    if save_and_restore_stdout:
        save_stdout()

    # load configuration
    configuration = Configuration(args)
    configuration.load()

    # start logger
    logging.basicConfig(filename=LOG_FILE,
                        level=configuration.logging_level)

    # create view
    curses_interface = CursesInterface(configuration)

    # select API backend
    if args.offline:
        api_backend = MockApi
    else:
        api_backend = TweepyApi

    # create controller
    turses = Turses(configuration=configuration,
                    ui=curses_interface,
                    api_backend=api_backend)
    try:
        turses.start()
    except KeyboardInterrupt:
        pass
    except:
        # open the debugger
        if args.debug or args.offline:
            import pdb
            pdb.post_mortem()
    finally:
        if save_and_restore_stdout:
            restore_stdout()

        restore_title()

        exit(0)
Пример #2
0
def main():
    """
    Launch ``turses``.
    """
    set_title(__name__)
    set_encoding('utf8')

    args = parse_arguments()

    # stdout
    if any([args.debug,
            args.offline,
            getattr(args, 'help', False),
            getattr(args, 'version', False)]):
        # we are going to print information to stdout
        save_and_restore_stdout = False
    else:
        save_and_restore_stdout = True

    if save_and_restore_stdout:
        save_stdout()

    # configuration
    configuration = Configuration(args)
    configuration.load()

    # view
    curses_interface = CursesInterface(configuration)

    # API
    if args.offline:
        api_backend = MockApi
    else:
        api_backend = TweepyApi

    # controller
    turses = Turses(configuration=configuration,
                    ui=curses_interface,
                    api_backend=api_backend)
    try:
        turses.start()
    except KeyboardInterrupt:
        pass
    except:
        if args.debug or args.offline:
            import pdb
            pdb.post_mortem()
    finally:
        if save_and_restore_stdout:
            restore_stdout()

        restore_title()

        exit(0)