forked from cah011/binja-avr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_readme.py
79 lines (60 loc) · 2.73 KB
/
generate_readme.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
''' Python script to generate a stub README.md files from a plugin.json file '''
import json
import argparse
import os
import sys
parser = argparse.ArgumentParser(description = 'Generate README.md (and optional LICENSE) from plugin.json metadata')
parser.add_argument('filename', type = argparse.FileType('r'), help = 'path to the plugin.json file')
parser.add_argument("-f", "--force", help = 'will automatically overwrite existing files', action='store_true')
args = parser.parse_args()
plugin = json.load(args.filename)['plugin']
outputfile = os.path.join(os.path.dirname(args.filename.name), 'README.md')
licensefile = os.path.join(os.path.dirname(args.filename.name), 'LICENSE')
if not args.force and (os.path.isfile(outputfile) or os.path.isfile(licensefile)):
print("Cowardly refusing to overwrite an existing license or readme.")
sys.exit(0)
if 'license' in plugin and 'name' in plugin['license'] and 'text' in plugin['license']:
name = plugin['license']['name']
text = plugin['license']['text']
license = '''## License
This plugin is released under a [{name}](LICENSE) license.
'''.format(name=plugin['license']['name'])
print("Creating {licensefile}".format(licensefile=licensefile))
open(licensefile,'w').write(plugin['license']['text'])
elif ('license' in plugin and 'name' in plugin['license']):
name = plugin['license']['name']
license = '''## License
This plugin is released under a {name}] license.
'''.format(name=plugin['license']['name'])
else:
license = ''
if 'minimumBinaryNinjaVersion' in plugin:
minimum = '## Minimum Version\n\nThis plugin requires the following minimum version of Binary Ninja:\n\n'
for chan in plugin['minimumBinaryNinjaVersion']:
version = plugin['minimumBinaryNinjaVersion'][chan]
minimum += " * {chan} - {version}\n".format(chan = chan, version = version)
minimum += '\n'
else:
minimum = ''
if 'dependencies' in plugin:
dependencies = '## Required Dependencies\n\nThe following dependencies are required for this plugin:\n\n'
for dependency in plugin['dependencies']:
dependencylist = ', '.join(plugin['dependencies'][dependency])
dependencies += " * {dependency} - {dependencylist}\n".format(dependency = dependency, dependencylist = dependencylist)
dependencies += '\n'
else:
dependencies = ''
template = '''# {PluginName} (v{version})
Author: **{author}**
_{description}_
## Description:
{longdescription}
{minimum}
{dependencies}
{license}
'''.format(PluginName = plugin['name'], version = plugin['version'],
author = plugin['author'], description = plugin['description'],
longdescription = plugin['longdescription'], license = license,
dependencies = dependencies, minimum = minimum)
print("Writing {outputfile}".format(outputfile=outputfile))
open(outputfile, 'w').write(template)