-
Notifications
You must be signed in to change notification settings - Fork 3
/
rake.py
70 lines (57 loc) · 2.1 KB
/
rake.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
import os
import re
import sublime
try:
from QuickRails.QuickRails import QuickRailsWindowCommand, get_idea
from QuickRails.QuickExec import ProcessListener
except Exception:
from .QuickRails import QuickRailsWindowCommand, get_idea
from .QuickExec import ProcessListener
class QuickRailsRakeTasksCommand(QuickRailsWindowCommand, ProcessListener):
def is_spring_available(self):
return os.path.isfile('spring') and os.access(fpath, os.X_OK)
def run(self):
self.rakeTasks = self.get_available_rake_tasks()
self.window.show_quick_panel(self.rakeTasks, self.on_selected)
def on_selected(self, selected):
if selected == 0:
if self.is_spring_available:
self.run_quick_command("spring rake -sT", self.window.folders()[0], self)
else:
self.run_quick_command("rake -sT", self.window.folders()[0], self)
elif selected > 0:
self.rake(self.rakeTasks[selected])
def on_data(self, proc, data):
pass
def on_finished(self, proc, alldata):
if alldata:
tasks = self.parse_rake_tasks(alldata)
self.write_tasks_to_file(tasks)
self.window.show_quick_panel(tasks, self.on_selected)
def rake(self, argument):
self.window.show_input_panel("rake ", argument + " ", lambda s: self.run_rake_task(s), None, None)
def run_rake_task(self, argument):
command = 'rake {thing}'.format(thing=argument)
self.run_shell_command(command, self.window.folders()[0])
def parse_rake_tasks(self, rake_tasks_result):
rtsk = re.findall("rake ([\w:]+)", rake_tasks_result)
return rtsk
def write_tasks_to_file(self, rtsk):
rtsk.sort()
data = "\n".join(rtsk)
f = open(os.path.join(get_idea(self.get_working_dir()), '.rakeTasks'), 'w')
f.write(data)
f.close()
def get_available_rake_tasks(self):
try:
f = open(os.path.join(get_idea(self.get_working_dir()), '.rakeTasks'), 'r')
data = f.read()
f.close()
rtsk = data.split()
rtsk.insert(0, "Update rake tasks...")
except IOError:
rtsk = "".split()
rtsk.insert(0, "Update rake tasks...")
return rtsk
def is_enabled(args):
return True