#!/usr/bin/env python3
"""
remove_file_content: this script is used to process a file, excluding the portion of
the file between two patterns (and the patterns themselves. The new file contents
is printed to stdout, leaving the original file intact.
"""

import sys
import getopt

import central_dop.util

def usage ():
    print ("Usage: remove_file_content --start='start_pattern' --end='end_pattern' --file='filename'")

def main():

    if len (sys.argv) != 4:
        usage ()
        sys.exit (1)

    try:
        optlist, args = getopt.getopt(sys.argv[1:], "", ["start=", "end=", "file="])
    except getopt.GetoptError as err:
        print((str(err)))
        usage()
        sys.exit(2)

    start_patt = None
    end_patt = None
    file = None

    for o, a in optlist:
        if o == "--start":
            start_patt = a
        elif o == "--end":
            end_patt = a
        elif o == "--file":
            file = a
        else:
            usage()
            sys.exit(1)

    content = [line.rstrip('\n') for line in open(file)]

    for line in central_dop.util.strip_between_patterns(start_patt, end_patt, content):
        print(line)

if __name__ == "__main__":
    main()