1 |
douglas |
606 |
#!/usr/bin/env python |
2 |
|
|
# CCS Computer Science |
3 |
|
|
# Secret Password |
4 |
|
|
# |
5 |
|
|
# Douglas Thrift |
6 |
|
|
# |
7 |
|
|
# $Id$ |
8 |
|
|
|
9 |
|
|
import admin |
10 |
|
|
import common |
11 |
|
|
import os |
12 |
|
|
|
13 |
|
|
if __name__ == '__main__': |
14 |
douglas |
681 |
parser = admin.parser() |
15 |
douglas |
606 |
|
16 |
douglas |
687 |
parser.add_option('-f', '--force', action = 'store_true', help = 'prompt for a new secret even if one already exists') |
17 |
douglas |
606 |
|
18 |
douglas |
687 |
if parser.parse_args()[0].force or not os.path.exists(admin.SECRET): |
19 |
douglas |
681 |
try: |
20 |
|
|
password = common.new_password() |
21 |
|
|
|
22 |
|
|
os.umask(0077) |
23 |
|
|
|
24 |
|
|
with open(admin.SECRET, 'wb') as secret: |
25 |
|
|
secret.write(password) |
26 |
|
|
except (common.PasswordError, IOError), error: |
27 |
|
|
admin.error(error) |
28 |
|
|
except (EOFError, KeyboardInterrupt): |
29 |
|
|
admin.eof() |