示例#1
0
def main_menu(settings):
    """
    Main menu function, calss the settings.show_
    main_screen function and handles user response
    """
    to_do = settings.show_main_screen(settings.settings_file_exists())

    # Act according to the users input to the main menu function
    if to_do == u"quit":
        sys.exit()
    elif to_do == u"set_settings":
        settings.set_settings()
        main_menu(settings)
    elif to_do == u"show_settings":
        settings.show(quit=False)
        main_menu(settings)
    elif to_do == u"show_help":
        usage.help()
    else:
        do_sync(settings, "")
示例#2
0
def run_canvas_sync():
    """ Main CanvasSync function, reads arguments from the command line and initializes the program """

    # Get command line arguments (C-style)
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], u"hsiSp:",
            [u"help", u"setup", u"info", u"sync", u"password"])
    except getopt.GetoptError as err:
        # print help information and exit
        print(err)
        usage.help()

    # Parse the command line arguments and act accordingly
    setup = False
    show_info = False
    manual_sync = False
    password = ""

    if len(opts) != 0:
        for o, a in opts:
            if o in (u"-h", u"--help"):
                # Show help
                usage.help()

            elif o in (u"-s", u"--setup"):
                # Force re-setup
                setup = True

            elif o in (u"-i", u"--info"):
                # Show current settings
                show_info = True

            elif o in (u"-S", u"--sync"):
                # Force sync
                manual_sync = True

            elif o in (u"-p", u"--password"):
                # Specify decyption password
                print(
                    "Warning: entering password via command line can be dangerous"
                )
                password = a.rstrip()

            else:
                # Unknown option
                assert False, u"Unknown option specified, please refer to the --help section."

    # Initialize Settings object. This object will parse the settings file or generate a new one if one does not exist.
    settings = Settings()

    # If the settings file does not exist or the user promoted to re-setup, start prompting user for settings info.
    if setup:
        settings.set_settings()

    # If -i or --info was specified, show the current settings and EXIT
    if show_info:
        settings.show(quit=True)

    # If -S or --sync was specified, sync and exit
    if manual_sync:
        do_sync(settings, password)
        sys.exit()

    # If here, CanvasSync was launched without parameters, show main screen
    main_menu(settings)