From a0c8deb806d61102d4a979b42bacc3a1bb59ee3b Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Tue, 17 Sep 2019 12:31:03 +0200 Subject: [PATCH] obi export: made output to stdout and pipe in less possible --- python/obitools3/commands/export.pyx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/python/obitools3/commands/export.pyx b/python/obitools3/commands/export.pyx index 387e159..8fe7df1 100755 --- a/python/obitools3/commands/export.pyx +++ b/python/obitools3/commands/export.pyx @@ -7,9 +7,11 @@ from obitools3.dms import DMS from obitools3.dms.obiseq import Nuc_Seq from obitools3.apps.optiongroups import addMinimalInputOption, \ - addExportOutputOption + addExportOutputOption, \ + addNoProgressBarOption import sys +import io __title__="Export a view to a different file format" @@ -18,6 +20,7 @@ def addOptions(parser): addMinimalInputOption(parser) addExportOutputOption(parser) + addNoProgressBarOption(parser) def run(config): @@ -46,24 +49,33 @@ def run(config): raise Exception("Error: the view to export in fasta or fastq format is not a NUC_SEQS view") # Initialize the progress bar - pb = ProgressBar(len(iview), config, seconde=5) + if config['obi']['noprogressbar']: + pb = None + else: + pb = ProgressBar(len(iview), config, seconde=5) i=0 for seq in iview : - pb(i) + if pb is not None: + pb(i) try: writer(seq) - except StopIteration: + except (StopIteration, BrokenPipeError, IOError): break i+=1 - pb(i, force=True) + if pb is not None: + pb(i, force=True) print("", file=sys.stderr) # TODO save command in input dms? - output_object.close() + if not BrokenPipeError and not IOError: + output_object.close() iview.close() input[0].close() logger("info", "Done.") + + if BrokenPipeError or IOError: + sys.stderr.close()