view @ 4:b69804a685e2 draft

planemo upload for repository commit 70fbb41d4c6b0a08a7bed4849a5ae7c865e1ab1e
author gga
date Mon, 12 Mar 2018 06:32:56 -0400
parents 1f2e360f7554
children a3000d01c04c
line wrap: on
line source

#!/usr/bin/env python
from __future__ import print_function

import argparse
import random
import time

from six.moves.builtins import str

from webapollo import WAAuth, WebApolloInstance

def pwgen(length):
    chars = list('qwrtpsdfghjklzxcvbnm')
    return ''.join(random.choice(chars) for _ in range(length))

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Sample script to add an account via web services')

    parser.add_argument('email', help='User Email')
    parser.add_argument('--first', help='First Name', default='Jane')
    parser.add_argument('--last', help='Last Name', default='Aggie')
    args = parser.parse_args()

    wa = WebApolloInstance(args.apollo, args.username, args.password)

    password = pwgen(12)
    users = wa.users.loadUsers()
    user = [u for u in users
            if u.username ==]

    if len(user) == 1:
        # Update name, regen password if the user ran it again
        userObj = user[0]
        returnData = wa.users.updateUser(userObj,, args.first, args.last, password)
        print('Updated User\nUsername: %s\nPassword: %s' % (, password))
        returnData = wa.users.createUser(, args.first, args.last, password, role='user')
        print('Created User\nUsername: %s\nPassword: %s' % (, password))

    print("Return data: " + str(returnData))