-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gourmet.py
854 lines (682 loc) · 28.2 KB
/
Gourmet.py
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
import datetime
import functools
import os
import re
import subprocess
import time
import thread
import sublime
import sublime_plugin
# Used for the command query panel.
history = ['']
class Prefs:
@staticmethod
def load():
settings = sublime.load_settings('Gourmet.sublime-settings')
Prefs.folder_search_hints = settings.get('top_folder_hints', [])
Prefs.folder_exclusions = settings.get('folder_exclusions', [])
Prefs.max_search_secs = settings.get('max_search_secs', 2)
Prefs.cake_additional_args = settings.get('cake_additional_args', False)
Prefs.debug = settings.get('debug', 0)
Prefs.path_to_cake = settings.get('path_to_cake', False)
Prefs.copy_env = settings.get('copy_env', True)
Prefs.override_env = settings.get('override_env', {})
Prefs.load()
class Msgs:
operation = 'top-level'
@staticmethod
def debug_msg(msg):
if Prefs.debug == 1:
print "[Gourmet Plugin " + Msgs.operation + "()] " + msg
Msgs.debug_msg('')
Msgs.debug_msg('')
Msgs.debug_msg('')
Msgs.debug_msg('=========================================================')
Msgs.debug_msg('Gourmet Plugin Reloaded')
Msgs.debug_msg('---------------------------------------------------------')
Msgs.debug_msg('')
Msgs.debug_msg('')
Msgs.debug_msg('')
# the AsyncProcess class has been cribbed from:
# https://github.com/maltize/sublime-text-2-ruby-tests/blob/master/run_ruby_test.py
class AsyncProcess(object):
def __init__(self, cmd, listener):
self.listener = listener
if Prefs.copy_env:
env = os.environ.copy()
# add 'PWD' to the environment, for those folks who use it
# in their tests
# env['PWD'] = cwd
else:
Msgs.debug_msg("Using EMPTY environment!")
env = {}
if Prefs.override_env:
Msgs.debug_msg("Updating environment with " + ' '.join(Prefs.override_env))
env.update(Prefs.override_env)
cwd = listener.cwd
Msgs.debug_msg("DEBUG_EXEC: " + ' '.join(cmd))
Msgs.debug_msg("DEBUG_CWD: " + cwd)
if os.name == 'nt':
# we have to run PHPUnit via the shell to get it to work for everyone on Windows
# no idea why :(
# I'm sure this will prove to be a terrible idea
self.proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env)
else:
# Popen works properly on OSX and Linux
self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env)
if self.proc.stdout:
thread.start_new_thread(self.read_stdout, ())
if self.proc.stderr:
thread.start_new_thread(self.read_stderr, ())
def read_stdout(self):
while True:
data = os.read(self.proc.stdout.fileno(), 2 ** 15)
if data != "":
sublime.set_timeout(functools.partial(self.listener.append_data, self.proc, data), 0)
else:
self.proc.stdout.close()
self.listener.is_running = False
break
def read_stderr(self):
while True:
data = os.read(self.proc.stderr.fileno(), 2 ** 15)
if data != "":
sublime.set_timeout(functools.partial(self.listener.append_data, self.proc, data), 0)
else:
self.proc.stderr.close()
self.listener.is_running = False
sublime.set_timeout(functools.partial(self.listener.append_data, self.proc, "\n--- PROCESS COMPLETE ---"), 0)
break
# the StatusProcess class has been cribbed from:
# https://github.com/maltize/sublime-text-2-ruby-tests/blob/master/run_ruby_test.py
class StatusProcess(object):
def __init__(self, msg, listener):
self.msg = msg
self.listener = listener
thread.start_new_thread(self.run_thread, ())
def run_thread(self):
progress = ""
while True:
if self.listener.is_running:
if len(progress) >= 10:
progress = ""
progress += "."
sublime.set_timeout(functools.partial(self.listener.update_status, self.msg, progress), 0)
time.sleep(1)
else:
break
class OutputView(object):
def __init__(self, name, window):
self.output_name = name
self.window = window
def show_output(self):
self.ensure_output_view()
self.window.run_command("show_panel", {"panel": "output." + self.output_name})
def show_empty_output(self):
self.ensure_output_view()
self.clear_output_view()
self.show_output()
def ensure_output_view(self):
if not hasattr(self, 'output_view'):
self.output_view = self.window.get_output_panel(self.output_name)
def clear_output_view(self):
self.ensure_output_view()
self.output_view.set_read_only(False)
edit = self.output_view.begin_edit()
self.output_view.erase(edit, sublime.Region(0, self.output_view.size()))
self.output_view.end_edit(edit)
self.output_view.set_read_only(True)
def append_data(self, proc, data):
str = data.decode("utf-8")
str = str.replace('\r\n', '\n').replace('\r', '\n')
str = re.sub('(.*)(\[2K|;\d+m)', '', str)
str = re.sub('\[(\d+)m', '', str)
# selection_was_at_end = (len(self.output_view.sel()) == 1
# and self.output_view.sel()[0]
# == sublime.Region(self.output_view.size()))
self.output_view.set_read_only(False)
edit = self.output_view.begin_edit()
self.output_view.insert(edit, self.output_view.size(), str)
#if selection_was_at_end:
self.output_view.show(self.output_view.size())
self.output_view.end_edit(edit)
self.output_view.set_read_only(True)
class CommandBase:
def __init__(self, window, cwd):
self.window = window
self.cwd = cwd
def show_output(self):
if not hasattr(self, 'output_view'):
self.output_view = OutputView('gourmet', self.window)
self.output_view.show_output()
def show_empty_output(self):
if not hasattr(self, 'output_view'):
self.output_view = OutputView('gourmet', self.window)
self.output_view.clear_output_view()
self.output_view.show_output()
def start_async(self, caption, executable):
self.is_running = True
self.proc = AsyncProcess(executable, self)
StatusProcess(caption, self)
def append_data(self, proc, data):
self.output_view.append_data(proc, data)
def update_status(self, msg, progress):
sublime.status_message(msg + " " + progress)
class GourmetCommand(CommandBase):
def run(self, shell, options={}, args=[]):
self.show_empty_output()
if Prefs.path_to_cake is not False:
executable = [Prefs.path_to_cake]
else:
executable = ["cake"]
if Prefs.cake_additional_args is not False:
for key, value in Prefs.cake_additional_args.items():
arg = "-" + key
if value != "":
arg += ' ' + value
executable.append(arg)
executable.append(shell)
# Add the additional options
for key, value in options:
option = "--" + key
if value != "":
option += "=" + value
executable.append(option)
# Add the additional arguments
if args != []:
for value in args:
executable.append(value)
self.start_async("Running Gourmet", executable)
class ActiveFile:
def is_test_buffer(self):
Msgs.debug_msg('Is buffer a file containing tests?')
filename = self.file_name()
if filename is None or not os.path.isfile(filename):
Msgs.debug_msg("-- Buffer is not a real file; unsaved new buffer?")
return False
filename = os.path.splitext(filename)[0]
if filename.endswith('Test'):
Msgs.debug_msg("-- Buffer is a test file")
return True
Msgs.debug_msg("-- Buffer is not a test file")
return False
def is_tests_buffer(self):
Msgs.debug_msg('Is buffer a file containing a testsuite?')
filename = self.file_name()
if not os.path.isfile(filename):
Msgs.debug_msg("-- Buffer is not a real file; unsaved new buffer?")
return False
filename = os.path.splitext(filename)[0]
if filename.endswith('Tests'):
Msgs.debug_msg("Buffer is a testsuite file")
return True
Msgs.debug_msg("Buffer is not a testsuite file")
return False
def determineClassToTest(self):
class_to_test = os.path.splitext(os.path.basename(self.file_name()))[0]
if not class_to_test.endswith('Test'):
class_to_test = class_to_test + "Test"
return class_to_test
# TODO Make it work with plugins too.
def determineWorkingDirectory(self):
workingDirectoryPath = os.path.dirname(self.file_name())
directory = os.path.basename(workingDirectoryPath)
while directory != 'Case' and directory != '':
workingDirectoryPath = os.path.dirname(workingDirectoryPath)
directory = os.path.basename(workingDirectoryPath)
regex = '^(.+)\/Test/Case.*$'
return re.match(regex, workingDirectoryPath).group(1)
def determineTestFile(self):
filename = os.path.splitext(os.path.basename(self.file_name()))[0]
if not filename.endswith('Test'):
return None
wholeName = self.file_name()
typeOfTest = os.path.basename( os.path.dirname(wholeName) )
fileName = os.path.basename( wholeName )
regex = '^(.+)Test.*$'
testName = re.match(regex, fileName).group(1)
return typeOfTest + '/' + testName
def error_message(self, message):
sublime.status_message(message)
def cannot_find_test_file(self):
return "Cannot find file containing unit tests"
def cannot_find_tested_file(self):
return "Cannot find file to be tested"
def not_in_project(self):
return "Only works if you have a ST2 project open"
def not_php_file(self, syntax):
Msgs.debug_msg(syntax)
matches = re.search("/([^/]+).tmLanguage", syntax)
if matches is not None:
syntax = matches.group(1)
return "Plugin does not support " + syntax + " syntax buffers"
class ActiveView(ActiveFile):
def is_php_buffer(self):
# most reliable way is to check the file extension
# we cannot rely on the buffer syntax; it can sometimes report
# 'HTML' even in a PHP buffer
filename = self.file_name();
if filename is None:
return False
ext = os.path.splitext(filename)[1]
if ext == '.php':
Msgs.debug_msg("Buffer is a PHP buffer")
return True
# is this a PHP buffer?
if re.search('.+\PHP.tmLanguage', self.view.settings().get('syntax')):
return True
# if we get here, we're not sure what else to try
Msgs.debug_msg("Buffer is not a PHP buffer; extension is: " + ext + "; syntax is: " + self.view.settings().get('syntax'))
return False
def has_project_open(self):
folders = self.view.window().folders()
if folders:
return True
return False
def file_name(self):
return self.view.file_name()
def top_folder(self):
folders = self.view.window().folders()
filename = self.file_name()
if filename is None:
return '/dev/null'
path = os.path.dirname(filename)
oldpath = ''
while not path in folders and path != oldpath:
oldpath = path
path = os.path.dirname(path)
if path == oldpath:
# problem - we didn't find ourselves in the list of open folders
# fallback to using heuristics instead
path = os.path.dirname(self.file_name())
while not FindFiles.reachedTopLevelFolders(oldpath, path):
oldpath = path
path = os.path.dirname(path)
Msgs.debug_msg("Top folder for this project is: " + path)
return path
def find_tested_file(self):
Msgs.debug_msg("Looking for tested file")
fq_classname = self.determine_full_class_name()
if fq_classname is None:
return None
if fq_classname[-4:] == 'Test':
fq_classname = fq_classname[:-4]
filename = fq_classname + '.php'
Msgs.debug_msg("Looking for tested file: " + os.path.basename(filename))
files_to_find = []
files_to_find.append(filename)
files_to_find.append(os.path.basename(filename))
filename = self.view.file_name()
if filename[-8:] == 'Test.php':
filename = filename[:-8] + '.php'
path_to_search = os.path.dirname(self.file_name())
path = FindFiles.find(self.top_folder(), path_to_search, files_to_find)
if path is None:
return None
return [path, fq_classname]
def find_test_file(self):
Msgs.debug_msg("Looking for test file")
classname = self.determine_full_class_name()
Msgs.debug_msg("classname is: " + classname)
if classname is None:
return None
classname = classname + 'Test'
filename = classname + '.php'
files_to_find = []
files_to_find.append(filename)
files_to_find.append(os.path.basename(filename))
files_to_find.append(os.path.basename(self.view.file_name())[:-4] + 'Test.php')
Msgs.debug_msg("Looking for test files: " + ', '.join(files_to_find))
path_to_search = os.path.dirname(self.file_name())
path = FindFiles.find(self.top_folder(), path_to_search, files_to_find)
if path is None:
return None
return [path, classname]
def determine_full_class_name(self):
namespace = self.extract_namespace()
classname = self.extract_classname()
if classname is None:
return None
path = ''
if len(namespace) > 0:
namespace = namespace.replace('\\', '/')
path = path + namespace + '/'
classname = classname.replace('_', '/')
path = path + classname
return path
def extract_namespace(self):
namespaces = self.view.find_all("namespace ([A-Za-z0-9_\\\]+);")
if namespaces is None or len(namespaces) == 0:
return ''
for namespace in namespaces:
line = self.view.substr(namespace)
return line[10:-1]
def extract_classname(self):
# Look for any classes in the current window
class_regions = self.view.find_by_selector('entity.name.type.class')
for r in class_regions:
# return the first class we find
return self.view.substr(r)
# If we get here, then there are no classes in the current window
return None
class ActiveWindow(ActiveFile):
def file_name(self):
if hasattr(self, '_file_name'):
return self._file_name
return None
def determine_filename(self, args=[]):
if len(args) == 0:
active_view = self.window.active_view()
filename = active_view.file_name()
else:
filename = args[0]
self._file_name = filename
def is_php_buffer(self):
ext = os.path.splitext(self.file_name())[1]
if ext == 'php':
return True
return False
class FoundFiles:
cache = {}
@staticmethod
def addToCache(top_folder, filename, result):
if top_folder not in FoundFiles.cache:
FoundFiles.cache[top_folder] = {}
Msgs.debug_msg('Adding ' + result + ' to cache for ' + top_folder)
FoundFiles.cache[top_folder][filename] = result
@staticmethod
def removeFromCache(top_folder, filename):
Msgs.debug_msg('Removing ' + filename + ' from cache for ' + top_folder)
if top_folder not in FoundFiles.cache:
Msgs.debug_msg('-- no cache for ' + top_folder)
return
if filename not in FoundFiles.cache[top_folder]:
Msgs.debug_msg('-- ' + filename + ' not found in cache')
return
del FoundFiles.cache[top_folder][filename]
Msgs.debug_msg('-- ' + filename + ' removed from cache')
@staticmethod
def removeCacheFor(top_folder):
Msgs.debug_msg('Removing cache for ' + top_folder)
if top_folder not in FoundFiles.cache:
Msgs.debug_msg('-- no cache for ' + top_folder)
return
del FoundFiles.cache[top_folder]
Msgs.debug_msg('-- removed cache')
@staticmethod
def removeCache():
Msgs.debug_msg('Completely emptying the cache')
FoundFiles.cache = {}
@staticmethod
def getFromCache(top_folder, filename):
Msgs.debug_msg('Get ' + filename + ' from cache for ' + top_folder)
if top_folder not in FoundFiles.cache:
Msgs.debug_msg('-- no cache for ' + top_folder)
return None
if filename not in FoundFiles.cache[top_folder]:
Msgs.debug_msg('-- ' + filename + ' not found in cache')
return None
Msgs.debug_msg('-- found ' + FoundFiles.cache[top_folder][filename])
return FoundFiles.cache[top_folder][filename]
class FindFiles:
searched_folders = {}
searched_for = {}
last_search_time = None
@staticmethod
def find(top_folder, search_from, files_to_find):
for file_to_find in files_to_find:
Msgs.debug_msg("Looking for " + file_to_find)
# check the cache - do we already know the answer?
result = FindFiles.searchCacheFor(top_folder, file_to_find)
if result is not None:
return result
# check the top folder
result = FindFiles.searchTopFolderFor(top_folder, file_to_find)
if result is not None:
# cache the result
FoundFiles.addToCache(top_folder, file_to_find, result)
return result
# check in the places given in hints
result = FindFiles.searchNamedPlacesFor(top_folder, Prefs.folder_search_hints, file_to_find)
if result is not None:
# cache the result
FoundFiles.addToCache(top_folder, file_to_find, result)
return result
# if we reach this point, we are going to have to search on disk
dir_name = search_from
if not os.path.isdir(dir_name):
dir_name = os.path.dirname(dir_name)
# straight-line search - fastest for most people
result = FindFiles.searchStraightUpwardsFor(top_folder, dir_name, file_to_find)
if result is not None:
# cache the result
FoundFiles.addToCache(top_folder, file_to_find, result)
return result
# okay, so where is it?
result = ProjectFiles.find(top_folder, file_to_find)
if result is not None:
FoundFiles.addToCache(top_folder, file_to_find, result)
return result
# if we get here, we cannot find the file
return None
@staticmethod
def searchCacheFor(top_folder, file_to_find):
return FoundFiles.getFromCache(top_folder, file_to_find)
@staticmethod
def searchNamedPlacesFor(top_folder, places, file_to_find):
for place in places:
pathToTest = os.path.join(top_folder, place)
filenameToTest = os.path.join(pathToTest, file_to_find)
Msgs.debug_msg('Searching for file ' + filenameToTest)
if os.path.exists(filenameToTest):
return filenameToTest
return None
@staticmethod
def searchTopFolderFor(top_folder, file_to_find):
Msgs.debug_msg('Searching top folder ' + top_folder + ' for ' + file_to_find)
return FindFiles.searchFolderFor(top_folder, file_to_find)
@staticmethod
def searchFolderFor(folder, file_to_find):
Msgs.debug_msg('-- Searching ' + folder + ' for ' + file_to_find)
filenameToTest = os.path.join(folder, file_to_find)
if os.path.exists(filenameToTest):
Msgs.debug_msg('---- Found ' + filenameToTest)
return filenameToTest
return None
@staticmethod
def reachedTopLevelFolders(oldpath, path):
if oldpath == path:
return True
hints = Prefs.folder_search_hints
hints.append("Sublime Text 2")
for hint in hints:
if os.path.exists(os.path.join(path, hint)):
return True
return False
@staticmethod
def reachedTopLevelFolder(folder, oldpath, path):
if oldpath == path:
return True
if folder[:len(path)] == path:
return True
return False
@staticmethod
def searchStraightUpwardsFor(top_folder, path, file_to_find):
Msgs.debug_msg("---- New search straight upwards ----")
# do we know where these files are?
return FindFiles._searchStraightUpwardsFor(top_folder, '', path, file_to_find)
@staticmethod
def _searchStraightUpwardsFor(top_folder, oldpath, path, file_to_find):
Msgs.debug_msg("Looking in " + path)
filenameToTest = os.path.join(path, file_to_find)
Msgs.debug_msg("Looking for " + filenameToTest)
if os.path.exists(filenameToTest):
return filenameToTest
if FindFiles.reachedTopLevelFolder(top_folder, oldpath, path):
return None
return FindFiles._searchStraightUpwardsFor(top_folder, path, os.path.dirname(path), file_to_find)
class ProjectFiles:
files = {}
last_built_time = None
@staticmethod
def buildFilesList(path):
Msgs.debug_msg('Building list of files under ' + path)
# does the path exist?
if not os.path.exists(path):
return None
ProjectFiles.files[path] = []
# how long will this take? let's find out
start = datetime.datetime.now()
# we're going to build up a cache of the files inside this project
i = 0
for root, dirs, files in os.walk(path):
for name in files:
ProjectFiles.files[path].append(os.path.join(root, name))
i = i + 1
end = datetime.datetime.now()
duration = (end - start)
Msgs.debug_msg('-- took ' + str(duration.seconds) + '.' + str(duration.microseconds) + ' second(s) to build')
Msgs.debug_msg('-- found ' + str(i) + ' file(s)')
# print ProjectFiles.files[path]
ProjectFiles.last_built_time = end
@staticmethod
def find(top_folder, filename):
Msgs.debug_msg('Searching ProjectFiles cache for ' + filename)
if top_folder not in ProjectFiles.files:
Msgs.debug_msg('-- no cache for ' + top_folder)
return None
result = [x for x in ProjectFiles.files[top_folder] if filename in x]
if len(result) == 0:
Msgs.debug_msg('-- none found')
return None
Msgs.debug_msg('-- found ' + result[0])
return result[0]
@staticmethod
def expired(when):
if not ProjectFiles.last_built_time is None and when < ProjectFiles.last_built_time:
return True
return False
class GourmetTextBase(sublime_plugin.TextCommand, ActiveView):
last_checked_enabled = None
def run(self, args):
print 'Not implemented'
def toggle_active_group(self):
# where will we open it?
num_groups = self.view.window().num_groups()
if num_groups > 1:
active_group = self.view.window().active_group()
active_group = (active_group + 1) % 2
if active_group >= num_groups:
active_group = num_groups - 1
Msgs.debug_msg("switching to group " + str(active_group))
self.view.window().focus_group(active_group)
def enabled_checked(self):
self.last_checked_enabled = datetime.datetime.now()
def needs_enabling(self):
if self.last_checked_enabled is None or ProjectFiles.expired(self.last_checked_enabled):
return True
return False
def execute_query(self, query):
global history
history.append(query)
query = query.split();
shell = query.pop(0);
cmd = GourmetCommand(self.view.window(), self.determineWorkingDirectory())
# TODO Replace hardcoded "app" argument to enable plugin tests.
cmd.run(shell, [], query)
class GourmetRunQueryCommand(GourmetTextBase):
def run(self, args):
global history
Msgs.operation = "GourmetRunQueryCommand.run"
Msgs.debug_msg('called')
sublime.active_window().show_input_panel('Enter command', history[-1], self.execute_query, None, None)
# TODO Finish up using `--filter` option for `TestShell`.
class GourmetRunTestFunctionCommand(GourmetTextBase):
def run(self, args):
Msgs.operation = "GourmetRunTestFileCommand.run"
def description(self):
Msgs.operation = "GourmetRunTestFileCommand.description"
return "Run Test ..."
def is_enabled(self):
Msgs.operation = "GourmetRunTestFileCommand.is_enabled"
Msgs.debug_msg('called')
return False
def is_visible(self):
Msgs.operation = "GourmetRunTestFileCommand.is_enabled"
Msgs.debug_msg('called')
return False
class GourmetRunTestFileCommand(GourmetTextBase):
def run(self, args):
Msgs.operation = "GourmetRunTestFileCommand.run"
Msgs.debug_msg('called')
cmd = GourmetCommand(self.view.window(), self.determineWorkingDirectory())
# TODO Replace hardcoded "app" argument to enable plugin tests.
cmd.run('test', [], ["app", self.determineTestFile()])
def description(self):
Msgs.operation = "GourmetRunTestFileCommand.description"
return "Run Tests ..."
def is_enabled(self):
Msgs.operation = "GourmetRunTestFileCommand.is_enabled"
return True
def is_visible(self):
if self.needs_enabling():
self.is_enabled()
Msgs.operation = "GourmetRunTestFileCommand.is_enabled"
Msgs.debug_msg('called')
if self.is_test_buffer() and os.path.exists(self.view.file_name()):
return True
return False
class GourmetOpenTestFileCommand(GourmetTextBase):
file_to_open = None
def run(self, args):
Msgs.operation = "GourmetOpenTestClassCommand.run"
# where will we open the file?
self.toggle_active_group()
# open the file
self.view.window().open_file(self.file_to_open)
def description(self):
return 'Open Test Class'
def is_enabled(self):
Msgs.operation = "GourmetOpenTestClassCommand.is_enabled"
Msgs.debug_msg('called')
self.enabled_checked()
self.file_to_open = None
if not self.has_project_open():
return False
if not self.is_php_buffer():
return False
if self.is_test_buffer() or self.is_tests_buffer():
return False
path = self.find_test_file()
if path is None:
return False
self.file_to_open = path[0]
return True
def is_visible(self):
if self.needs_enabling():
self.is_enabled()
Msgs.operation = "GourmetOpenTestClassCommand.is_visible"
Msgs.debug_msg('called')
if self.file_to_open is not None:
return True
return False
class GourmetFlushCacheCommand(GourmetTextBase):
def is_enabled(self):
Msgs.operation = "GourmetFlushCacheCommand.is_enabled"
Msgs.debug_msg('called')
Prefs.load()
FoundFiles.removeCache()
ProjectFiles.buildFilesList(self.top_folder())
# special case!!
#
# we call enabled_checked() AT THE END because it must have a
# timestamp no earlier than the time we rebuilt the ProjectFiles
# cache
self.enabled_checked()
return False
def is_visible(self):
if self.needs_enabling():
self.is_enabled()
Msgs.operation = "GourmetFlushCacheCommand.is_visible"
Msgs.debug_msg('called')
return False