forked from camerb/AHKs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugAgain.ahk
379 lines (331 loc) · 11.9 KB
/
DebugAgain.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include FcnLib.ahk
#include thirdParty/CmdRet.ahk
fatalIfNotThisPc("PHOSPHORUS")
;{{{ Switch to random windows and bring them to debugging position
;WinMinimize, ahk_class gdkWindowToplevel
ForceWinFocusIfExist("ahk_class gdkWindowToplevel")
ForceWinFocusIfExist("BareTail")
;}}}
;{{{ Get all of our settings
ini:="gitExempt/global.ini"
A_Debug := IniRead(ini, A_ScriptName, "A_Debug")
suppressPageReload := IniRead(ini, A_ScriptName, "suppressPageReload")
dbicDebugMode := IniRead(ini, A_ScriptName, "dbicDebugMode")
epmsDebugMode := IniRead(ini, A_ScriptName, "epmsDebugMode")
;}}}
;{{{ Get all of the debugger commands from the file
;We'll execute the last command from the file
Loop, read, DebuggerCommands.txt
{
DebuggerCommand = %A_LoopReadLine%
}
;}}}
;{{{ Process aliases
if RegExMatch(DebuggerCommand, "i)EPMS.workbench")
DebuggerCommand=cmd 1: {C:\code\epms\script}, 2: {perl epms_workbench.pl}
;}}}
;{{{ Set some variables depending upon what mode we are in (project, refresh server, live/not)
;find out if we are in the mode to refresh the server
SysGet, MonitorCount, MonitorCount
refreshServerMode:=GetKeyState("ScrollLock", "T")=="D"
;if we're VPNing, we don't have access to the keyboard, so just always refresh the server
if (MonitorCount = 1)
refreshServerMode:=true
;DbicDebugMode:=true
;EpmsDebugMode:=true
;TODO make this so we can switch between :wa and :wa!
;force save in gvim
;if blah
;gvimForceSaveMode:=true
;find out if we're in live site mode
FileRead, filecontents, C:\code\bench\fl_bench.json
if InStr(filecontents, "argon")
LiveSiteMode:=true
FileRead, filecontents, C:\code\epms\cgi\epms_local.json
if InStr(filecontents, "prozac")
LiveSiteMode:=true
epmsTitles=Ellis Partners in Mystery Shopping|EPMS|Survey Detailed Reporting|Net Promoter Score|Personality Trait|Buying Stage|Zone of Success|Decision Driver|Customer Loyalty Score
;find out what project we're on
StringLeft, project, debuggerCommand, 2
StringLeft, firstFour, debuggerCommand, 4
if (firstFour == "cmd ")
{
suppressPageReload:=true
RegExMatch(debuggerCommand, "1: {(.*?)}", projDir)
RegExMatch(debuggerCommand, "2: {(.*?)}", projRun)
projDir:=RegExReplace(projDir, "(\d\: \{|\})", "")
projRun:=RegExReplace(projRun, "(\d\: \{|\})", "")
}
else if (firstFour == "perl")
{
suppressPageReload:=true
;projDir=cd C:\inetpub\EPMS-import\script\property_importers
projRun:=debuggerCommand
}
else if (project == "FL")
{
;suppressPageReload:=true
projTitle=American Bench
projDir=C:\code\bench
projRun=perl -MCarp::Always -I ..\Mitsi\perl\trunk\lib script\fl_bench_server.pl -d
projRun=perl -I ..\Mitsi\perl\trunk\lib script\fl_bench_server.pl -d
welcomeTabImage:="images\firebug\WelcomeTab.bmp"
}
else if (project == "TM")
{
projTitle=Slope Monitor Server
projDir=C:\code\deepcrow
projRun=perl -I ..\Mitsi\perl\trunk\lib script\tm_server.pl -d
welcomeTabImage:="images\firebug\WelcomeTabBlue.bmp"
}
else if (debuggerCommand == "EPMS")
{
apacheServer:=true
plackServer:=true
projTitle := epmsTitles
projDir=C:/code/epms/script
projRun=plackup psgi/dispatch.psgi -p 3001 -I"../App/lib"
;CmdRet_RunReturn("plackup psgi/dispatch.psgi -p 3001", "C:/code/epms/script")
}
else
{
debug("unrecognized command")
ExitApp
}
allWindow=Forms|Parts|Bench|Server|Home|xds|phosphorus|%epmsTitles%
ffWindow=(%projTitle%).* - Mozilla Firefox ahk_class MozillaWindowClass
ieWindow=(%projTitle%).* - Windows Internet Explorer ahk_class IEFrame
;}}}
;{{{ Live site mode warning
if LiveSiteMode
Run, LiveDbWarning.ahk
;}}}
;{{{ Copy the correct project config over
if LiveSiteMode
{
FileCopy, C:\code\bench\fl_bench.json.remote, C:\code\bench\fl_bench.json, 1
FileCopy, C:\code\epms\cgi\epms_LIVE.json, C:\code\epms\cgi\epms_local.json, 1
}
else
{
FileCopy, C:\code\bench\fl_bench.json.dev, C:\code\bench\fl_bench.json, 1
FileCopy, C:\code\epms\cgi\epms_mydev.json, C:\code\epms\cgi\epms_local.json, 1
}
;}}}
;{{{ Save files we were working with in Vim
if ForceWinFocusIfExist("\\(strawberry|code|(i|I)netpub).*GVIM ahk_class Vim", "RegEx")
{
;TODO flag for overwrite RO files in gvim
;SendInput, {Escape 6}{;}wa{!}{Enter}
SendInput, {Escape 6}{;}wa{Enter}
}
;}}}
;{{{ Restart the server, if desired
if refreshServerMode
{
if apacheServer
{
Run, "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe" -w -n "Apache2.2" -k restart
WinWaitActive, httpd.exe
WinMinimize, httpd.exe
WinWaitClose, httpd.exe
}
if plackServer
{
ForceWinFocusCmd()
ProcessCloseAll("perl.exe")
if ProcessExist("perl.exe")
errord("red line", "stupid perl process did not close!!! this means ProcessCloseAll() is broken", A_LineNumber, A_ScriptName)
Sleep, 100
FileAppendLine("grey line - restarted plack server", "C:/code/epms_logs/plack.log")
;CmdRet_RunReturn("plackup psgi/dispatch.psgi -p 3001 -I"../App/lib"", "C:/code/epms/script")
ForceWinFocusCmd()
SendInput, {esc}cls{ENTER}
SendInput, {esc}cd C:{ENTER}
SendInput, cd %projDir%{ENTER}
SendInput, %projRun%{ENTER}
ForceWinFocusIfExist("BareTail")
}
if NOT apacheServer and NOT plackServer
{
ForceWinFocusCmd()
SendInput, ^c
SendInput, ^c
SendInput, Y{ENTER}
dd:=WaitForImageSearch("images\cmd\Prompt(dir).bmp")
;dd:=WaitForImageSearch("images\cmd\Prompt(dir)lc.bmp")
if NOT dd
return
dd:=WaitForImageSearch("images\cmd\Prompt(arrow).bmp")
if NOT dd
return
SendInput, {esc}cls{ENTER}
SendInput, {esc}cd C:{ENTER}
if EpmsDebugMode
SendInput, set EPMS_UPTO=trace{ENTER}
else
SendInput, set EPMS_UPTO={ENTER}
SendInput, cd %projDir%{ENTER}
SendInput, %projRun%{ENTER}
dd:=WaitForImageSearch("images\cmd\PerlServerIsRunning.bmp")
if NOT dd
return ;TODO launch build error detection (to go through and find the word "syntax error" or whatever quickly
}
}
else
{
if (firstFour == "perl")
{
;perhaps this warning msg should be moved to the top, and it might be nice if it only runs in A_Debug mode
debug("um, guessing that you meant to have the scrolllock key down to refresh the server (since you're running a perl script)")
ExitApp
}
}
;}}}
;{{{ Save files in Ext Designer, if it's open
if ForceWinFocusIfExist("Ext Designer ahk_class QWidget", "Contains")
{
Send, ^s
Sleep, 100
Send, {ALT}
Sleep, 100
Send, a
Sleep, 100
Send, e
}
;}}}
;FIXME this entire section is so wrong...
;TODO need to change this section so that first we're figuring out what browser we're debugging with. Maybe this will suck because I'm using VirtuaWin and windows will exist, but it will be impossible to activate them. I had a feeling of that in the beginning, so that was why I decided to just use WinActivate. But it's a little bit annoying, having browser windows jump one in front of the other (I'd like to coin the term "ADHD-AHK").
SetTitleMatchMode, RegEx
;WinActivate, .*(%allWindow%).* - Google Chrome
WinActivate, .*(%allWindow%).* - Windows Internet Explorer ahk_class IEFrame
WinActivate, .*(%allWindow%|Problem loading page).* - Mozilla Firefox ahk_class MozillaWindowClass
IfWinActive, %ieWindow%
Click, 600, 600
IfWinActive, %ffWindow%
Click(600, 600, "Control")
Sleep, 500
;TODO maybe we could toggle this on and off easily like server refresh mode
if suppressPageReload
ExitApp
WinActivate, .*(%allWindow%|Problem loading page).* - Mozilla Firefox ahk_class MozillaWindowClass
IfWinActive, %ffWindow%
SendInput, {F8}
SendInput, {F5}
Run, RefreshIfProblemLoadingPage.ahk
Run, AutoDownloadFirefoxPrompts.ahk
;WaitForImageSearch("images\firebug\WelcomeTabCruddy.bmp")
;WaitForImageSearch("images\firebug\WelcomeTab.bmp")
;WaitForImageSearch("images\firebug\WelcomeScreen.bmp")
;{{{ Refresh if we're using firefox
if InStr( GetURLbar("firefox"), "phosphorus.lan.mitsi.com" )
{
if ForceWinFocusIfExist("Ellis Partners in Mystery Shopping: Customer Interface - Mozilla Firefox", "Exact")
{
;This section is for testing out EPMS Customer Interface (Initially for Survey Graphing / Reporting)
Sleep, 500
;Click(1279,52)
SleepSeconds(2)
WaitForImageSearch("images/firebug/EllisLogo.bmp")
SleepSeconds(2)
Click(72, 308, "Control")
Sleep, 700
Click(72, 359, "Control")
;Sleep, 700
ExitApp
}
if ForceWinFocusIfExist(ffWindow, "RegEx")
{
ForceWinFocus(ffWindow, "RegEx")
ClickIfImageSearch("images\firebug\ConsoleTab.bmp", "Control")
if (DebuggerCommand == "EPMS")
ExitApp
ForceWinFocus(ffWindow, "RegEx")
if (welcomeTabImage)
WaitForImageSearch(welcomeTabImage)
WaitForImageSearch("images\firebug\LoadedRoles.bmp")
WaitForImageSearch("images\firebug\LoadedWelcome.bmp")
ForceWinFocus(ffWindow, "RegEx")
ClickIfImageSearch("images\firebug\ClearTypedText.bmp", "Control")
ClickIfImageSearch("images\firebug\SelectCommandWindow.bmp", "Control")
;Send, %DebuggerCommand%
;SendInput, %DebuggerCommand%
if ( StrLen(DebuggerCommand) > 4 )
SendViaClipboard(DebuggerCommand)
ClickIfImageSearch("images\firebug\RunTypedText.bmp", "Control")
ExitApp
}
ForceWinFocusIfExist("Mozilla Firefox", "Contains")
if (DebuggerCommand == "EPMS")
{
Click(500,500)
;if InStr( GetURLbar("firefox"), "phosphorus.lan.mitsi.com" )
;{
;ClickIfImageSearch("images\firebug\reloadButton.bmp", "Control")
;ClickIfImageSearch("images\firebug\reloadButton.bmp") ;I think this doesn't work for this version of ff
Send, {F5}
;Send, ^{F5}
;}
}
}
;}}}
;{{{ Refresh if we're using IE
if ForceWinFocusIfExist(ieWindow, "RegEx")
{
;if (DebuggerCommand == "EPMS")
;ExitApp
;WaitForImageSearch(welcomeTabImage)
;Sleep, 100
;IfWinNotActive, , Developer Tools Tabs ,
;SendInput, {F12}
;Sleep, 100
;IfWinNotActive, , Developer Tools Tabs ,
;SendInput, {F12}
;Sleep, 100
;ClickIfImageSearch("images\ieDebug\ScriptTab.bmp")
;ClickIfImageSearch("images\ieDebug\MultiLineModeButton.bmp")
;SendInput, ^p
;Sleep, 100
;ClickIfImageSearch("images\ieDebug\ScriptTextbox.bmp")
;Sleep, 100
;;Send, %DebuggerCommand%
;;SendInput, %DebuggerCommand%
;SendViaClipboard(DebuggerCommand)
;Sleep, 100
;ClickIfImageSearch("images\ieDebug\RunScriptButton.bmp")
;;return
;SendInput, {F12}
;;ExitApp
}
Sleep, 4000
if ForceWinFocusIfExist("Ellis Partners in Mystery Shopping: Customer Interface - Windows Internet Explorer", "Exact")
{
MouseClick, left, 58, 308
Sleep, 700
MouseClick, left, 81, 330
Sleep, 700
MouseClick, left, 92, 348
Sleep, 700
MouseClick, left, 257, 240
Sleep, 700
MouseClick, left, 827, 507
}
;}}}
ExitApp
;{{{ Dumb functions to help out
ForceWinFocusCmd()
{
if LiveSiteMode
Sleep, 1000
;TODO change this to one regex that excludes MINGW32
if NOT ForceWinFocusIfExist("plackup ahk_class ConsoleWindowClass", "Contains")
if NOT ForceWinFocusIfExist("_server.pl ahk_class ConsoleWindowClass", "Contains")
if NOT ForceWinFocusIfExist("Administrator: Command Prompt ahk_class ConsoleWindowClass", "Exact")
if NOT ForceWinFocusIfExist("ahk_class ConsoleWindowClass", "Exact")
ForceWinFocusIfExist("cmd.exe", "Contains")
CustomTitleMatchMode("Contains")
IfWinActive, MINGW32
FatalErrord("", "Accidentally grabbed Git window")
CustomTitleMatchMode("Default")
}
;}}}