-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcapistrano.py
64 lines (52 loc) · 2.07 KB
/
capistrano.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
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 QuickRailsCapistranoTasksCommand(QuickRailsWindowCommand, ProcessListener):
def run(self):
self.capistranoTasks = self.get_available_capistrano_tasks()
self.window.show_quick_panel(self.capistranoTasks, self.on_selected)
def on_selected(self, selected):
if selected == 0:
self.run_quick_command("cap -vT", self.window.folders()[0], self)
elif selected > 0:
self.capistrano(self.capistranoTasks[selected][0])
def on_data(self, proc, data):
pass
def on_finished(self, proc, alldata):
if alldata:
tasks = self.parse_capistrano_tasks(alldata)
self.write_tasks_to_file(tasks)
self.window.show_quick_panel(tasks, self.on_selected)
def capistrano(self, argument):
self.window.show_input_panel("cap ", argument + " ", lambda s: self.run_capistrano_task(s), None, None)
def run_capistrano_task(self, argument):
command = 'cap {thing}'.format(thing=argument)
self.run_shell_command(command, self.window.folders()[0])
def parse_capistrano_tasks(self, capistrano_tasks_result):
ctsk = re.findall("cap ([\w:]+\s.*)", capistrano_tasks_result)
ctsk = [re.sub("([\w:]+)[\s#]+(.*)", "\\1 \\2", i) for i in ctsk]
return ctsk
def write_tasks_to_file(self, ctsk):
ctsk.sort()
data = "\n".join(ctsk)
f = open(os.path.join(get_idea(self.get_working_dir()), '.capistranoTasks'), 'w')
f.write(data)
f.close()
def get_available_capistrano_tasks(self):
try:
f = open(os.path.join(get_idea(self.get_working_dir()), '.capistranoTasks'), 'r')
data = f.read()
f.close()
ctsk = [i.split(" ", 1) for i in data.split("\n")]
except IOError:
ctsk = []
ctsk.insert(0, ["Update capistrano tasks...", "Rebuild list of available capistrano tasks"])
return ctsk
def is_enabled(args):
return True