# Path: lib/loghelper.py
# class Logger():
#     """
#     Think of this class like a light interface
#     """
# 
#     def __init__(self, method=""):
#         self.instance = _LoggerSingleton()
#         self.method = method
# 
#     def setup(self, **kwargs):
#         self.instance.setup(**kwargs)
# 
#     def print_(self, message, **kwargs):
#         self.instance.logprint(message, **kwargs)
# 
#     def debug(self, *args):
#         """
#         This works a little differently. You can basically throw anything you want into it.
#         :param message:
#         :return:
#         """
#         msgarr =  []
#         for arg in args:
#             if type(arg) is str:
#                 msgarr.append(arg)
#             else:
#                 msgarr.append(pformat(arg))
#         finalmessage = '\n'.join(msgarr).replace('\n', '\n              ')
#         self.instance.logprint(finalmessage, self.method, "debug")
# 
#     def destroy(self):
#         self.instance = None
#         self.method = None
# 
#     def info(self, message):
#         self.instance.logprint(message, self.method, "info")
# 
#     def error(self, message, exception=None):
#         self.instance.logprint(message, self.method, "error", exception)
# 
#     def warning(self, message, exception=None):
#         self.instance.logprint(message, self.method, "warning", exception)
# 
# Path: lib/sitkaAPI.py
# def downloadUnzipTopo(visitID, unzipPath):
#     """
#     Download a topo zip file to a local path using a visitID
#     :param visitID:
#     :param zipFilePath:
#     :return:
#     """
#     tokenator = Tokenator()
#     log = Logger("downloadTopoZip")
# 
#     # First find the appropriate download URL
#     try:
#         topoFieldFolders = APIGet('visits/{}/fieldFolders/Topo'.format(visitID))
# 
#         log.debug("Getting visit file data")
#         file = next(file for file in topoFieldFolders['files'] if file['componentTypeID'] == 181)
#         downloadUrl = file['downloadUrl']
#     except Exception, e:
#         raise MissingException("ERROR: No TopoData.zip file found for visit".format(visitID))
# 
#     # Download the file to a temporary location
#     with NamedTemporaryFile() as f:
#         response = APIGet(downloadUrl, absolute=True)
#         f.write(response.content)
# 
#         log.debug("Downloaded file: {} to: {}".format(downloadUrl, f.name))
# 
#         # Now we have it. Unzip
#         with zipfile.ZipFile(f, 'r') as zip_ref:
#             log.debug("Unzipping file: {} to: {}".format(f.name, unzipPath))
#             zip_ref.extractall(unzipPath)
# 
#         # Return a folder where we can find a project.rs.xml (or not)
#         projpath = None
#         for root, subFolders, files in os.walk(unzipPath):
#             if "project.rs.xml" in files:
#                 projpath = root
# 
#     return file, projpath
# 
# Path: lib/exception.py
# class DataException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(DataException, self).__init__(message)
#         self.returncode = 2
#         logg = Logger('DataException')
#         logg.error(message)
# 
# class MissingException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(MissingException, self).__init__(message)
#         self.returncode = 4
# 
#         logg = Logger('MissingException')
#         logg.error(message)
# 
# class NetworkException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(NetworkException, self).__init__(message)
#         self.returncode = 3
# 
#         logg = Logger('NetworkException')
#         logg.error(message)


import sys
import os
import lib.env
import argparse
import traceback
from lib.loghelper import Logger
from lib.sitkaAPI import downloadUnzipTopo
from writetoxml import writeMetricsToXML
from lib.exception import DataException, MissingException, NetworkException
from champ_survey import CHaMPSurvey
    if len(validationResults) == 0:
        log.error("No layers found to validate")
        stats["errors"] += 1
        stats["status"] = Status.FAIL
        returnValue = 2

    # The last message is what gets picked up so let's be clever:
    if returnValue == 2:
        log.error("Validation Failed")
    else:
        log.error("Validation Passed")

    writeMetricsToXML(validationResults, stats, xmlfile)

    return returnValue


def main():
    # parse command line options
    parser = argparse.ArgumentParser()
    parser.add_argument('visitID', help='Visit ID', type=int)
    parser.add_argument('outputfolder', help='Path to output folder', type=str)
    parser.add_argument('--datafolder', help='(optional) Top level folder containing TopoMetrics Riverscapes projects', type=str)
    parser.add_argument('--verbose', help='Get more information in your logs.', action='store_true', default=False )
    args = parser.parse_args()

    # Make sure the output folder exists
    resultsFolder = os.path.join(args.outputfolder, "outputs")

    # Initiate the log file

