obi less: now actually behaves like less
This commit is contained in:
@ -1,9 +1,17 @@
|
||||
#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.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"
|
||||
|
||||
@ -12,33 +20,31 @@ def addOptions(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):
|
||||
|
||||
cdef object entries
|
||||
cdef int n
|
||||
|
||||
DMS.obi_atexit()
|
||||
|
||||
# Open the input
|
||||
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) :
|
||||
n = len(entries)
|
||||
else :
|
||||
n = config['less']['print']
|
||||
for seq in iview :
|
||||
PyErr_CheckSignals()
|
||||
try:
|
||||
process.stdin.write(tobytes(repr(seq)))
|
||||
process.stdin.write(b"\n")
|
||||
except (StopIteration, BrokenPipeError, IOError):
|
||||
break
|
||||
|
||||
# Print
|
||||
for i in range(n) :
|
||||
print(repr(entries[i]))
|
||||
sys.stderr.close()
|
||||
process.stdin.close()
|
||||
process.wait()
|
||||
|
||||
iview.close()
|
||||
input[0].close()
|
||||
|
||||
|
Reference in New Issue
Block a user