18
18
#
19
19
20
20
#
21
- # Copyright (c) 2017, 2023 , Oracle and/or its affiliates. All rights reserved.
21
+ # Copyright (c) 2017, 2024 , Oracle and/or its affiliates. All rights reserved.
22
22
#
23
23
24
24
import logging
@@ -49,10 +49,13 @@ class Command:
49
49
ERRORED = "errored"
50
50
TIMEDOUT = "timed out"
51
51
52
+ MAX_LINE_LENGTH_DEFAULT = 250
53
+ MAX_LINES_DEFAULT = 10000
54
+
52
55
def __init__ (self , cmd , args_subst = None , args_append = None , logger = None ,
53
56
excl_subst = False , work_dir = None , env_vars = None , timeout = None ,
54
57
redirect_stderr = True , resource_limits = None , doprint = False ,
55
- max_line_length = 250 , max_lines = 10000 ):
58
+ max_line_length = None , max_lines = None ):
56
59
57
60
if doprint is None :
58
61
doprint = False
@@ -72,8 +75,17 @@ def __init__(self, cmd, args_subst=None, args_append=None, logger=None,
72
75
self .doprint = doprint
73
76
self .err = None
74
77
self .returncode = None
75
- self .max_line_length = int (max_line_length )
76
- self .max_lines = int (max_lines )
78
+
79
+ # Convert the maximums to integers to avoid exceptions when using them as indexes
80
+ # in case they are passed as floats.
81
+ if (max_line_length is None ):
82
+ self .max_line_length = self .MAX_LINE_LENGTH_DEFAULT
83
+ else :
84
+ self .max_line_length = int (max_line_length )
85
+ if (max_lines is None ):
86
+ self .max_lines = self .MAX_LINES_DEFAULT
87
+ else :
88
+ self .max_lines = int (max_lines )
77
89
78
90
self .logger = logger or logging .getLogger (__name__ )
79
91
@@ -162,7 +174,10 @@ class OutputThread(threading.Thread):
162
174
stdout/stderr buffers fill up.
163
175
"""
164
176
165
- def __init__ (self , event , logger , doprint = False , max_line_length = 250 , max_lines = 10000 ):
177
+ def __init__ (self , event , logger , doprint = False ,
178
+ max_line_length = Command .MAX_LINE_LENGTH_DEFAULT ,
179
+ max_lines = Command .MAX_LINES_DEFAULT ):
180
+
166
181
super (OutputThread , self ).__init__ ()
167
182
self .read_fd , self .write_fd = os .pipe ()
168
183
self .pipe_fobj = os .fdopen (self .read_fd , encoding = 'utf8' )
@@ -195,11 +210,11 @@ def run(self):
195
210
line = line .rstrip () # This will remove not only newline but also whitespace.
196
211
197
212
# Assuming that self.max_line_length is bigger than 3.
198
- if len (line ) > self .max_line_length :
213
+ if self . max_line_length > 0 and len (line ) > self .max_line_length :
199
214
line = line [:self .max_line_length ] + "..."
200
215
201
216
# Shorten the list to be one less than the maximum because a line is going to be added.
202
- if len (self .out ) >= self .max_lines :
217
+ if self . max_lines > 0 and len (self .out ) >= self .max_lines :
203
218
self .out = self .out [- self .max_lines + 1 :]
204
219
self .out [0 ] = "... <truncated>"
205
220
0 commit comments