Changeset View
Changeset View
Standalone View
Standalone View
pykolab/wap_client/__init__.py
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | post = json.dumps( | ||||
} | } | ||||
) | ) | ||||
response = request('POST', "system.authenticate", post=post) | response = request('POST', "system.authenticate", post=post) | ||||
if not response: | if not response: | ||||
return False | return False | ||||
if response.has_key('session_token'): | if 'session_token' in response: | ||||
session_id = response['session_token'] | session_id = response['session_token'] | ||||
return True | return True | ||||
def connect(uri=None): | def connect(uri=None): | ||||
global conn, API_SSL, API_PORT, API_HOSTNAME, API_BASE | global conn, API_SSL, API_PORT, API_HOSTNAME, API_BASE | ||||
if not uri == None: | if not uri == None: | ||||
result = urlparse(uri) | result = urlparse(uri) | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | def get_group_input(): | ||||
elif len(group_types.keys()) > 0: | elif len(group_types.keys()) > 0: | ||||
print "Automatically selected the only group type available" | print "Automatically selected the only group type available" | ||||
group_type_id = group_types.keys()[0] | group_type_id = group_types.keys()[0] | ||||
else: | else: | ||||
print "No group types available" | print "No group types available" | ||||
sys.exit(1) | sys.exit(1) | ||||
if group_types.has_key(group_type_id): | if group_type_id in group_types: | ||||
group_type_info = group_types[group_type_id]['attributes'] | group_type_info = group_types[group_type_id]['attributes'] | ||||
else: | else: | ||||
print "No such group type" | print "No such group type" | ||||
sys.exit(1) | sys.exit(1) | ||||
params = { | params = { | ||||
'group_type_id': group_type_id | 'group_type_id': group_type_id | ||||
} | } | ||||
Show All 22 Lines | def get_user_input(): | ||||
elif user_types['count'] > 0: | elif user_types['count'] > 0: | ||||
print "Automatically selected the only user type available" | print "Automatically selected the only user type available" | ||||
user_type_id = user_types['list'].keys()[0] | user_type_id = user_types['list'].keys()[0] | ||||
else: | else: | ||||
print "No user types available" | print "No user types available" | ||||
sys.exit(1) | sys.exit(1) | ||||
if user_types['list'].has_key(user_type_id): | if user_type_id in user_types['list']: | ||||
user_type_info = user_types['list'][user_type_id]['attributes'] | user_type_info = user_types['list'][user_type_id]['attributes'] | ||||
else: | else: | ||||
print "No such user type" | print "No such user type" | ||||
sys.exit(1) | sys.exit(1) | ||||
params = { | params = { | ||||
'object_type': 'user', | 'object_type': 'user', | ||||
'type_id': user_type_id | 'type_id': user_type_id | ||||
} | } | ||||
must_attrs = [] | must_attrs = [] | ||||
may_attrs = [] | may_attrs = [] | ||||
for attribute in user_type_info['form_fields'].keys(): | for attribute in user_type_info['form_fields'].keys(): | ||||
if isinstance(user_type_info['form_fields'][attribute], dict): | if isinstance(user_type_info['form_fields'][attribute], dict): | ||||
if user_type_info['form_fields'][attribute].has_key('optional') and user_type_info['form_fields'][attribute]['optional']: | if 'optional' in user_type_info['form_fields'][attribute] and user_type_info['form_fields'][attribute]['optional']: | ||||
may_attrs.append(attribute) | may_attrs.append(attribute) | ||||
else: | else: | ||||
must_attrs.append(attribute) | must_attrs.append(attribute) | ||||
else: | else: | ||||
must_attrs.append(attribute) | must_attrs.append(attribute) | ||||
for attribute in must_attrs: | for attribute in must_attrs: | ||||
if isinstance(user_type_info['form_fields'][attribute], dict) and \ | if isinstance(user_type_info['form_fields'][attribute], dict) and \ | ||||
user_type_info['form_fields'][attribute].has_key('type'): | 'type' in user_type_info['form_fields'][attribute]: | ||||
if user_type_info['form_fields'][attribute]['type'] == 'select': | if user_type_info['form_fields'][attribute]['type'] == 'select': | ||||
if not user_type_info['form_fields'][attribute].has_key('values'): | if 'values' not in user_type_info['form_fields'][attribute]: | ||||
attribute_values = form_value_select_options('user', user_type_id, attribute) | attribute_values = form_value_select_options('user', user_type_id, attribute) | ||||
default = '' | default = '' | ||||
if attribute_values[attribute].has_key('default'): | if 'default' in attribute_values[attribute]: | ||||
default = attribute_values[attribute]['default'] | default = attribute_values[attribute]['default'] | ||||
params[attribute] = utils.ask_menu( | params[attribute] = utils.ask_menu( | ||||
"Choose the %s value" % (attribute), | "Choose the %s value" % (attribute), | ||||
attribute_values[attribute]['list'], | attribute_values[attribute]['list'], | ||||
default=default | default=default | ||||
) | ) | ||||
else: | else: | ||||
default = '' | default = '' | ||||
if user_type_info['form_fields'][attribute].has_key('default'): | if 'default' in user_type_info['form_fields'][attribute]: | ||||
default = user_type_info['form_fields'][attribute]['default'] | default = user_type_info['form_fields'][attribute]['default'] | ||||
params[attribute] = utils.ask_menu( | params[attribute] = utils.ask_menu( | ||||
"Choose the %s value" % (attribute), | "Choose the %s value" % (attribute), | ||||
user_type_info['form_fields'][attribute]['values'], | user_type_info['form_fields'][attribute]['values'], | ||||
default=default | default=default | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | |||||
def role_delete(params=None): | def role_delete(params=None): | ||||
if params == None: | if params == None: | ||||
role_name = utils.ask_question("Role name") | role_name = utils.ask_question("Role name") | ||||
role = role_find_by_attribute({'cn': role_name}) | role = role_find_by_attribute({'cn': role_name}) | ||||
params = { | params = { | ||||
'role': role.keys()[0] | 'role': role.keys()[0] | ||||
} | } | ||||
if not params.has_key('role'): | if 'role' not in params: | ||||
role = role_find_by_attribute(params) | role = role_find_by_attribute(params) | ||||
params = { | params = { | ||||
'role': role.keys()[0] | 'role': role.keys()[0] | ||||
} | } | ||||
post = json.dumps(params) | post = json.dumps(params) | ||||
return request('POST', 'role.delete', post=post) | return request('POST', 'role.delete', post=post) | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | def user_edit(user = None, attributes={}): | ||||
return user_edit | return user_edit | ||||
def user_find(attribs=None): | def user_find(attribs=None): | ||||
if attribs == None: | if attribs == None: | ||||
post = { | post = { | ||||
'search': { | 'search': { | ||||
'params': { | 'params': { | ||||
utils.ask_question("Attribute") : { | utils.ask_question("Attribute") : { | ||||
Lint: PEP8 E203: whitespace before ':' | |||||
'value': utils.ask_question("value"), | 'value': utils.ask_question("value"), | ||||
'type': 'exact' | 'type': 'exact' | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else: | else: | ||||
post = { 'search': { 'params': {} } } | post = { 'search': { 'params': {} } } | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
whitespace before ':'