| 1 |
ninoborges |
8 |
## Commence_bkp_agent_repair.py
|
| 2 |
|
|
## This program will correct the the backup agent in commence by setting it to a J link instead of a UNC.
|
| 3 |
|
|
## This program will controll a autoIt script that will do the actuall work once this script determines
|
| 4 |
|
|
## that is is ready.
|
| 5 |
|
|
## EBorges
|
| 6 |
|
|
## 06.17.03
|
| 7 |
|
|
|
| 8 |
|
|
import win32gui, os, sys, tkMessageBox, string, time
|
| 9 |
|
|
|
| 10 |
|
|
global allAppsList
|
| 11 |
|
|
|
| 12 |
|
|
## Function: addToLogFile
|
| 13 |
|
|
## Purpose: Writes the string passed in to the designated log file
|
| 14 |
|
|
## Arguments: fileName - name of the log file
|
| 15 |
|
|
## logEntry - string to add to end of log file
|
| 16 |
|
|
## userSpecific - set to 1 if log file stored in the user's netchk dir, 0 if stored globally
|
| 17 |
|
|
## echo - set to 1 to also echo the logEntry string to stdout
|
| 18 |
|
|
def addToLogFile(fileName, logEntry, userSpecific=0, echo=0 ):
|
| 19 |
|
|
# User specific stuff was removed so that I wouldent have to import the Reg stuff. ;-)
|
| 20 |
|
|
# Since not user specific, use the global log directory
|
| 21 |
|
|
WinDir = os.getenv('SystemRoot')
|
| 22 |
|
|
WinDrive = string.split( WinDir, ':' )
|
| 23 |
|
|
logDir = WinDrive[0] + ':\\NetChk'
|
| 24 |
|
|
logFileName = logDir + '\\' + fileName
|
| 25 |
|
|
try:
|
| 26 |
|
|
logFile = open( logFileName, 'a' )
|
| 27 |
|
|
except IOError:
|
| 28 |
|
|
os.makedirs(logDir)
|
| 29 |
|
|
logFile = open( logFileName, 'a' )
|
| 30 |
|
|
logFile.write( time.strftime('%d/%m/%Y\t%H:%M:%S -\t',time.localtime()) + logEntry + '\n' )
|
| 31 |
|
|
if echo == 1: print logEntry
|
| 32 |
|
|
logFile.close()
|
| 33 |
|
|
|
| 34 |
|
|
def IsCommenceRunning():
|
| 35 |
|
|
win32gui.EnumWindows(GetAppsRunning, None)
|
| 36 |
|
|
for i in allAppsList:
|
| 37 |
|
|
exists = i.find('Commence/CLIENT')
|
| 38 |
|
|
if exists >-1:
|
| 39 |
|
|
break
|
| 40 |
|
|
#try:
|
| 41 |
|
|
#exists = allAppsList.index('Commence/CLIENT - Labor Database')
|
| 42 |
|
|
# exists = allAppsList.index('Commence/CLIENT')
|
| 43 |
|
|
#except:
|
| 44 |
|
|
# exists = 0
|
| 45 |
|
|
return exists
|
| 46 |
|
|
|
| 47 |
|
|
def GetAppsRunning(window, extra):
|
| 48 |
|
|
"""Gives a list of all windows curently running"""
|
| 49 |
|
|
title = win32gui.GetWindowText(window)
|
| 50 |
|
|
if title:
|
| 51 |
|
|
allAppsList.append(title)
|
| 52 |
|
|
|
| 53 |
|
|
if __name__ == '__main__':
|
| 54 |
|
|
allAppsList = []
|
| 55 |
|
|
netChkFile = "Commence_bkp_agent_repair.log"
|
| 56 |
|
|
addToLogFile(netChkFile,"Commence Backup agent repair started. Looking to see if Commence is open...")
|
| 57 |
|
|
welcomeMessage = """This program will repair the Commence backup agent by changing its UNC to a J: drive mapping.
|
| 58 |
|
|
Please close all programs EXCEPT Commence. Please have Commence minimized.\nClick OK to continue."""
|
| 59 |
|
|
runMain = tkMessageBox.askokcancel("Commence backup agent repair", welcomeMessage)
|
| 60 |
|
|
if runMain:
|
| 61 |
|
|
commenceRunning = IsCommenceRunning()
|
| 62 |
|
|
while commenceRunning == -1:
|
| 63 |
|
|
addToLogFile(netChkFile,"Commence is still not open. Reminding user to open it...")
|
| 64 |
|
|
allAppsList = []
|
| 65 |
|
|
runRetry = tkMessageBox.askretrycancel("Open Commence Please",
|
| 66 |
|
|
"Commence is not running! Please open Commence and minimize it. Then click RETRY")
|
| 67 |
|
|
if runRetry == 0:
|
| 68 |
|
|
sys.exit()
|
| 69 |
|
|
commenceRunning = IsCommenceRunning()
|
| 70 |
|
|
addToLogFile(netChkFile,"Commence is running! Starting script to change the UNC to a J: drive mapping...")
|
| 71 |
|
|
sucess = os.system('Backup_agent_fix.exe')
|
| 72 |
|
|
if sucess == 27:
|
| 73 |
|
|
addToLogFile(netChkFile,"The agent was changed successfully! Writing an entry in the LogFile directory that this user is all set...")
|
| 74 |
|
|
userName = os.environ['USERNAME']
|
| 75 |
|
|
machineName = os.environ['COMPUTERNAME']
|
| 76 |
|
|
if os.path.exists(r"Y:\log_files"):
|
| 77 |
|
|
w = open(r"Y:\log_files\Completed_Commence_agent_fixes.log",'a')
|
| 78 |
|
|
contents = "%s : %s\n" %(userName,machineName)
|
| 79 |
|
|
w.write(contents)
|
| 80 |
|
|
w.close()
|
| 81 |
|
|
addToLogFile(netChkFile,"File was written successfuly!")
|
| 82 |
|
|
else:
|
| 83 |
|
|
addToLogFile(netChkFile,"ERROR: The agent was not successful! It will need to be re-run.")
|