def Main(argv):
    argparser = argparse.ArgumentParser(description='Processes a logfile previously generated by the ac2git.py script for restore points and optionally restores the state of a git repository to a selected point. Only works for the transactions method conversions.')
    argparser.add_argument('-f', '--file', dest='file', help='The log file from which the state information will be parsed.')
    argparser.add_argument('-t', '--transaction', dest='transaction', help='The transaction, from the log file, to which the state will be restored to. If omitted then all potential restore points are printed and the script exits with a return code of 1.')
    argparser.add_argument('-r', '--git-repo', dest='repo', help='The path to the git repository whose state will be restored.')
    args = argparser.parse_args()
    if (not os.path.exists(args.file)):
        print("Failed to open log file '{f}'.".format(f=args.file))
        return 1
    trList = []
    with codecs.open(args.file) as f:
        line = f.readline()
        while (len(line) > 0):
            line = line.strip()
            tr = GetTransaction(line)
            if (tr is not None):
                branchList = []
                line = f.readline()
                while (len(line) > 0):
                    line = line.strip()
                    br = GetBranch(line)
                    if (br is not None):
                        branchList.append(br)
                    else:
                        break
                    line = f.readline()
                if ((args.transaction is not None) and (int(tr) == int(args.transaction))):
                    return Restore(args.repo, branchList, int(args.transaction))
                elif (tr not in trList):
                    trList.append(tr)
                    print('Found transaction {tr}.'.format(tr=tr))
            line = f.readline()
    if (len(trList) > 0):
        print('Please choose one of the transactions listed above to restore the state to and re-run the script with the -t option.')
        return 0
    else:
        print("Found no usable transaction state information in the log file '{f}'".format(f=args.file))
    return 1
def Main(argv):
    argparser = argparse.ArgumentParser(description='Processes a logfile previously generated by the ac2git.py script for restore points and optionally restores the state of a git repository to a selected point. Only works for the transactions method conversions.')
    argparser.add_argument('-f', '--file', dest='file', help='The log file from which the state information will be parsed.')
    argparser.add_argument('-t', '--transaction', dest='transaction', help='The transaction, from the log file, to which the state will be restored to. If omitted then all potential restore points are printed and the script exits with a return code of 1.')
    argparser.add_argument('-r', '--git-repo', dest='repo', help='The path to the git repository whose state will be restored.')
    args = argparser.parse_args()
    if (not os.path.exists(args.file)):
        print("Failed to open log file '{f}'.".format(f=args.file))
        return 1
    trList = []
    with codecs.open(args.file) as f:
        line = f.readline()
        while (len(line) > 0):
            line = line.strip()
            tr = GetTransaction(line)
            if (tr is not None):
                branchList = []
                line = f.readline()
                while (len(line) > 0):
                    line = line.strip()
                    br = GetBranch(line)
                    if (br is not None):
                        branchList.append(br)
                    else:
                        break
                    line = f.readline()
                if ((args.transaction is not None) and (int(tr) == int(args.transaction))):
                    return Restore(args.repo, branchList, int(args.transaction))
                elif (tr not in trList):
                    trList.append(tr)
                    print('Found transaction {tr}.'.format(tr=tr))
            line = f.readline()
    if (len(trList) > 0):
        print('Please choose one of the transactions listed above to restore the state to and re-run the script with the -t option.')
        return 0
    else:
        print("Found no usable transaction state information in the log file '{f}'".format(f=args.file))
    return 1