Beispiel #1
0
def main(args):
    import sys

    filename = args["<hwp5file>"]
    if filename:
        from hwp5.binmodel import Hwp5File
        from hwp5.proc import parse_recordstream_name

        streamname = args["<record-stream>"]
        hwpfile = Hwp5File(filename)
        stream = parse_recordstream_name(hwpfile, streamname)
    else:
        version = args["--formatversion"] or "5.0.0.0"
        version = version.split(".")
        version = tuple(int(x) for x in version)

        from hwp5.storage import Open2Stream
        from hwp5.binmodel import ModelStream

        stream = ModelStream(Open2Stream(lambda: sys.stdin), version)

    opts = dict()

    treegroup = args["--treegroup"]
    if treegroup is not None:
        opts["treegroup"] = int(treegroup)

    if args["--simple"]:
        for model in stream.models(**opts):
            print "%04d" % model["seqno"],
            print " " * model["level"] + model["type"].__name__
    else:
        stream.models_json(**opts).dump(sys.stdout)
Beispiel #2
0
def stream_from_args(args):
    filename = args['<hwp5file>']
    if filename:
        from hwp5.binmodel import Hwp5File
        from hwp5.proc import parse_recordstream_name
        streamname = args['<record-stream>']
        hwpfile = Hwp5File(filename)
        return parse_recordstream_name(hwpfile, streamname)
    else:
        version = args['--file-format-version'] or '5.0.0.0'
        version = version.split('.')
        version = tuple(int(x) for x in version)

        from hwp5.storage import Open2Stream
        from hwp5.binmodel import ModelStream
        return ModelStream(Open2Stream(lambda: sys.stdin), version)
Beispiel #3
0
def stream_from_args(args):
    filename = args['<hwp5file>']
    if filename:
        from hwp5.binmodel import Hwp5File
        from hwp5.proc import parse_recordstream_name
        streamname = args['<record-stream>']
        hwpfile = Hwp5File(filename)
        return parse_recordstream_name(hwpfile, streamname)
    else:
        version = args['--file-format-version'] or '5.0.0.0'
        version = version.split('.')
        version = tuple(int(x) for x in version)

        from hwp5.storage import Open2Stream
        from hwp5.binmodel import ModelStream
        return ModelStream(Open2Stream(lambda: sys.stdin), version)
Beispiel #4
0
def main(args):
    import sys
    filename = args['<hwp5file>']
    if filename:
        from hwp5.recordstream import Hwp5File
        from hwp5.proc import parse_recordstream_name
        hwpfile = Hwp5File(filename)
        streamname = args['<record-stream>']
        stream = parse_recordstream_name(hwpfile, streamname)
    else:
        from hwp5.storage import Open2Stream
        from hwp5.recordstream import RecordStream
        stream = RecordStream(Open2Stream(lambda: sys.stdin), None)

    opts = dict()
    rng = args['--range']
    if rng:
        rng = rng.split('-', 1)
        rng = tuple(int(x) for x in rng)
        if len(rng) == 1:
            rng = (rng[0], rng[0] + 1)
        opts['range'] = rng
    treegroup = args['--treegroup']
    if treegroup is not None:
        opts['treegroup'] = int(treegroup)

    if args['--simple']:
        for record in stream.records(**opts):
            print '%04d' % record['seqno'],
            print '  ' * record['level'], record['tagname']
    elif args['--raw']:
        from hwp5.recordstream import dump_record
        for record in stream.records(**opts):
            dump_record(sys.stdout, record)
    elif args['--raw-header']:
        from hwp5.recordstream import encode_record_header
        for record in stream.records(**opts):
            hdr = encode_record_header(record)
            sys.stdout.write(hdr)
    elif args['--raw-payload']:
        for record in stream.records(**opts):
            sys.stdout.write(record['payload'])
    else:
        stream.records_json(**opts).dump(sys.stdout)