ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccs/admin/shells.py
Revision: 681
Committed: 2010-07-13T02:19:33-07:00 (14 years, 11 months ago) by douglas
Content type: text/x-python
File size: 1694 byte(s)
Log Message:
Add mksh to available shells; options with argparse (not sure if I like it).

File Contents

# User Rev Content
1 douglas 602 #!/usr/bin/env python
2     # CCS Computer Science
3     # Shells
4     #
5     # Douglas Thrift
6     #
7     # $Id$
8    
9     import admin
10     import common
11     import copy
12     import ldap
13     import ldap.modlist
14    
15     if __name__ == '__main__':
16 douglas 681 parser = admin.parser()
17     commands = parser.add_mutually_exclusive_group(required = True)
18 douglas 602
19 douglas 681 commands.add_argument('-l', '--list', action = 'store_const', const = 'list', help = 'list the available shells and their per system paths', dest = 'command')
20     commands.add_argument('-u', '--update', action = 'store_const', const = 'update', help = 'update shells in the LDAP database', dest = 'command')
21 douglas 602
22 douglas 681 command = parser.parse_args().command
23 douglas 602
24 douglas 681 if command == 'list':
25     for shell, shells in common.SHELLS:
26     print 'shell:', shell
27 douglas 602
28 douglas 681 for system, shell in zip(common.SYSTEMS, shells):
29     print '%20s:' % system, shell if shell else '{user defined}'
30     elif command == 'update':
31     shells = list(common.SHELLS)
32     shells[-1] = ('custom', dict(common.SHELLS)['bash'])
33 douglas 602
34 douglas 681 try:
35     connection = admin.ldap_connection()
36 douglas 602
37 douglas 681 for shell, shells in shells:
38     for dn, old_entry in connection.search_s(admin.PEOPLE, ldap.SCOPE_ONELEVEL, '(loginShell=%s)' % shell, ['uid'] + admin.SHELLS):
39 douglas 602
40 douglas 681 if shell != 'custom':
41     new_entry = dict(zip(admin.SHELLS, map(lambda shell: [shell], shells)))
42     else:
43     new_entry = copy.copy(old_entry)
44 douglas 602
45 douglas 681 for type, _shell in zip(admin.SHELLS, shells):
46     if type not in new_entry:
47     new_entry[type] = _shell
48    
49     modlist = ldap.modlist.modifyModlist(old_entry, new_entry, ('uid',))
50    
51     if modlist:
52     print old_entry['uid'][0], modlist
53    
54     connection.modify_s(dn, modlist)
55    
56     connection.unbind_s()
57     except (IOError, ldap.LDAPError), error:
58     admin.error(error)

Properties

Name Value
svn:executable *
svn:keywords Id