Dashboard > Pulse v2.1 > ... > Remote API Examples > Python Example - Creating Users
  Pulse v2.1 Log In | Sign Up   View a printable version of the current page.  
  Python Example - Creating Users
Added by Jason Sankey, last edited by Jason Sankey on Mar 19, 2009
Labels: 
(None)

Pulse Manual Index

Overview

This example is extracted from a real script used to automatically create new pulse™ accounts with a default setup for new developers. It illustrates how the remote API can be used to make a pulse™ admin's life easier by automating a standard task.

Attribution

This example was kindly donated by Simon Middleton.

Code

import sys
import xmlrpclib

pulse_server = 'http://pulse:8080/xmlrpc'
loginuser = 'admin'
loginpassword = 'admin'
contact_name = 'work email'

def create_user(id, name, email_addr):

    server = xmlrpclib.ServerProxy(pulse_server)
    api = server.RemoteApi

    token = api.login(loginuser, loginpassword)

    try:
        user = api.createDefaultConfig(token, 'zutubi.userConfig')
        user['login'] = id
        user['name'] = name

        prefs = user['preferences']

        # Set some view defaults that we like
        prefs['browseView']['hierarchyShown'] = False
        prefs['browseView']['groupsShown'] = False
        prefs['browseView']['columns'].append('version')

        prefs['dashboard']['hierarchyShown'] = False
        prefs['dashboard']['columns'].append('version')

        # Create work email
        email = api.createDefaultConfig(token, 'zutubi.emailContactConfig')
        email['name'] = contact_name
        email['address'] = email_addr

        prefs['contacts'][contact_name] = email

        print user

        # Create the user
        api.insertConfig(token, 'users', user)

        # Create subscription and add it
        condition = api.createDefaultConfig(token, 'zutubi.customConditionConfig')
        condition['customCondition'] = 'not success and changed.by.me'
   
        sub = api.createDefaultConfig(token, 'zutubi.projectSubscriptionConfig')
        sub['name'] = 'My failed builds'
        sub['contact'] = 'users/%s/preferences/contacts/%s' % (id, contact_name)
        sub['condition'] = condition
        sub['template'] = 'plain-text-email'
        sub['projects'] = []
        api.insertConfig(token, 'users/%s/preferences/subscriptions' % id, sub)

        # Add to group developers
        developers = api.getConfig(token, 'groups/developers')
        developers['members'].append('users/%s' % id)
        api.saveConfig(token, 'groups/developers', developers, False)

        # Set password to empty to activate user
        password = api.createDefaultConfig(token, 'zutubi.setPasswordConfig')
        password['password'] = password['confirmPassword'] = ''
        api.doConfigActionWithArgument(token, 'users/%s' % id, 'setPassword', password)

    finally:
        api.logout(token)

if __name__ == '__main__':
    create_user(sys.argv[1], sys.argv[2], sys.argv[3])

Zutubi wiki is Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators