#!/usr/bin/python3

from __future__ import print_function

import getopt,sys
import gratia.common.GratiaCore as GratiaCore
import gratia.common.bundle as bundle
import gratia.common.utils as utils
import gratia.common.probe_details as probe_details

class UsageError(Exception):
    def __init__(self, msg):
        self.msg = msg

def Usage():
        print(" Usage: "+sys.argv[0]+" [-v] [--verbose]")
        print()
        print("   -v, --verbose: print the result in human readable form")
        print()
        print(" This will attempt to upload a handshake to the server")

if __name__ == '__main__':
        verbose = False;
        argv = sys.argv
        try:
                try:
                        opts, args = getopt.getopt(argv[1:], "hv", ["help","verbose"])
                except getopt.error as msg:
                        raise UsageError(msg)
        except UsageError as err:
                print(err.msg, file=sys.stderr)
                print("for help use --help", file=sys.stderr)
                sys.exit(2)
        for o, a in opts:
                if o in ("-v","--verbose"):
                        verbose = True;
                if o in ("-h","--help"):
                        Usage()
                        sys.exit(0)

        probe_details.RegisterReporter("GratiaPing.py")

        GratiaCore.Initialize()

        if (verbose):
                print("Number of successful handshakes: "+str(bundle.successfulHandshakes))
        sys.exit(0==bundle.successfulHandshakes)

