<s> import sys , os , traceback , time <EOL> import arcpy <EOL> class LicenseError ( Exception ) : <EOL> pass <EOL> def uploadServiceDefinition ( sdFilePath , agsPubConnectionFile , startService = True ) : <EOL> success = True <EOL> pymsg = "<STR_LIT>" <EOL> try : <EOL> if startService : <EOL> startService = "<STR_LIT>" <EOL> else : <EOL> startService = "<STR_LIT>" <EOL> arcpy . UploadServiceDefinition_server ( sdFilePath , agsPubConnectionFile , in_startupType = startService , in_cluster = '<STR_LIT:default>' ) <EOL> except : <EOL> success = False <EOL> pymsg = "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> return [ success , pymsg ] <EOL> def copyData ( sourcePath , destinationPath , dataType = "<STR_LIT>" ) : <EOL> success = True <EOL> pymsg = "<STR_LIT>" <EOL> try : <EOL> if arcpy . Exists ( destinationPath ) : <EOL> print "<STR_LIT>" + destinationPath <EOL> print "<STR_LIT>" <EOL> else : <EOL> arcpy . Copy_management ( sourcePath , destinationPath ) <EOL> except : <EOL> success = False <EOL> pymsg = "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> return [ success , pymsg ] <EOL> def copyGDBData ( sourceGDBPath , destinationGDBPath ) : <EOL> success = True <EOL> pymsg = "<STR_LIT>" <EOL> printMsg = True <EOL> debug = False <EOL> try : <EOL> print '<STR_LIT>' . format ( "<STR_LIT>" , sourceGDBPath ) <EOL> print '<STR_LIT>' . format ( "<STR_LIT>" , destinationGDBPath ) <EOL> print "<STR_LIT>" <EOL> if arcpy . CheckExtension ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> arcpy . CheckOutExtension ( "<STR_LIT>" ) <EOL> else : <EOL> raise LicenseError <EOL> descGDB = arcpy . Describe ( sourceGDBPath ) <EOL> if debug : <EOL> if hasattr ( descGDB , "<STR_LIT:name>" ) : <EOL> print "<STR_LIT>" + descGDB . name <EOL> if hasattr ( descGDB , "<STR_LIT>" ) : <EOL> print "<STR_LIT>" + descGDB . dataType <EOL> if hasattr ( descGDB , "<STR_LIT>" ) : <EOL> print "<STR_LIT>" + descGDB . catalogPath <EOL> datasets = [ ] <EOL> copyExcludeList = [ ] <EOL> for child in descGDB . children : <EOL> if child . dataType != "<STR_LIT>" : <EOL> datasets . append ( child . name ) <EOL> else : <EOL> descRel = arcpy . Describe ( sourceGDBPath + "<STR_LIT:/>" + child . name ) <EOL> for destClassName in descRel . destinationClassNames : <EOL> copyExcludeList . append ( destClassName ) <EOL> copyList = [ dataset for dataset in datasets if dataset not in copyExcludeList ] <EOL> if debug : <EOL> print "<STR_LIT>" <EOL> print datasets <EOL> print "<STR_LIT>" <EOL> print copyExcludeList <EOL> print "<STR_LIT>" <EOL> print copyList <EOL> if len ( copyList ) > <NUM_LIT:0> : <EOL> n = <NUM_LIT:1> <EOL> print "<STR_LIT>" <EOL> for dataset in copyList : <EOL> srcPath = os . path . join ( sourceGDBPath , dataset ) <EOL> destPath = os . path . join ( destinationGDBPath , dataset ) <EOL> print "<STR_LIT>" . format ( dataset , n , len ( copyList ) ) <EOL> if arcpy . Exists ( destPath ) : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" + destPath <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> results = copyData ( srcPath , destPath ) <EOL> copySuccess = checkResults ( results , printMsg ) <EOL> if not copySuccess : <EOL> success = False <EOL> n = n + <NUM_LIT:1> <EOL> else : <EOL> print "<STR_LIT>" <EOL> except LicenseError : <EOL> success = False <EOL> print "<STR_LIT>" <EOL> except : <EOL> success = False <EOL> pymsg = "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> arcpy . CheckInExtension ( "<STR_LIT>" ) <EOL> return [ success , pymsg ] <EOL> def checkResults ( results , printMsg ) : <EOL> success = results [ <NUM_LIT:0> ] <EOL> if printMsg : <EOL> if success : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print results [ <NUM_LIT:1> ] <EOL> print "<STR_LIT>" <EOL> print <EOL> return success <EOL> def repairMosaicDatasetPaths ( mosaicDatasetPath , pathsList ) : <EOL> success = True <EOL> pymsg = "<STR_LIT>" <EOL> try : <EOL> arcpy . RepairMosaicDatasetPaths_management ( mosaicDatasetPath , pathsList ) <EOL> except : <EOL> success = False <EOL> pymsg = "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> return [ success , pymsg ] <EOL> def createAGSConnectionFile ( agsConnFolderPath , agsConnFile , serverName , <EOL> userName , passWord , port = <NUM_LIT> , useSSL = False , <EOL> connectionType = "<STR_LIT>" , <EOL> serverType = "<STR_LIT>" , <EOL> saveUserNamePassWord = "<STR_LIT>" ) : <EOL> success = True <EOL> pymsg = "<STR_LIT>" <EOL> try : <EOL> agsConnFilePath = agsConnFolderPath + os . sep + agsConnFile <EOL> if os . path . exists ( agsConnFilePath ) : <EOL> os . remove ( agsConnFilePath ) <EOL> if useSSL : <EOL> targetAGSURL = "<STR_LIT>" <EOL> else : <EOL> targetAGSURL = "<STR_LIT:http>" <EOL> targetAGSURL = "<STR_LIT>" . format ( targetAGSURL , serverName ) <EOL> if port : <EOL> targetAGSURL = "<STR_LIT>" . format ( targetAGSURL , port ) <EOL> targetAGSURL = "<STR_LIT>" . format ( targetAGSURL ) <EOL> arcpy . mapping . CreateGISServerConnectionFile ( <EOL> connectionType , agsConnFolderPath , agsConnFile , <EOL> targetAGSURL , serverType , True , None , userName , passWord , <EOL> saveUserNamePassWord ) <EOL> except : <EOL> success = False <EOL> pymsg = "<STR_LIT>" + str ( sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> return [ success , pymsg ] </s>
