-
Notifications
You must be signed in to change notification settings - Fork 6
/
conf.py
140 lines (116 loc) · 3.83 KB
/
conf.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
129
130
131
132
133
134
135
136
137
138
139
140
#coding:utf-8
from __future__ import print_function, unicode_literals
import sys
import os
import re
from workflow import Workflow
from consts import *
log = None
def main(wf):
query = wf.decode(sys.argv[1])
log.info(query)
handle(wf, query)
def handle(wf, query):
query = query.strip()
if re.match(r'\S+\s+\S+', query) is None:
hasOption = False
for i, key in enumerate(ALL_KEYS):
if key.startswith(query):
if query == KEY_FOLDER:
hasOption = True
prepareFolders()
elif query == KEY_PROFILE:
hasOption = True
prepareProfile()
else:
hasOption = True
value = wf.stored_data(key)
option = key + ' ' + "[" + value + "]" if value else ALL_VALS[i]
wf.add_item(
title=option,
subtitle="Set Config for " + ALL_KEY_DESCS[i],
arg=key,
uid=option,
valid=True
)
if not hasOption:
option = 'You can configure: ' + ', '.join(ALL_KEYS)
wf.add_item(
title=option,
subtitle='',
arg=option,
uid=option,
valid=False
)
else:
query.replace(r'\s+', ' ')
kvPair = query.split(' ')
key = kvPair[0]
val = kvPair[1]
message = None
if ALL_KEYS.index(key) >= 0:
# wf.store_data(key, val)
# message = 'Configure ' + key + ' to ' + val + 'successfully!'
arg = key + ' ' + val
wf.add_item(
title='Set ' + ALL_KEY_DESCS[ALL_KEYS.index(key)] + ' to ' + val,
subtitle='',
arg=arg,
uid=arg,
valid=True
)
else:
message = 'Unrecognize configuration name: ' + key
wf.send_feedback()
def prepareFolders():
import sqlite3
#add default folder
wf.add_item(
title='Default(All)',
subtitle='Set search folder under Default(All)',
valid=True,
uid='folder 0',
arg='folder 0',
)
homePath = os.environ['HOME']
profile = wf.stored_data(KEY_PROFILE) or OUTLOOK_DEFAULT_PROFILE
# outlookData = homePath + '/outlook/'
outlookData = homePath + OUTLOOK_DATA_PARENT + profile + OUTLOOK_DATA_FOLDER
log.info(outlookData)
con = sqlite3.connect(outlookData + 'Outlook.sqlite')
count = 0
cur = con.cursor()
log.info("start querying folders")
cur.execute( """
SELECT Record_RecordID, Folder_Name FROM Folders
WHERE Record_AccountUID > 0
AND Folder_Name is not null
""")
if cur.rowcount:
for row in cur:
log.info(row[1])
wf.add_item(
title=unicode(row[1]),
subtitle='Set search folder under ' + unicode(row[1]),
valid=True,
uid='folder ' + str(row[0]),
arg='folder ' + str(row[0]),
)
cur.close()
def prepareProfile():
homePath = os.environ['HOME']
parent = homePath + OUTLOOK_DATA_PARENT
profiles = os.listdir(parent)
for profile in profiles:
if not profile.startswith('.'):
wf.add_item(
title=unicode(profile),
subtitle='Set profile as: ' + unicode(profile),
valid=True,
uid='profile ' + str(profile),
arg='profile ' + str(profile),
)
if __name__ == '__main__':
wf = Workflow()
log = wf.logger
sys.exit(wf.run(main))