27
27
"""
28
28
29
29
import argparse
30
+ import logging
30
31
import multiprocessing
31
32
import os
32
33
import sys
52
53
print ("Need Python 3, you are running {}" .format (major_version ))
53
54
sys .exit (1 )
54
55
55
- __version__ = "1.4 "
56
+ __version__ = "1.5 "
56
57
57
58
58
59
def worker (base ):
@@ -69,7 +70,7 @@ def worker(base):
69
70
70
71
def do_sync (loglevel , commands , cleanup , dirs_to_process , ignore_errors ,
71
72
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 ):
73
74
"""
74
75
Process the list of directories in parallel.
75
76
:param logger: logger to be used in this function
@@ -87,19 +88,26 @@ def do_sync(loglevel, commands, cleanup, dirs_to_process, ignore_errors,
87
88
:param http_headers: optional dictionary of HTTP headers
88
89
:param timeout: optional timeout in seconds for API call response
89
90
:param api_timeout: optional timeout in seconds for async API call duration
91
+ :param check_config: check configuration and return
90
92
:return SUCCESS_EXITVAL on success, FAILURE_EXITVAL on error
91
93
"""
92
94
93
95
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 ,
96
98
cleanup = cleanup ,
97
99
driveon = driveon , url = uri ,
98
100
http_headers = http_headers ,
99
101
api_timeout = timeout ,
100
102
async_api_timeout = api_timeout )
101
103
cmds_base .append (cmd_base )
102
104
105
+ if check_config :
106
+ if not logger :
107
+ logger = logging .getLogger (__name__ )
108
+ logger .info ("Configuration check passed" )
109
+ return SUCCESS_EXITVAL
110
+
103
111
# Map the commands into pool of workers, so they can be processed.
104
112
retval = SUCCESS_EXITVAL
105
113
with Pool (processes = numworkers ) as pool :
@@ -160,6 +168,8 @@ def main():
160
168
'for RESTful API calls' )
161
169
parser .add_argument ('--async_api_timeout' , type = int , default = 300 ,
162
170
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' )
163
173
add_http_headers (parser )
164
174
165
175
try :
@@ -280,7 +290,8 @@ def main():
280
290
ignore_errors , uri , args .workers ,
281
291
driveon = args .driveon , http_headers = headers ,
282
292
timeout = args .api_timeout ,
283
- api_timeout = args .async_api_timeout )
293
+ api_timeout = args .async_api_timeout ,
294
+ check_config = args .check_config )
284
295
except CommandConfigurationException as exc :
285
296
logger .error ("Invalid configuration: {}" .format (exc ))
286
297
return FAILURE_EXITVAL
@@ -295,7 +306,8 @@ def main():
295
306
ignore_errors , uri , args .workers ,
296
307
driveon = args .driveon , http_headers = headers ,
297
308
timeout = args .api_timeout ,
298
- api_timeout = args .async_api_timeout )
309
+ api_timeout = args .async_api_timeout ,
310
+ check_config = args .check_config )
299
311
except CommandConfigurationException as exc :
300
312
logger .error ("Invalid configuration: {}" .format (exc ))
301
313
return FAILURE_EXITVAL
0 commit comments