-
Notifications
You must be signed in to change notification settings - Fork 0
/
workers.py
49 lines (36 loc) · 1.25 KB
/
workers.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
# -*- coding: utf-8 -*-
import subprocess
from PyQt4.QtCore import QThread, SIGNAL
class VagrantPaths(QThread):
def __init__(self, parent=None):
QThread.__init__(self, parent)
def run(self):
output = subprocess.Popen(
"vagrant global-status --prune | awk '{ print $5 }' | grep '^\/'",
shell=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE
).stdout
paths = [line.decode('utf-8').strip() for line in output]
self.emit(SIGNAL('paths(QStringList)'), paths)
class VagrantCommand(QThread):
commandTemplate = 'cd %s && vagrant %s'
def __init__(self, parent=None):
QThread.__init__(self, parent)
self.action = None
self.path = None
def _getCommand(self):
return self.commandTemplate % (self.path, self.action)
def run(self):
output = subprocess.Popen(
self._getCommand(),
shell=True,
stdout=subprocess.PIPE
)
while True:
line = output.stdout.readline()
if line:
self.emit(SIGNAL('commandOutput(QString)'), line.decode('utf-8').rstrip())
else:
self.emit(SIGNAL('commandFinish()'))
break