Example #1
0
def main(argv=sys.argv):
    parser = argparse.ArgumentParser(
        description=DOC, formatter_class=RawTextHelpFormatter)
    parser.add_argument('action',
                        help='Action to perform.')
    parser.add_argument('-p', '--path',
                        help='Path where Cozy files will be mounted')
    parser.add_argument('-u', '--url',
                        help='URL of remote Cozy to sync')
    parser.add_argument('-n', '--name',
                        help='Name of the device on which action occurs')

    args = parser.parse_args()

    if args.action is None:
        parser.print_help()
        print('\nYou must specify an action argument\n')
        sys.exit(2)

    elif args.action == 'configure':
        actions.configure_new_device(args.name, args.url, args.path)

    elif args.action == 'remove_configuration':
        actions.remove_device(args.name)

    elif args.action == 'sync':
        actions.sync(args.name)

    elif args.action == 'mount':
        actions.mount_folder(args.name)

    elif args.action == 'unmount':
        actions.unmount_folder(args.name, args.path)

    elif args.action == 'reset':
        actions.reset()

    elif args.action == 'display_config':
        actions.display_config()

    elif args.action == 'kill_running_replications':
        actions.kill_running_replications()

    else:
        parser.print_help()
        print('\nYou must specify an action argument\n')
Example #2
0
    elif args.action == 'mount':
        actions.mount_folder(args.name)

    elif args.action == 'unmount':
        actions.unmount_folder(args.name, args.path)

    elif args.action == 'reset':
        password = retrieve_user_password()
        actions.reset(password)

    elif args.action == 'display_config':
        actions.display_config()

    elif args.action == 'kill_running_replications':
        actions.kill_running_replications()

    else:
        parser.print_help()
        print('\nYou must specify an action argument\n')

def retrieve_user_password():
    '''
    Ask for the user password
    '''
    return getpass.getpass('Type your Cozy password (won\'t be stored):\n')


if __name__ == "__main__":
    main()