43
43
add_project , delete_project , get_config_value
44
44
from .utils .parsers import get_baseparser
45
45
from .utils .utils import get_command , is_web_uri
46
+ from .utils .exitvals import (
47
+ FAILURE_EXITVAL ,
48
+ SUCCESS_EXITVAL
49
+ )
46
50
47
51
MAJOR_VERSION = sys .version_info [0 ]
48
52
if (MAJOR_VERSION < 3 ):
@@ -62,11 +66,12 @@ def exec_command(doit, logger, cmd, msg):
62
66
logger .info (cmd )
63
67
return
64
68
cmd .execute ()
65
- if cmd .getstate () is not Command .FINISHED or cmd .getretcode () != 0 :
69
+ if cmd .getstate () is not Command .FINISHED \
70
+ or cmd .getretcode () != SUCCESS_EXITVAL :
66
71
logger .error (msg )
67
72
logger .error ("Standard output: {}" .format (cmd .getoutput ()))
68
73
logger .error ("Error output: {}" .format (cmd .geterroutput ()))
69
- sys .exit (1 )
74
+ sys .exit (FAILURE_EXITVAL )
70
75
71
76
logger .debug (cmd .geterroutputstr ())
72
77
@@ -99,11 +104,11 @@ def install_config(doit, logger, src, dst):
99
104
except PermissionError :
100
105
logger .error ('Failed to copy {} to {} (permissions)' .
101
106
format (src , dst ))
102
- sys .exit (1 )
107
+ sys .exit (FAILURE_EXITVAL )
103
108
except OSError :
104
109
logger .error ('Failed to copy {} to {} (I/O)' .
105
110
format (src , dst ))
106
- sys .exit (1 )
111
+ sys .exit (FAILURE_EXITVAL )
107
112
108
113
109
114
def config_refresh (doit , logger , basedir , uri , configmerge , jar_file ,
@@ -120,12 +125,12 @@ def config_refresh(doit, logger, basedir, uri, configmerge, jar_file,
120
125
main_config = get_config_file (basedir )
121
126
if not path .isfile (main_config ):
122
127
logger .error ("file {} does not exist" .format (main_config ))
123
- sys .exit (1 )
128
+ sys .exit (FAILURE_EXITVAL )
124
129
125
130
if doit :
126
131
current_config = get_configuration (logger , uri )
127
132
if not current_config :
128
- sys .exit (1 )
133
+ sys .exit (FAILURE_EXITVAL )
129
134
else :
130
135
current_config = None
131
136
@@ -260,7 +265,7 @@ def main():
260
265
261
266
if args .nosourcedelete and not args .delete :
262
267
logger .error ("The no source delete option is only valid for delete" )
263
- sys .exit (1 )
268
+ sys .exit (FAILURE_EXITVAL )
264
269
265
270
# Set the base directory
266
271
if args .base :
@@ -271,7 +276,7 @@ def main():
271
276
logger .error ("Not a directory: {}\n "
272
277
"Set the base directory with the --base option."
273
278
.format (args .base ))
274
- sys .exit (1 )
279
+ sys .exit (FAILURE_EXITVAL )
275
280
276
281
# If read-only configuration file is specified, this means read-only
277
282
# configuration will need to be merged with active webapp configuration.
@@ -282,14 +287,14 @@ def main():
282
287
logger .debug ("Using {} as read-only config" .format (args .roconfig ))
283
288
else :
284
289
logger .error ("File {} does not exist" .format (args .roconfig ))
285
- sys .exit (1 )
290
+ sys .exit (FAILURE_EXITVAL )
286
291
287
292
configmerge_file = get_command (logger , args .configmerge ,
288
293
"opengrok-config-merge" )
289
294
if configmerge_file is None :
290
295
logger .error ("Use the --configmerge option to specify the path to"
291
296
"the config merge script" )
292
- sys .exit (1 )
297
+ sys .exit (FAILURE_EXITVAL )
293
298
294
299
configmerge = [configmerge_file ]
295
300
if args .loglevel :
@@ -299,12 +304,12 @@ def main():
299
304
if args .jar is None :
300
305
logger .error ('jar file needed for config merge tool, '
301
306
'use --jar to specify one' )
302
- sys .exit (1 )
307
+ sys .exit (FAILURE_EXITVAL )
303
308
304
309
uri = args .uri
305
310
if not is_web_uri (uri ):
306
311
logger .error ("Not a URI: {}" .format (uri ))
307
- sys .exit (1 )
312
+ sys .exit (FAILURE_EXITVAL )
308
313
logger .debug ("web application URI = {}" .format (uri ))
309
314
310
315
lock = FileLock (os .path .join (tempfile .gettempdir (),
@@ -348,7 +353,7 @@ def main():
348
353
java = args .java )
349
354
else :
350
355
parser .print_help ()
351
- sys .exit (1 )
356
+ sys .exit (FAILURE_EXITVAL )
352
357
353
358
if args .upload :
354
359
main_config = get_config_file (basedir = args .base )
@@ -359,13 +364,13 @@ def main():
359
364
config_data = config_file .read ().encode ("utf-8" )
360
365
if not set_configuration (logger ,
361
366
config_data , uri ):
362
- sys .exit (1 )
367
+ sys .exit (FAILURE_EXITVAL )
363
368
else :
364
369
logger .error ("file {} does not exist" .format (main_config ))
365
- sys .exit (1 )
370
+ sys .exit (FAILURE_EXITVAL )
366
371
except Timeout :
367
372
logger .warning ("Already running, exiting." )
368
- sys .exit (1 )
373
+ sys .exit (FAILURE_EXITVAL )
369
374
370
375
371
376
if __name__ == '__main__' :
0 commit comments