#!/usr/bin/env python2

##
# autosign
# https://github.com/leosartaj/autosign.git
# 
# copyright (c) 2014 sartaj singh
# licensed under the mit license.
##

import os
import re
import exce

"""
Main functions
"""

def getIndex(fName, options):
    """
    returns the start and end of a signature in a file
    returns None if no signature found
    """
    handler = open(fName)

    opt_start, opt_end, opt_line = options.start, options.end, options.line
    ls, le, ll = len(opt_start), len(opt_end), len(opt_line)

    start, end = None, None
    for index, line in enumerate(handler):
        if line[:ls] == opt_start and start == None:
            start = index
        elif line[:le] == opt_end and end == None:
            end = index
            break
        elif line[:ll] != opt_line and start != None:
            start, end = None, None
            break
    if start != None and end != None:
        return start, end
    return None, None

def isSign(fName, options):
    """
    Checks if a file is already signed
    """
    start, end = getIndex(fName, options)
    if start != None and end != None:
        return True
    return False

def checkRe(exp, line):