-
Notifications
You must be signed in to change notification settings - Fork 6
/
cheatsheet.py
executable file
·54 lines (42 loc) · 1.34 KB
/
cheatsheet.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
#!/usr/bin/env python
# encoding: utf-8
#desc: use for key word to search the shortcut
import os.path
import glob
import sys
import yaml
COLOR_NONE = "\033[m"
COLOR_GREEN = "\033[01;32m"
COLOR_RED = "\033[01;31m"
COLOR_YELLOW = "\033[01;33m"
def get_color_str(color, msg):
return color + msg + COLOR_NONE
def build_map(meta_map, key_map, dir_path):
"""read yaml config file to map"""
kv_paths = glob.glob(os.path.join(dir_path, '*.kv'))
for kv_path in kv_paths:
filename = os.path.basename(kv_path)
filename = filename.split('.')[0]
f = open(kv_path)
data = yaml.load(f)
for key, value in data.items():
key = str(key)
meta_key = '[%s] %s' %(filename, key)
meta_map.update({meta_key: value})
key_map.setdefault(key, []).append(meta_key)
if __name__ == '__main__':
meta_map = {}
key_map = {}
path = os.path.dirname(os.path.abspath(__file__))
dir_path = os.path.join(path, 'CSData')
build_map(meta_map, key_map, dir_path)
key = sys.argv[1]
key = key.lower()
if key in key_map:
meta_keys = key_map.get(key)
for meta_key in meta_keys:
print get_color_str(COLOR_GREEN, meta_key)
print meta_map.get(meta_key),
print
else:
print get_color_str(COLOR_RED, 'miss match')