ckan/lib/cli.py
def user_add(args):
    '''Add new user if we use paster sysadmin add
    or paster user add
    '''
    if len(args) < 1:
        error('Error: you need to specify the user name.')
    username = args[0]

    # parse args into data_dict
    data_dict = {'name': username}
    for arg in args[1:]:
        try:
            field, value = arg.split('=', 1)
            data_dict[field] = value
        except ValueError:
            raise ValueError(
                'Could not parse arg: %r (expected "<option>=<value>)"' % arg
            )

    # Required
    while '@' not in data_dict.get('email', ''):
        print('Error: Invalid email address')
        data_dict['email'] = input('Email address: ').strip()

    if 'password' not in data_dict:
        data_dict['password'] = UserCmd.password_prompt()

    # Optional
    if 'fullname' in data_dict:
        data_dict['fullname'] = data_dict['fullname'].decode(
            sys.getfilesystemencoding()
        )

    print('Creating user: %r' % username)

    try:
        import ckan.logic as logic
        import ckan.model as model
        site_user = logic.get_action('get_site_user')({
            'model': model,
            'ignore_auth': True},
            {}
        )
        context = {
            'model': model,
            'session': model.Session,
            'ignore_auth': True,
            'user': site_user['name'],
        }
        user_dict = logic.get_action('user_create')(context, data_dict)
        pprint(user_dict)
    except logic.ValidationError as e:
        error(traceback.format_exc())
Add new user if we use paster sysadmin add
    or paster user add
    
Add new user if we use paster sysadmin add
or paster user add
Add new user if we use paster sysadmin add or paster user add
def user_add(args):
    if len(args) < 1:
        error('Error: you need to specify the user name.')
    username = args[0]
    data_dict = {'name': username}
    for arg in args[1:]:
        try:
            field, value = arg.split('=', 1)
            data_dict[field] = value
        except ValueError:
            raise ValueError(
                'Could not parse arg: %r (expected "<option>=<value>)"' % arg
            )
    while '@' not in data_dict.get('email', ''):
        print('Error: Invalid email address')
        data_dict['email'] = input('Email address: ').strip()
    if 'password' not in data_dict:
        data_dict['password'] = UserCmd.password_prompt()
    if 'fullname' in data_dict:
        data_dict['fullname'] = data_dict['fullname'].decode(
            sys.getfilesystemencoding()
        )
    print('Creating user: %r' % username)
    try:
        import ckan.logic as logic
        import ckan.model as model
        site_user = logic.get_action('get_site_user')({
            'model': model,
            'ignore_auth': True},
            {}
        )
        context = {
            'model': model,
            'session': model.Session,
            'ignore_auth': True,
            'user': site_user['name'],
        }
        user_dict = logic.get_action('user_create')(context, data_dict)
        pprint(user_dict)
    except logic.ValidationError as e:
        error(traceback.format_exc())
def user_add ( args ) : if len ( args ) < 1 : error ( 'Error: you need to specify the user name.' ) username = args [ 0 ] data_dict = { 'name' : username } for arg in args [ 1 : ] : try : field , value = arg . split ( '=' , 1 ) data_dict [ field ] = value except ValueError : raise ValueError ( 'Could not parse arg: %r (expected "<option>=<value>)"' % arg ) while '@' not in data_dict . get ( 'email' , '' ) : print ( 'Error: Invalid email address' ) data_dict [ 'email' ] = input ( 'Email address: ' ) . strip ( ) if 'password' not in data_dict : data_dict [ 'password' ] = UserCmd . password_prompt ( ) if 'fullname' in data_dict : data_dict [ 'fullname' ] = data_dict [ 'fullname' ] . decode ( sys . getfilesystemencoding ( ) ) print ( 'Creating user: %r' % username ) try : import ckan . logic as logic import ckan . model as model site_user = logic . get_action ( 'get_site_user' ) ( { 'model' : model , 'ignore_auth' : True } , { } ) context = { 'model' : model , 'session' : model . Session , 'ignore_auth' : True , 'user' : site_user [ 'name' ] , } user_dict = logic . get_action ( 'user_create' ) ( context , data_dict ) pprint ( user_dict ) except logic . ValidationError as e : error ( traceback . format_exc ( ) )
Add new user if we use paster sysadmin add
or paster user add
Add new user if we use paster sysadmin add or paster user add
'''Add new user if we use paster sysadmin add
    or paster user add
    ''' # parse args into data_dict # Required # Optional
args