-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.py
128 lines (91 loc) · 2.46 KB
/
info.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
#!/usr/bin/python
# encoding: utf-8
#
# Copyright (c) 2018 Mark Koester [email protected]
#
# MIT Licence. See http://opensource.org/licenses/MIT
#
# Created on 2018-05
#
"""info.py [options] [<query>]
View/manage workflow settings.
Usage:
info.py [<query>]
info.py (-h|--help)
info.py --openhelp
info.py --logbug
Options:
-h, --help Show this message
--openhelp Open help file in default browser
--logbug Log bug to Bug Tracker
"""
from __future__ import absolute_import
import subprocess
import sys
from docopt import docopt
from workflow import (
ICON_INFO,
ICON_WARNING,
ICON_WEB,
MATCH_ALL,
MATCH_ALLCHARS,
Workflow3,
)
from config import (
ICON_HELP,
ICON_BUG,
KEYWORD_SETTINGS,
README_URL,
HELP_URL
)
log = None
DELIMITER = u'\u203a' # SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
ALFRED_AS = 'tell application "Alfred 3" to search "{}"'.format(
KEYWORD_SETTINGS)
def main(wf):
"""Run Script Filter.
Args:
wf (workflow.Workflow): Workflow object.
"""
args = docopt(__doc__, wf.args)
log.debug('args : {!r}'.format(args))
query = args.get('<query>')
# bootstrap(wf)
# Alternative actions ----------------------------------------------
if args.get('--openhelp'):
subprocess.call(['open', README_URL])
return
if args.get('--logbug'):
subprocess.call(['open', HELP_URL])
return
# Parse query ------------------------------------------------------
if DELIMITER in query:
return handle_delimited_query(query)
# Filter options ---------------------------------------------------
query = query.strip()
options = [
dict(title='View Help File',
subtitle='Open help file in your browser',
valid=True,
arg='--openhelp',
icon=ICON_HELP),
dict(title='Log a Bug',
subtitle='Log a bug your browser',
valid=True,
arg='--logbug',
icon=ICON_BUG),
]
if query:
options = wf.filter(query, options, key=lambda d: d['title'],
min_score=30)
if not options:
wf.add_item('No matching options', 'Try a different query?',
icon=ICON_WARNING)
for d in options:
wf.add_item(**d)
wf.send_feedback()
return
if __name__ == '__main__':
wf = Workflow3()
log = wf.logger
sys.exit(wf.run(main))