1 |
douglas |
587 |
#!/usr/bin/env python |
2 |
|
|
# CCS Computer Science |
3 |
douglas |
592 |
# Change Full Name |
4 |
douglas |
587 |
# |
5 |
|
|
# Douglas Thrift |
6 |
|
|
# |
7 |
|
|
# $Id$ |
8 |
|
|
|
9 |
douglas |
593 |
from __future__ import with_statement |
10 |
douglas |
591 |
import admin |
11 |
douglas |
590 |
import common |
12 |
douglas |
593 |
import ldap |
13 |
douglas |
598 |
import psycopg2 |
14 |
douglas |
587 |
import re |
15 |
douglas |
593 |
import sys |
16 |
douglas |
598 |
import users |
17 |
douglas |
587 |
|
18 |
douglas |
593 |
if sys.hexversion >= 0x2060000: |
19 |
|
|
import warnings |
20 |
|
|
|
21 |
|
|
with warnings.catch_warnings(): |
22 |
|
|
warnings.filterwarnings('ignore', 'the sets module is deprecated', DeprecationWarning) |
23 |
|
|
|
24 |
|
|
import MySQLdb |
25 |
|
|
else: |
26 |
|
|
import MySQLdb |
27 |
|
|
|
28 |
douglas |
587 |
if __name__ == '__main__': |
29 |
|
|
try: |
30 |
douglas |
598 |
user = '' |
31 |
|
|
string = re.compile('^[a-z0-9]{1,16}$') |
32 |
douglas |
587 |
|
33 |
douglas |
598 |
while string.match(user) is None: |
34 |
|
|
user = raw_input('User Name: ') |
35 |
douglas |
597 |
|
36 |
douglas |
598 |
if users.user(user): |
37 |
|
|
admin.error('User exists: %s.' % user) |
38 |
douglas |
587 |
|
39 |
douglas |
598 |
name = '' |
40 |
|
|
string = re.compile('^[^:]+$') |
41 |
douglas |
593 |
|
42 |
douglas |
598 |
while string.match(name) is None: |
43 |
|
|
name = raw_input('Full Name: ') |
44 |
|
|
|
45 |
|
|
password = common.new_password() |
46 |
|
|
|
47 |
douglas |
591 |
if admin.master(): |
48 |
douglas |
598 |
admin.adduser(user, name, password) |
49 |
|
|
|
50 |
|
|
admin.run(common.add_all(user, name, password)) |
51 |
|
|
except (common.PasswordError, ldap.LDAPError, OSError, MySQLdb.MySQLError, psycopg2.Error, psycopg2.Warning), error: |
52 |
douglas |
593 |
admin.error(error) |
53 |
douglas |
587 |
except (EOFError, KeyboardInterrupt): |
54 |
douglas |
592 |
admin.eof() |