obi less: now actually behaves like less
This commit is contained in:
@ -1,9 +1,17 @@
|
|||||||
#cython: language_level=3
|
#cython: language_level=3
|
||||||
|
|
||||||
from obitools3.apps.optiongroups import addMinimalInputOption
|
from obitools3.apps.progress cimport ProgressBar # @UnresolvedImport
|
||||||
from obitools3.uri.decode import open_uri
|
from obitools3.uri.decode import open_uri
|
||||||
from obitools3.dms import DMS
|
from obitools3.dms import DMS
|
||||||
|
from obitools3.utils cimport tobytes
|
||||||
|
from obitools3.dms.capi.obiview cimport QUALITY_COLUMN
|
||||||
|
from obitools3.apps.optiongroups import addMinimalInputOption
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import io
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
|
from cpython.exc cimport PyErr_CheckSignals
|
||||||
|
|
||||||
__title__="Less equivalent"
|
__title__="Less equivalent"
|
||||||
|
|
||||||
@ -12,33 +20,31 @@ def addOptions(parser):
|
|||||||
|
|
||||||
addMinimalInputOption(parser)
|
addMinimalInputOption(parser)
|
||||||
|
|
||||||
group=parser.add_argument_group('obi less specific options')
|
|
||||||
|
|
||||||
group.add_argument('--print', '-n',
|
|
||||||
action="store", dest="less:print",
|
|
||||||
metavar='<N>',
|
|
||||||
default=10,
|
|
||||||
type=int,
|
|
||||||
help="Print N entries (default: 10)")
|
|
||||||
|
|
||||||
|
|
||||||
def run(config):
|
def run(config):
|
||||||
|
|
||||||
cdef object entries
|
|
||||||
cdef int n
|
|
||||||
|
|
||||||
DMS.obi_atexit()
|
DMS.obi_atexit()
|
||||||
|
|
||||||
|
# Open the input
|
||||||
input = open_uri(config['obi']['inputURI'])
|
input = open_uri(config['obi']['inputURI'])
|
||||||
|
if input is None:
|
||||||
|
raise Exception("Could not read input")
|
||||||
|
iview = input[1]
|
||||||
|
|
||||||
entries = input[1]
|
process = Popen(["less"], stdin=PIPE)
|
||||||
|
|
||||||
if config['less']['print'] > len(entries) :
|
for seq in iview :
|
||||||
n = len(entries)
|
PyErr_CheckSignals()
|
||||||
else :
|
try:
|
||||||
n = config['less']['print']
|
process.stdin.write(tobytes(repr(seq)))
|
||||||
|
process.stdin.write(b"\n")
|
||||||
|
except (StopIteration, BrokenPipeError, IOError):
|
||||||
|
break
|
||||||
|
|
||||||
# Print
|
sys.stderr.close()
|
||||||
for i in range(n) :
|
process.stdin.close()
|
||||||
print(repr(entries[i]))
|
process.wait()
|
||||||
|
|
||||||
|
iview.close()
|
||||||
|
input[0].close()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user