#-------------------------------------------------------------------------------
# Name: ULIMS Perfomance Management
# Purpose: Script scheduled in windows scheduler used to perfom enteprise geodatabase tuning
#
# Author: dmuthami
#
# Created: 17/03/2015
# Copyright: (c) dmuthami 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
import os, sys
import logging
import arcpy
import traceback
from arcpy import env
from datetime import datetime
def ulimsPerfomanceManagement():
#Set-up logging
logger = logging.getLogger('ulimsAutomation')
try:
#Export to text file#
currentDate = datetime.now().strftime("-%y-%m-%d_%H-%M-%S") # Current time
#Set-up some error logging code.
cat_logfile = os.path.join(os.path.dirname("__file__"), 'cat_logfile' + str(currentDate)+'.log')
#cat_logfile = r"C:\DAVID-MUTHAMI\GIS Data\Namibia ULIMS\Scripts" + "\\"+str(currentDate)+'.log'
hdlr = logging.FileHandler(cat_logfile)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
# Import the toolbox containing the model. This toolbox
# has an alias of "ulimsAutomation"
#Run model in a toolbox in a folder
# model optimizes enterprise geodatabase from SQL Server
#arcpy.ImportToolbox(r"C:\DAVID-MUTHAMI\GIS Data\Namibia ULIMS\Scripts\ULIMS_System.tbx","ulimsAutomation")
#Run model hosted on SQL Server enterprise GDB to optimize enterprise geodatabase
arcpy.ImportToolbox(r"Database Connections\sde@localhost@ulims_publication.sde","ulimsAutomation")
# Run the model.
#
arcpy.ULIMSPerformanceManagement_ulimsAutomation()
msg = "Performance tuning complete"
print msg
logger.info(msg)
except:
## Return any Python specific errors and any error returned by the geoprocessor
##
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\n ulimsPerfomanceManagement() Function : Traceback Info:\n" + tbinfo + "\nError Info:\n " + \
str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n" +\
"Line {0}".format(tb.tb_lineno)
msgs = "Geoprocessing Errors :\n" + arcpy.GetMessages(2) + "\n"
##Add custom informative message to the Python script tool
arcpy.AddError(pymsg) #Add error message to the Python script tool(Progress dialog box, Results windows and Python Window).
arcpy.AddError(msgs) #Add error message to the Python script tool(Progress dialog box, Results windows and Python Window).
##For debugging purposes only
##To be commented on python script scheduling in Windows _log
print pymsg
logger.info(pymsg)
print "\n" +msgs
logger.info(msgs)
def main():
pass
if __name__ == '__main__':
main()
#Run perfomance management module
ulimsPerfomanceManagement()