forked from lucasduffey/binaryninja-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_index.py
74 lines (57 loc) · 2.69 KB
/
generate_index.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
''' Python script to generate a stub README.md files from a plugin.json file '''
import json
import argparse
import os
import sys
import configparser
from collections import OrderedDict
parser = argparse.ArgumentParser(description = 'Generate README.md index of all plugins')
parser.add_argument("-f", "--force", help = 'will automatically overwrite existing README', action='store_true')
args = parser.parse_args()
os.path.realpath(__file__)
basedir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'plugins')
outputfile = os.path.join(basedir, 'README.md')
if not args.force and os.path.isfile(outputfile):
print("Cowardly refusing to overwrite an existing README. Remove or re-run with -f.")
sys.exit(0)
channels = os.walk(basedir).next()[1]
template = '# Binary Ninja Plugins\n\n'
config = configparser.ConfigParser()
config.readfp(open(os.path.join(basedir, '..', '.gitmodules')))
submodules = {}
for section in config.items()[1:]:
sectionname = section[0].split('"')[1]
submodules[sectionname] = config.get(section[0], 'url')
for channel in ['official', 'community']: # Because otherwise it's alphabetical
index = os.path.join(basedir, channel + ".json")
if not args.force and os.path.isfile(index):
print("Cowardly refusing to overwrite an existing index. Remove or re-run with -f.")
sys.exit(0)
plugins = []
if channel.startswith('.'):
continue
template += "## {}\n\n".format(channel.title())
template += '''| PluginName | Author | License | Description |
|------------|--------|---------|-------------|
'''
for plugin in os.walk(os.path.join(basedir, channel)).next()[1]:
try:
url = submodules[os.path.join('plugins', channel, plugin)]
if url.endswith('.git'):
url = url[:-4]
authorlink = '/'.join(url.split('/')[:4])
except:
url = 'https://github.com/Vector35/binaryninja-plugins/tree/master/plugins/{channel}/{plugin}'.format(channel = channel, plugin = plugin)
authorlink = 'https://github.com/Vector35/'
data = json.load(open(os.path.join(basedir, channel, plugin, "plugin.json")), object_pairs_hook=OrderedDict)['plugin']
data['url'] = url
data['path'] = plugin
plugins.append(data)
template += '|[{name}]({url})|[{author}]({authorlink})|[{license}]({channel}/{plugin}/LICENSE)|{description}|\n'.format(name = data['name'], channel = channel,
url = url, plugin = plugin, author = data['author'], authorlink = authorlink,
license = data['license']['name'], description = data['description'])
template += "\n\n"
print("Writing {outputfile}".format(outputfile=index))
open(index, 'w').write(json.dumps(plugins, indent=4, sort_keys=True))
print("Writing {outputfile}".format(outputfile=outputfile))
open(outputfile, 'w').write(template)