Skip to content

Commit cf2cb7f

Browse files
d-w-moorealanking
authored andcommitted
[#537] add --help option to the script setupssl.py
1 parent 732bc3c commit cf2cb7f

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

irods/test/setupssl.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python
22

33
from __future__ import print_function
4+
import numbers
45
import os
5-
import sys
6-
import socket
76
import posix
7+
import socket
88
import shutil
99
from subprocess import (Popen, PIPE)
10+
import sys
1011

1112
IRODS_SSL_DIR = '/etc/irods/ssl'
1213
SERVER_CERT_HOSTNAME = None
@@ -71,24 +72,33 @@ def test(options, args=()):
7172
ssl_dir_files = create_ssl_dir(use_strong_primes_for_dh_generation = dh_strong_primes)
7273
print('ssl_dir_files=', ssl_dir_files, file = sys.stderr)
7374

75+
def usage(exit_code = None):
76+
77+
print("""Usage: {sys.argv[0]} [-f] [-h <hostname>] [-k] [-q] [-x <extension>]
78+
-f Force replacement of the existing SSL directory (/etc/irods/ssl) with a new one, containing newly generated files.
79+
-h In the generated certificate, use the given hostname rather than the value returned from socket.gethostname()
80+
-k (Keep old secrets files.) Do not generate new key file or dhparams.pem file.
81+
-q For testing; do a quick generation of a dhparams.pem file rather than waiting on system entropy to make it more secure.
82+
-x Optional extra extension for appending to end of the filename for the generated certificate.
83+
--help Print this help.
84+
85+
Any invalid option prints this help.
86+
""".format(**globals()), file = sys.stderr)
87+
if isinstance(exit_code, numbers.Integral):
88+
exit(exit_code)
89+
7490
if __name__ == '__main__':
7591
import getopt
7692
try:
77-
opt, arg_list = getopt.getopt(sys.argv[1:],'x:fh:kq')
93+
opt, arg_list = getopt.getopt(sys.argv[1:],'x:fh:kq',['help'])
7894
except getopt.GetoptError:
79-
print("""Usage: {sys.argv[0]} [-f] [-h <hostname>] [-k] [-q] [-x <extension>]
80-
-f Force replacement of the existing SSL directory (/etc/irods/ssl) with a new one, containing newly generated files.
81-
-h In the generated certificate, use the given hostname rather than the value returned from socket.gethostname()
82-
-k (Keep old secrets files.) Do not generate new key file or dhparams.pem file.
83-
-q For testing; do a quick generation of a dhparams.pem file rather than waiting on system entropy to make it more secure.
84-
-x Optional extra extension for appending to end of the filename for the generated certificate.
85-
86-
Any invalid option prints this help.
87-
""".format(**locals()), file = sys.stderr)
88-
exit(1)
95+
usage(exit_code = 1)
8996

9097
opt_lookup = dict(opt)
9198

99+
if '--help' in opt_lookup:
100+
usage(exit_code = 0)
101+
92102
ext = opt_lookup.get('-x','')
93103
if ext:
94104
ext = '.' + ext.lstrip('.')

0 commit comments

Comments
 (0)