'''
Name: esrd_replace_nulls_tool.py

Overview: 

Description:
    
Notes:

Author: 

Modifications:

'''


import os
import sys
import pdb

import arcpy

from srd.srd_exception import *
import srd.srd_logging as srd_logging
import srd.srd_misc as srd_misc

import avi_attribute_qc_testing

## Set to 1 if you wish to use the DEBUG mode arguments.
DEBUG = 0

logFilePath = srd_misc.getLogFilePath(sys.argv[0])
logChn = srd_logging.SRD_Log(logFilePath)
    
#====================================================================
if __name__ == '__main__':

    if DEBUG:
        # Modify arguments to simulate those passed from toolbox.
        # You will have to modify these based on your scripts requirements.

        ## NOTE MUST BE RUN FROM ArcCatalog or ArcMap or will fail
        sys.argv = [sys.argv[0],
                    r'D:\pythonscripts\rdiff_backup\data\backup\TOLKO_S19_AVI_INFILL',
                    r'D:\pythonscripts\rdiff_backup\data\restore\TOLKO_S19_AVI_INFILL',
                    '0'
                    ]
        
        print('\n***\n*** IN DEBUG MODE\n***')
        arcpy.AddMessage('\n***\n*** IN DEBUG MODE\n***')

    # Modify as required.
    arcpy.env.overwriteOutput = True
    # If using geographic features then may be best to modify these.
    arcpy.env.XYTolerance = .001
    arcpy.env.XYResolution = .0001
    arcpy.gp.logHistory = False
    
    try:

        ##==============================
        ## Modify parameters as needed.
        worksheetPathArg = arcpy.GetParameterAsText(0)
        worksheetArg = arcpy.GetParameterAsText(1)
            
        #-------------------------------------------------------------
        # Set the log file.
        if logFilePath:
            # Parameters to tool will be written to log file in case of problems.
            params = arcpy.GetParameterInfo()
            hdrList = ['Arguments:']
            for param in params:
                hdrList.append('Name: %s, Type: %s, Value: %s' % (param.name, param.parameterType, param.value))
            
            logChn.stampHeader(hdrList)
            arcpy.AddMessage('\n*** Log information will be written to: %s\n' % logFilePath)

        ##============================================================

            myObj = avi_attribute_qc_testing.AVI_AttributeTest()
            myObj.runAttQC(worksheetPathArg, worksheetArg)

        
        ##============================================================
        
    except SRD_Exception as e:
        logChn.logError(e)
        logChn.logError(srd_misc.exceptionDetails(sys.exc_info()[2]))
    except Exception as e:
        logChn.logError(e)
        logChn.logError(srd_misc.exceptionDetails(sys.exc_info()[2]))
    else:
        logChn.logMsg('\n*** %s completed normally\n' % sys.argv[0])
    finally:
        arcpy.ResetEnvironments()
