Example #1
0
def main(argv):
    """
    Gets the argument flags and launches the server or command line interface.
    """
    print('Running Python version ' + platform.python_version())

    # This variable is used to select between the different modes, defaults both
    start = 'both'

    # Checking command line arguments in order of priority
    print('\n======= Parsing Command line arguments =======')
    if len(argv) > 0:
        arguments = parsing_args(argv)
        if 'both' in arguments:
            print('Command line and server selected')
            start = 'both'
        elif 'cli' in arguments:
            print('Command line selected')
            start = 'cli'
        elif 'server' in arguments:
            print('Server selected')
            start = 'server'
    else:
        print('No flags defaults to the command line interface.')

    # Loading the settings
    print('\n=========== Launching LightUpPi Alarm ==========')
    if start == 'server':
        # For the server we only set the offset alarm, as it is meant to be run
        # headless and nothing else will be connected to ring/alert
        alarm_mgr = AlarmManager.AlarmManager(
            offset_alert_callback=alarm_offset_alert)
        Server.run(alarm_mgr_arg=alarm_mgr)
    else:
        # The command line interface running on its own thread is common to
        # the 'cli' and 'both' options.
        cli_thread = CliThread()
        alarm_mgr = AlarmManager.AlarmManager(
            alert_callback=cli_thread.alarm_alert,
            offset_alert_callback=alarm_offset_alert)
        cli_thread.attach_alarm_mgr(alarm_mgr)
        cli_thread.start()
        # Infinite loop can be the Flask server, or just a loop
        try:
            if start == 'both':
                Server.run(
                    alarm_mgr_arg=alarm_mgr,
                    silent=True,
                    callback_arg=cli_thread.callback_event)
            else:
                while cli_thread.isAlive():
                    sleep(0.2)
        except (KeyboardInterrupt, SystemExit):
            # Allow the clean exit from the CLI interface to execute
            if cli_thread.isAlive():
                sleep(1)
Example #2
0
def main(argv=None, alarm_mgr=None):
    # Checking command line arguments
    if (argv is not None) and (len(argv) > 0):
        pass

    Server.main(alarm_mgr)