# Path: lib/loghelper.py
# class Logger():
#     """
#     Think of this class like a light interface
#     """
# 
#     def __init__(self, method=""):
#         self.instance = _LoggerSingleton()
#         self.method = method
# 
#     def setup(self, **kwargs):
#         self.instance.setup(**kwargs)
# 
#     def print_(self, message, **kwargs):
#         self.instance.logprint(message, **kwargs)
# 
#     def debug(self, *args):
#         """
#         This works a little differently. You can basically throw anything you want into it.
#         :param message:
#         :return:
#         """
#         msgarr =  []
#         for arg in args:
#             if type(arg) is str:
#                 msgarr.append(arg)
#             else:
#                 msgarr.append(pformat(arg))
#         finalmessage = '\n'.join(msgarr).replace('\n', '\n              ')
#         self.instance.logprint(finalmessage, self.method, "debug")
# 
#     def destroy(self):
#         self.instance = None
#         self.method = None
# 
#     def info(self, message):
#         self.instance.logprint(message, self.method, "info")
# 
#     def error(self, message, exception=None):
#         self.instance.logprint(message, self.method, "error", exception)
# 
#     def warning(self, message, exception=None):
#         self.instance.logprint(message, self.method, "warning", exception)
# 
# Path: lib/sitkaAPI.py
# def downloadUnzipTopo(visitID, unzipPath):
#     """
#     Download a topo zip file to a local path using a visitID
#     :param visitID:
#     :param zipFilePath:
#     :return:
#     """
#     tokenator = Tokenator()
#     log = Logger("downloadTopoZip")
# 
#     # First find the appropriate download URL
#     try:
#         topoFieldFolders = APIGet('visits/{}/fieldFolders/Topo'.format(visitID))
# 
#         log.debug("Getting visit file data")
#         file = next(file for file in topoFieldFolders['files'] if file['componentTypeID'] == 181)
#         downloadUrl = file['downloadUrl']
#     except Exception, e:
#         raise MissingException("ERROR: No TopoData.zip file found for visit".format(visitID))
# 
#     # Download the file to a temporary location
#     with NamedTemporaryFile() as f:
#         response = APIGet(downloadUrl, absolute=True)
#         f.write(response.content)
# 
#         log.debug("Downloaded file: {} to: {}".format(downloadUrl, f.name))
# 
#         # Now we have it. Unzip
#         with zipfile.ZipFile(f, 'r') as zip_ref:
#             log.debug("Unzipping file: {} to: {}".format(f.name, unzipPath))
#             zip_ref.extractall(unzipPath)
# 
#         # Return a folder where we can find a project.rs.xml (or not)
#         projpath = None
#         for root, subFolders, files in os.walk(unzipPath):
#             if "project.rs.xml" in files:
#                 projpath = root
# 
#     return file, projpath
# 
# Path: lib/exception.py
# class DataException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(DataException, self).__init__(message)
#         self.returncode = 2
#         logg = Logger('DataException')
#         logg.error(message)
# 
# class MissingException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(MissingException, self).__init__(message)
#         self.returncode = 4
# 
#         logg = Logger('MissingException')
#         logg.error(message)
# 
# class NetworkException(Exception):
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(NetworkException, self).__init__(message)
#         self.returncode = 3
# 
#         logg = Logger('NetworkException')
#         logg.error(message)


# Path: tools/validation/validation.py
import sys
import os
import lib.env
import argparse
import traceback
from lib.loghelper import Logger
from lib.sitkaAPI import downloadUnzipTopo
from writetoxml import writeMetricsToXML
from lib.exception import DataException, MissingException, NetworkException
from champ_survey import CHaMPSurvey

    if len(validationResults) == 0:
        log.error("No layers found to validate")
        stats["errors"] += 1
        stats["status"] = Status.FAIL
        returnValue = 2

    # The last message is what gets picked up so let's be clever:
    if returnValue == 2:
        log.error("Validation Failed")
    else:
        log.error("Validation Passed")

    writeMetricsToXML(validationResults, stats, xmlfile)

    return returnValue


def main():
    # parse command line options
    parser = argparse.ArgumentParser()
    parser.add_argument('visitID', help='Visit ID', type=int)
    parser.add_argument('outputfolder', help='Path to output folder', type=str)
    parser.add_argument('--datafolder', help='(optional) Top level folder containing TopoMetrics Riverscapes projects', type=str)
    parser.add_argument('--verbose', help='Get more information in your logs.', action='store_true', default=False )
    args = parser.parse_args()

    # Make sure the output folder exists
    resultsFolder = os.path.join(args.outputfolder, "outputs")

    # Initiate the log file

    logg = Logger("Program")