-
Notifications
You must be signed in to change notification settings - Fork 0
/
rwx.py
60 lines (49 loc) · 866 Bytes
/
rwx.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
'''
RWX v1.0
Github: https://github.com/nyukhalov/alfred-rwx
Author: Roman Niukhalov
'''
ex = {
0: "---",
1: "--x",
2: "-w-",
3: "-wx",
4: "r--",
5: "r-x",
6: "rw-",
7: "rwx",
}
roles = {
0: "owner",
1: "group",
2: "other"
}
bad_format_msg = "Type one to three digits each in the range [0..7]"
query = '{query}'
query = query.lower()
title = ""
explanation = ""
valid = True
if len(query) > 3:
valid = False
else:
exp_parts = []
for idx, x in enumerate(query):
num = ord(x) - ord('0')
if num < 0 or num > 7:
valid = False
break
exp_parts.append("{0}: {1}".format(roles[idx], ex[num]))
title += ex[num]
explanation = ", ".join(exp_parts)
if not valid:
title = bad_format_msg
explanation = ""
json = """{{"items": [
{{
"uid": "result",
"title": "{0}",
"subtitle": "{1}"
}}
]}}""".format(title, explanation)
print json