Skip to content

Commit 681d94c

Browse files
committed
changed default behaviour to output NO_AVAILABLE_SERVER and blank only if using --quiet
1 parent 46c3e15 commit 681d94c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

find_active_server.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
sys.exit(4)
8585

8686
__author__ = 'Hari Sekhon'
87-
__version__ = '0.3.3'
87+
__version__ = '0.4'
8888

8989

9090
class FindActiveServer(CLI):
@@ -120,6 +120,8 @@ def add_options(self):
120120
'use -n=1 for deterministic host preference order [slower])')
121121
self.add_opt('-R', '--random', action='store_true', help='Randomize order of hosts tested ' +
122122
'(for use with --num-threads=1)')
123+
self.add_opt('-q', '--quiet', action='store_true', help='Returns no output instead of NO_AVAILABLE_SERVER '\
124+
+ '(convenience for scripting)')
123125
self.add_opt('-T', '--request-timeout', metavar='secs', type='int',
124126
help='Timeout for each individual server request in seconds (default: 1 second)')
125127

@@ -197,7 +199,7 @@ def run(self):
197199
# self.finish(host, port)
198200
self.launch_thread(self.check_socket, host, port)
199201
self.collect_results()
200-
if self.verbose:
202+
if not self.get_opt('quiet'):
201203
print('NO_AVAILABLE_SERVER')
202204
sys.exit(1)
203205

@@ -289,9 +291,9 @@ def check_http(self, host, port, url_path=''):
289291
if not isStr(url_path):
290292
url_path = ''
291293
url = '{protocol}://{host}:{port}/{url_path}'.format(protocol=self.protocol,
292-
host=host,
293-
port=port,
294-
url_path=url_path.lstrip('/'))
294+
host=host,
295+
port=port,
296+
url_path=url_path.lstrip('/'))
295297
log.info('GET %s', url)
296298
try:
297299
# timeout here isn't total timeout, it's response time

0 commit comments

Comments
 (0)