44
44
from mig .shared .conf import get_configuration_object
45
45
from mig .shared .defaults import valid_auth_types , keyword_auto
46
46
from mig .shared .gdp .all import ensure_gdp_user
47
+ from mig .shared .minimist import parse_getopt_args , break_apart_legacy_usage
47
48
from mig .shared .pwcrypto import unscramble_password , scramble_password , \
48
49
make_hash
49
50
from mig .shared .serial import load
@@ -75,21 +76,36 @@ def usage(name='createuser.py'):
75
76
or
76
77
%(name)s [OPTIONS] -i CERT_DN
77
78
Where OPTIONS may be one or more of:
78
- -a AUTH_TYPE Prepare account for AUTH_TYPE login (expire, password)
79
- -c CONF_FILE Use CONF_FILE as server configuration
80
- -d DB_FILE Use DB_FILE as user data base file
81
- -e EXPIRE Set user account expiration to EXPIRE (epoch)
82
- -f Force operations to continue past errors
83
- -h Show this help
84
- -i CERT_DN Use CERT_DN as user ID despite what other fields suggest
85
- -o SHORT_ID Add SHORT_ID as OpenID alias for user
86
- -p PEER_PATTERN Verify in Peers of existing account matching PEER_PATTERN
87
- -r Renew user account with existing values
88
- -R ROLES Set user affiliation to ROLES
89
- -s SLACK_DAYS Allow peers even with account expired within SLACK_DAYS
90
- -u USER_FILE Read user information from pickle file
91
- -v Verbose output
92
- """ % {'name' : name , 'cert_warn' : cert_warn })
79
+ """ )
80
+
81
+ name_by_argument = break_apart_legacy_usage ("""
82
+ -a: AUTH_TYPE
83
+ -c: CONF_FILE
84
+ -d: DB_FILE
85
+ -e: EXPIRE
86
+ -i: CERT_DN
87
+ -o: SHORT_ID
88
+ -p: PEER_PATTERN
89
+ -R: ROLES
90
+ -s: SLACK_DAYS
91
+ -u: USER_FILE
92
+ """ )
93
+
94
+ help_by_argument = break_apart_legacy_usage ("""
95
+ -a: Prepare account for AUTH_TYPE login (expire, password)
96
+ -c: Use CONF_FILE as server configuration
97
+ -d: Use DB_FILE as user data base file
98
+ -e: Set user account expiration to EXPIRE (epoch)
99
+ -f: Force operations to continue past errors
100
+ -i: Use CERT_DN as user ID despite what other fields suggest
101
+ -o: Add SHORT_ID as OpenID alias for user
102
+ -p: Verify in Peers of existing account matching PEER_PATTERN
103
+ -r: Renew user account with existing values
104
+ -R: Set user affiliation to ROLES
105
+ -s: Allow peers even with account expired within SLACK_DAYS
106
+ -u: Read user information from pickle file
107
+ -v: Verbose output
108
+ """ )
93
109
94
110
95
111
def main (args , cwd , db_path = keyword_auto ):
@@ -113,7 +129,9 @@ def main(args, cwd, db_path=keyword_auto):
113
129
opt_args = 'a:c:d:e:fhi:o:p:rR:s:u:v'
114
130
115
131
try :
116
- (opts , args ) = getopt .getopt (args , opt_args )
132
+ (opts , args ) = parse_getopt_args (args , opt_args ,
133
+ help_by_argument = help_by_argument ,
134
+ name_by_argument = name_by_argument )
117
135
except getopt .GetoptError as err :
118
136
print ('Error: ' , err .msg )
119
137
usage ()
@@ -138,7 +156,7 @@ def main(args, cwd, db_path=keyword_auto):
138
156
expire = int (raw )
139
157
parsed = True
140
158
break
141
- except ValueError :
159
+ except ( TypeError , ValueError ) :
142
160
print ('Failed to parse expire value: %s' % val )
143
161
sys .exit (1 )
144
162
elif opt == '-f' :
0 commit comments