This repository was archived by the owner on Dec 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathr2wiki.py
47 lines (43 loc) · 1.5 KB
/
r2wiki.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
import os
import re
import sys
import pydoc
try:
from pygments import highlight
from pygments.lexers import MarkdownLexer
from pygments.formatters import TerminalFormatter
except ImportError:
print 'Pygments dependency not met. pip install Pygments'
"""
Directions on how to setup is in the wiki itself
"""
try:
src_dir = os.path.dirname(os.path.realpath(__file__))
pattern = re.compile (sys.argv[1])
found = ''
for path, subdirs, files in os.walk(src_dir):
for name in files:
md_path = os.path.join(path, name)
if not '.git' in md_path and md_path.endswith('.md'):
with open(md_path, 'r') as f:
for lines in f.readlines():
if re.search(pattern, lines):
if not any(filter in lines for filter in ['<p hidden>',
'<!--',
'<img src']):
match = ((re.sub('\*\*', '', lines)).lstrip() + '\n')#.replace('`', "'")
if match.startswith('- ['):
split = match.split(']')
found += max(split, key=len).replace('[', '') + \
' [.](https://radare2.securisec.com%s' % split[-1].strip('(')
else:
if match.startswith('>'):
match = ''.join(list(match)[1:])
if match.startswith('#'):
match = ''.join(list(match)[1:])
if match.startswith(' _'):
match = re.sub('_', '', ''.join(list(match)[1:]))
found += match
pydoc.pipepager(highlight(found, MarkdownLexer(), TerminalFormatter()), cmd='less -r')
except IndexError:
print 'Usage: %s search_param' % sys.argv[0]