Tuesday 5 June 2012

Daily_UpdateBacklog.au3

Task reminders in morning or evening don't really work. Especially when quite busy last thing and opening explorer, locking a file, opening excel takes a few minutes. So. Automate the open folder, get svn lock and open file part and pop all up as a reminder. Hudson daily task and AutoIt script.

Prompt user, svn update, get lock, open .xls file, commit and release lock (or timeout and release lock) handle lock fail or user not present run from Hudson or other regular cron tool.



;http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-automation.html
;http://www.autoitscript.com/autoit3/docs/libfunctions/_IECreate.htm
;http://stackoverflow.com/questions/9667957/automation-of-right-clicking-of-file-in-windows-explorer


#include <GUIListView.au3>
#include  <Excel.au3>

$Title = "UPDATE BACKLOG"
$Path = "C:\SVN\DocsPlanning\XXX\"
$File = "C:\SVN\DocsPlanning\XXX\Sprint36.xls"

$TortoisePath = "c:\Program Files\TortoiseSVN\bin\TortoiseProc.exe"
;http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-automation.html
; TODO: change all to /closeonend:1 when all are working
;/closeonend:1 auto close if no errors

Local $iSvnPid = Run($TortoisePath & " /closeonend:1 /command:update /path:" & $Path)
ProcessWaitClose($iSvnPid)
$x = MsgBox(0,$Title & ": svn update done","svnpid:"&$iSvnPid&"\nsvn update done",5)

;http://www.autoitscript.com/autoit3/docs/libfunctions/_IECreate.htm
;#include
;Local $oIE = _IECreate("www.autoitscript.com")

$x = MsgBox(33,$Title & ": Try and Lock Backlog?",$File&"\nTry and Lock Backlog?",1800)
;$x = MsgBox(0,$Title & ": Debug","Debug answer = " & $x,900)
; $x = 1 okay $x = 2 cancel

If $x = 1 Then
  ;Hmpfh. the lock command doesn't take logmsg
  Local $iSvnPid = Run($TortoisePath & " /closeonend:0 /command:lock /logmsg:""update jco integration tasks"" /path:" & $File)
  ProcessWaitClose($iSvnPid)
  $x1 = MsgBox(33,$Title & ": Locked?",$File&"\nDid you lock it?")

  ;http://stackoverflow.com/questions/9667957/automation-of-right-clicking-of-file-in-windows-explorer
  ;Local $hList = ControlGetHandle("[CLASS:CabinetWClass]", "", "[CLASS:SysListView32; INSTANCE:1]")
  ;Local $aClient = WinGetPos($hList)
  ;Local $aPos = _GUICtrlListView_GetItemPosition($hList, _GUICtrlListView_GetSelectedIndices($hList))
  ;MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4)
  
  ;MouseClick("Right", "Optical_SW_Sprint_36.xls")

  If $x1 = 1 Then

    ;pull up explorer window for commit or if there is trouble
    Local $iPid = Run("C:\WINDOWS\EXPLORER.EXE /n,/e," & $Path)
    ProcessWait($iPid)
    MsgBox(0,$Title & ": EXPLORER","pid:"&$iPid,5)
    Sleep(3000)
  
    $excel_file = _ExcelBookOpen($File)

    $x2 = MsgBox(33,$Title & ": Commit and unlock Backlog","Now edit backlog.\nWhen finished commit and unlock Backlog.\nFinished?\n")

    If $x2 = 1 Then
      ; commit and release lock
      Local $iSvnPid = Run($TortoisePath & " /closeonend:0 /command:commit /logmsg:""update jco integration tasks"" /path:" & $File)
      ProcessWait($iSvnPid)
    EndIf
   
  EndIf

  ; unlock in case the commit didn't unlock
  Sleep(30000)
  Local $iSvnPid = Run($TortoisePath & " /closeonend:1 /command:unlock /path:" & $File)
  ProcessWait($iSvnPid)

  ; close explorer
  ProcessClose($iPid)

EndIf

Exit