#!/usr/bin/env python2
#
# Copyright (C) 2012-2017 Chris Cummins.
#
# This file is part of emu.
#
# Emu is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# Emu is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with emu.  If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function

import re
import sys
import os

from emu import *


def main(argv, argc):
    parser = Parser()
    parser.add_option("--dont-cache", action="store_true", dest="dont_cache",
                      default=False)
    parser.add_option("--use-cached", action="store_true", dest="use_cached",
                      default=False)
    (options, args) = parser.parse_args()

    snapshots = parser.parse_snapshots(Source(options.source_dir))
    status = 0

    if not len(snapshots):
        print("No snapshots to verify!")
        status = 1

    for snapshot in snapshots:
        if snapshot.verify(cache_results=not options.dont_cache,
                           use_cached=options.use_cached):
            print(snapshot, colourise("ok", Colours.OK))
        else:
            status = 2
            print(snapshot, colourise("bad", Colours.ERROR))

    return status


if __name__ == "__main__":
    argv = sys.argv[1:]
    ret = main(argv, len(argv))
    sys.exit(ret)
