File: less.pyx

package info (click to toggle)
obitools 3.0.1~b26%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,756 kB
  • sloc: ansic: 24,299; python: 657; sh: 27; makefile: 21
file content (50 lines) | stat: -rwxr-xr-x 1,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#cython: language_level=3

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"


def addOptions(parser):
    
    addMinimalInputOption(parser)


def run(config):
        
    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]
    
    process = Popen(["less"], stdin=PIPE)
    
    for seq in iview :
        PyErr_CheckSignals()
        try:
            process.stdin.write(tobytes(repr(seq)))
            process.stdin.write(b"\n")
        except (StopIteration, BrokenPipeError, IOError):
            break

    sys.stderr.close()
    process.stdin.close()
    process.wait()

    iview.close()
    input[0].close(force=True)