Exemple #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')
Exemple #2
0
def command(cmd):
    """Send a command to the server.

    .. Keyword Arguments:
    :param: cmd: String with the command.

    .. Types:
    :type: cmd: A string.

    """
    resp = None
    args = {}

    cmd_splitted = cmd.split()
    action = cmd_splitted[0]
    cmd_rest = cmd_splitted[1:]


    print_key = None


################ navigatement begin ############
    if action == "w":
        resp = navigate.up()
    elif action == "e":
        resp = navigate.right_up()
    elif action == "a":
        resp = navigate.left()
    elif action == "s":
        resp = navigate.down()
    elif action == "d":
        resp = navigate.right()
    elif action == "q":
        resp = navigate.left_up()
    elif action == "z":
        resp = navigate.left_down()
    elif action == "c":
        resp = navigate.right_down()
################ navigatement end ############
    elif action == "p" or action == "pickup":
        resp = actions.pickup()
    elif action == "l" or action == "drop":
        if len(cmd_rest) < 1:
            print("Missing thing to drop")
        else:
            thingid = cmd_rest[0]
            resp = actions.drop(thingid)
    elif action == "reset":
        resp = actions.reset()
    elif action == "scan":
        resp = scan.scan()
        if len(cmd_rest) >= 1:
            print_key = cmd_rest[0]
    else:
        print("Unknown command")

    if resp is None:
        print("Error with command.")
        return 1

    if print_key:
        resp = resp['payload']
        if print_key in resp:
            pprint(resp[print_key])
        else:
            print("Selected key %s does not exists" % print_key)
    else:
        pprint(resp)
    return 0
    elif args.action == 'sync':
        try:
            actions.sync_daemon(args.name)
        except Exception, e:
            print e

    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
    '''