Skip to content

Commit 539be6b

Browse files
authored
[Python] Add optional flag to disable printing from the SOFA side (#112)
* fix errors introduced by the progresshandler PR * add optional flag to disable printing from sofa
1 parent d6a52f0 commit 539be6b

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

SofaRegressionProgram.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ def make_parser():
145145
help='If set, will display more information',
146146
action='store_true'
147147
)
148+
parser.add_argument(
149+
"--quiet",
150+
dest="quiet",
151+
help='If set, will only print error messages and results.',
152+
action='store_true'
153+
)
148154
parser.add_argument(
149155
"--legacy-regression",
150156
dest="legacy_mode",
@@ -185,11 +191,25 @@ def make_parser():
185191
reg_prog.replay_references(replayId)
186192
sys.exit()
187193

194+
old_fd = os.dup(1)
195+
if args.quiet:
196+
# Save and redirect
197+
sys.stdout.flush()
198+
devnull = os.open(os.devnull, os.O_WRONLY)
199+
os.dup2(devnull, 1)
200+
os.close(devnull)
201+
188202
if args.write_mode:
189203
nbr_scenes = reg_prog.write_all_sets_references()
190204
else:
191205
nbr_scenes = reg_prog.compare_all_sets_references()
192206

207+
if args.quiet:
208+
# Restore
209+
sys.stdout.flush()
210+
os.dup2(old_fd, 1)
211+
os.close(old_fd)
212+
193213
np.set_printoptions(legacy='1.25') # revert printing floating-point type in numpy (concretely remove np.array when displaying a list of np.float)
194214

195215
print ("### Number of sets Done: " + str(len(reg_prog.scene_sets)))

0 commit comments

Comments
 (0)