2727"""
2828
2929import argparse
30+ import logging
3031import multiprocessing
3132import os
3233import sys
5253 print ("Need Python 3, you are running {}" .format (major_version ))
5354 sys .exit (1 )
5455
55- __version__ = "1.4 "
56+ __version__ = "1.5 "
5657
5758
5859def worker (base ):
@@ -69,7 +70,7 @@ def worker(base):
6970
7071def do_sync (loglevel , commands , cleanup , dirs_to_process , ignore_errors ,
7172 uri , numworkers , driveon = False , print_output = False , logger = None ,
72- http_headers = None , timeout = None , api_timeout = None ):
73+ http_headers = None , timeout = None , api_timeout = None , check_config = False ):
7374 """
7475 Process the list of directories in parallel.
7576 :param logger: logger to be used in this function
@@ -87,19 +88,26 @@ def do_sync(loglevel, commands, cleanup, dirs_to_process, ignore_errors,
8788 :param http_headers: optional dictionary of HTTP headers
8889 :param timeout: optional timeout in seconds for API call response
8990 :param api_timeout: optional timeout in seconds for async API call duration
91+ :param check_config: check configuration and return
9092 :return SUCCESS_EXITVAL on success, FAILURE_EXITVAL on error
9193 """
9294
9395 cmds_base = []
94- for dir in dirs_to_process :
95- cmd_base = CommandSequenceBase (dir , commands , loglevel = loglevel ,
96+ for directory in dirs_to_process :
97+ cmd_base = CommandSequenceBase (directory , commands , loglevel = loglevel ,
9698 cleanup = cleanup ,
9799 driveon = driveon , url = uri ,
98100 http_headers = http_headers ,
99101 api_timeout = timeout ,
100102 async_api_timeout = api_timeout )
101103 cmds_base .append (cmd_base )
102104
105+ if check_config :
106+ if not logger :
107+ logger = logging .getLogger (__name__ )
108+ logger .info ("Configuration check passed" )
109+ return SUCCESS_EXITVAL
110+
103111 # Map the commands into pool of workers, so they can be processed.
104112 retval = SUCCESS_EXITVAL
105113 with Pool (processes = numworkers ) as pool :
@@ -160,6 +168,8 @@ def main():
160168 'for RESTful API calls' )
161169 parser .add_argument ('--async_api_timeout' , type = int , default = 300 ,
162170 help = 'Set timeout in seconds for asynchronous REST API calls' )
171+ parser .add_argument ('--check_config' , action = 'store_true' ,
172+ help = 'check configuration and exit' )
163173 add_http_headers (parser )
164174
165175 try :
@@ -280,7 +290,8 @@ def main():
280290 ignore_errors , uri , args .workers ,
281291 driveon = args .driveon , http_headers = headers ,
282292 timeout = args .api_timeout ,
283- api_timeout = args .async_api_timeout )
293+ api_timeout = args .async_api_timeout ,
294+ check_config = args .check_config )
284295 except CommandConfigurationException as exc :
285296 logger .error ("Invalid configuration: {}" .format (exc ))
286297 return FAILURE_EXITVAL
@@ -295,7 +306,8 @@ def main():
295306 ignore_errors , uri , args .workers ,
296307 driveon = args .driveon , http_headers = headers ,
297308 timeout = args .api_timeout ,
298- api_timeout = args .async_api_timeout )
309+ api_timeout = args .async_api_timeout ,
310+ check_config = args .check_config )
299311 except CommandConfigurationException as exc :
300312 logger .error ("Invalid configuration: {}" .format (exc ))
301313 return FAILURE_EXITVAL
0 commit comments