<s> '''<STR_LIT>''' <EOL> import arcpy <EOL> import os <EOL> import sys <EOL> import traceback <EOL> import platform <EOL> import logging <EOL> import Configuration <EOL> import datetime <EOL> def getLoggerName ( ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : <EOL> print ( "<STR_LIT>" ) <EOL> seq = <NUM_LIT:0> <EOL> name = nameFromDate ( seq ) <EOL> while os . path . exists ( os . path . join ( Configuration . logPath , name ) ) : <EOL> seq += <NUM_LIT:1> <EOL> name = nameFromDate ( seq ) <EOL> return name <EOL> def getCurrentDateTimeForLogFile ( ) : <EOL> '''<STR_LIT>''' <EOL> return datetime . datetime . now ( ) . strftime ( "<STR_LIT>" ) <EOL> def getCurrentDateTime ( ) : <EOL> '''<STR_LIT>''' <EOL> return datetime . datetime . now ( ) . strftime ( "<STR_LIT>" ) <EOL> def nameFromDate ( seq ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' + str ( getCurrentDateTimeForLogFile ( ) ) + '<STR_LIT>' + str ( seq ) + '<STR_LIT>' <EOL> def makeFileFromPath ( filePath ) : <EOL> '''<STR_LIT>''' <EOL> if not checkExists ( filePath ) : <EOL> try : <EOL> fd = open ( filePath , '<STR_LIT:a>' ) <EOL> fd . close ( ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> return filePath <EOL> def makeFolderFromPath ( folderPath ) : <EOL> '''<STR_LIT>''' <EOL> if not checkExists ( folderPath ) : <EOL> try : <EOL> os . makedirs ( folderPath ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> return folderPath <EOL> def initializeLogger ( name ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : <EOL> print ( "<STR_LIT>" ) <EOL> if not os . path . exists ( Configuration . logPath ) : <EOL> dummy = makeFolderFromPath ( Configuration . logPath ) <EOL> if name == None or name == "<STR_LIT>" : <EOL> name = getLoggerName ( ) <EOL> logFile = os . path . join ( Configuration . logPath , name ) <EOL> if not os . path . exists ( logFile ) : <EOL> logFile = makeFileFromPath ( logFile ) <EOL> logging . basicConfig ( format = '<STR_LIT>' , filename = logFile , level = logging . DEBUG ) <EOL> logger = logging . getLogger ( name ) <EOL> return logger <EOL> def setUpLogFileHeader ( ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : <EOL> print ( "<STR_LIT>" ) <EOL> Configuration . Logger . info ( "<STR_LIT>" ) <EOL> Configuration . Logger . info ( "<STR_LIT>" . format ( platform . platform ( ) ) ) <EOL> Configuration . Logger . info ( "<STR_LIT>" . format ( sys . version ) ) <EOL> d = arcpy . GetInstallInfo ( ) <EOL> Configuration . Logger . info ( "<STR_LIT>" . format ( d [ '<STR_LIT>' ] , d [ '<STR_LIT>' ] , d [ '<STR_LIT>' ] ) ) <EOL> Configuration . Logger . info ( "<STR_LIT>" ) <EOL> def checkArcPy ( ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> arcpy . AddMessage ( "<STR_LIT>" ) <EOL> def checkExists ( p ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> return os . path . exists ( p ) <EOL> def createScratch ( scratchPath ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> scratchName = '<STR_LIT>' <EOL> scratchGDB = os . path . join ( scratchPath , scratchName ) <EOL> if checkExists ( scratchGDB ) : <EOL> print ( "<STR_LIT>" ) <EOL> return scratchGDB <EOL> try : <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> arcpy . CreateFileGDB_management ( scratchPath , scratchName ) <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> return scratchGDB <EOL> def deleteScratch ( scratchPath ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> try : <EOL> arcpy . Delete_management ( scratchPath ) <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> def checkFilePaths ( paths ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> for path2check in paths : <EOL> if os . path . exists ( path2check ) : <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" + path2check ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' + str ( path2check ) ) <EOL> def checkGeoObjects ( objects ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> for object2Check in objects : <EOL> desc = arcpy . Describe ( object2Check ) <EOL> if desc == None : <EOL> print ( "<STR_LIT>" + str ( object2Check ) ) <EOL> arcpy . AddError ( "<STR_LIT>" ) <EOL> raise Exception ( '<STR_LIT>' ) <EOL> else : <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" + desc . Name ) <EOL> def handleArcPyError ( ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> msgs = arcpy . GetMessages ( ) <EOL> arcpy . AddError ( msgs ) <EOL> print ( msgs ) <EOL> Configuration . Logger . error ( msgs ) <EOL> def handleGeneralError ( ) : <EOL> '''<STR_LIT>''' <EOL> if Configuration . DEBUG == True : print ( "<STR_LIT>" ) <EOL> tb = sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> tbinfo = traceback . format_tb ( tb ) [ <NUM_LIT:0> ] <EOL> pymsg = "<STR_LIT>" + tbinfo + "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> msgs = "<STR_LIT>" + arcpy . GetMessages ( ) + "<STR_LIT:\n>" <EOL> print ( pymsg + "<STR_LIT:\n>" ) <EOL> Configuration . Logger . error ( pymsg ) <EOL> print ( msgs ) <EOL> Configuration . Logger . error ( msgs ) <EOL> def geoObjectsExist ( objects ) : <EOL> '''<STR_LIT>''' <EOL> allExist = True <EOL> for obj in objects : <EOL> if not arcpy . Exists ( obj ) : <EOL> allExist = False <EOL> return allExist <EOL> def folderPathsExist ( paths ) : <EOL> '''<STR_LIT>''' <EOL> allExist = True <EOL> for p in paths : <EOL> if not os . path . exists ( p ) : <EOL> allExist = False <EOL> return allExist <EOL> def deleteIfExists ( dataset ) : <EOL> '''<STR_LIT>''' <EOL> if ( arcpy . Exists ( dataset ) ) : <EOL> arcpy . Delete_management ( dataset ) <EOL> arcpy . AddMessage ( "<STR_LIT>" + dataset ) </s>
