-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (55 loc) · 1.44 KB
/
main.py
File metadata and controls
59 lines (55 loc) · 1.44 KB
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
# encoding: utf-8
import sys
import init
from workflow import Workflow, ICON_ERROR, ICON_INFO
from workflow.background import run_in_background, is_running
def filterVariables(variable):
elements = []
elements.append(variable["name"])
elements.append(variable["value"])
return u' '.join(elements)
def main(wf):
if len(wf.args) and wf.args[0] == "--update" and not is_running('update'):
cmd = ['/usr/bin/python', wf.workflowfile('init.py')]
run_in_background('update', cmd)
elif len(wf.args) and wf.args[0] == "--shell":
if len(wf.args) == 2 and wf.args[1] in init.shells:
wf.settings["shell"] = str(wf.args[1])
else:
for sh in init.shells:
wf.add_item(sh,
arg=sh,
valid=True,
icon=u'icon.png')
wf.send_feedback()
return
elif len(wf.args):
query = wf.args[0]
else:
query = None
if is_running('update'):
wf.add_item('In progress',
valid=False,
icon=ICON_INFO)
wf.send_feedback()
return
try:
variables = wf.settings["data"]
except:
wf.add_item(title="List not initialized",
subtitle="You should run sv init",
icon=ICON_ERROR)
wf.send_feedback()
return
if query:
variables = wf.filter(query, variables, key=filterVariables)
for variable in variables:
wf.add_item(title=variable["name"],
subtitle=variable["value"],
arg=variable["value"],
valid=True,
icon=u'icon.png')
wf.send_feedback()
if __name__ == "__main__":
wf = Workflow()
sys.exit(wf.run(main))