Example #1
0
def init_client(options):
    username = options.username
    if not username:
        username = raw_input("username/email: ").strip()
    password = getpass.getpass("password: "******"box configuration error - {}\n".format(e))
        sys.exit(1)
    except (StatusError, AssertionError) as e:
        sys.stderr.write("{}\n".format(e))
        sys.exit(1)

    if options.auth_token:
        print_unicode(u"auth_token: {}".format(auth_token))
        sys.exit()

    if options.account_info:
        print_unicode(u"account_info: {}".format(client.get_account_info()))
        sys.exit()

    what_id = options.what_id
    if what_id:
        target = options.target
        if target == 'd':
            target_type = False
        elif target == 'f':
            target_type = True
        else:
            target_type = None
        id_, is_file = client.get_file_id(what_id, target_type)
        if not id_:
            print_unicode(u"no id found for {}(type: {})".format(
                    what_id, "unspecified" if target is None else target))
        else:
            print_unicode(u"{} {}'s id is {}".format(
                    "file" if is_file else "folder", what_id, id_))
        sys.exit()

    return client
Example #2
0
def init_client(options):
    username = options.username
    if not username:
        username = raw_input("username/email: ").strip()
    password = getpass.getpass("password: "******"box configuration error - {}\n".format(e))
        sys.exit(1)
    except (StatusError, AssertionError) as e:
        sys.stderr.write("{}\n".format(e))
        sys.exit(1)

    if options.auth_token:
        print_unicode(u"auth_token: {}".format(auth_token))
        sys.exit()

    if options.account_info:
        print_unicode(u"account_info: {}".format(client.get_account_info()))
        sys.exit()

    what_id = options.what_id
    if what_id:
        target = options.target
        if target == 'd':
            target_type = False
        elif target == 'f':
            target_type = True
        else:
            target_type = None
        id_, is_file = client.get_file_id(what_id, target_type)
        if not id_:
            print_unicode(u"no id found for {}(type: {})".format(
                what_id, "unspecified" if target is None else target))
        else:
            print_unicode(u"{} {}'s id is {}".format(
                "file" if is_file else "folder", what_id, id_))
        sys.exit()

    return client
Example #3
0
def init_client(options):
    login = options.login
    user_account = options.user_account
    password = None
    if not login and not user_account:
        sys.stderr.write(
            "You must specify either login(email) or account name\n")
        sys.exit(1)

    if login:
        username = user_of_email(login)
        if not username:
            sys.stderr.write("Login should be a valid email address\n")
            sys.exit(1)

        password = getpass.getpass("password: "******"Password cannot be empty\n")
            sys.exit(1)

        if not user_account:
            user_account = username

    try:
        client = BoxApi()
        access_token, refresh_token, token_time = client.get_auth_token(
            user_account, login, password)
        if login:
            sys.exit()
    except ConfigError as e:
        sys.stderr.write("box configuration error - {}\n".format(e))
        sys.exit(1)
    except (StatusError, AssertionError) as e:
        sys.stderr.write("{}\n".format(e))
        sys.exit(1)

    if options.auth_token:
        print_unicode(
            u"access token:  {}\nrefresh token: {}\ntoken time: {}".format(
                access_token, refresh_token, token_time))
        sys.exit()

    if options.account_info:
        print_unicode(u"account_info: {}".format(client.get_account_info()))
        sys.exit()

    what_id = options.what_id
    if what_id:
        target = options.target
        if target == 'd':
            target_type = False
        elif target == 'f':
            target_type = True
        else:
            target_type = None
        id_, is_file = client.get_file_id(what_id, target_type)
        if not id_:
            print_unicode(u"no id found for {}(type: {})".format(
                what_id, "unspecified" if target is None else target))
        else:
            print_unicode(u"{} {}'s id is {}".format(
                "file" if is_file else "folder", what_id, id_))
        sys.exit()

    return client
Example #4
0
def init_client(options):
    login = options.login
    user_account = options.user_account
    password = None
    if not login and not user_account:
        sys.stderr.write(
            "You must specify either login(email) or account name\n")
        sys.exit(1)

    if login:
        username = user_of_email(login)
        if not username:
            sys.stderr.write("Login should be a valid email address\n")
            sys.exit(1)

        password = getpass.getpass("password: "******"Password cannot be empty\n")
            sys.exit(1)

        if not user_account:
            user_account = username

    try:
        client = BoxApi()
        access_token, refresh_token, token_time = client.get_auth_token(
            user_account, login, password)
        if login:
            sys.exit()
    except ConfigError as e:
        sys.stderr.write("box configuration error - {}\n".format(e))
        sys.exit(1)
    except (StatusError, AssertionError) as e:
        sys.stderr.write("{}\n".format(e))
        sys.exit(1)

    if options.auth_token:
        print_unicode(
            u"access token:  {}\nrefresh token: {}\ntoken time: {}".format(
                access_token, refresh_token, token_time))
        sys.exit()

    if options.account_info:
        print_unicode(u"account_info: {}".format(client.get_account_info()))
        sys.exit()

    what_id = options.what_id
    if what_id:
        target = options.target
        if target == 'd':
            target_type = False
        elif target == 'f':
            target_type = True
        else:
            target_type = None
        id_, is_file = client.get_file_id(what_id, target_type)
        if not id_:
            print_unicode(u"no id found for {}(type: {})".format(
                what_id, "unspecified" if target is None else target))
        else:
            print_unicode(u"{} {}'s id is {}".format(
                "file" if is_file else "folder", what_id, id_))
        sys.exit()

    return client