-
Notifications
You must be signed in to change notification settings - Fork 3
/
make-readme.py
executable file
·47 lines (37 loc) · 1.47 KB
/
make-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
#!/usr/bin/python3
from __future__ import absolute_import, division, print_function, unicode_literals
import argparse
import os
import subprocess
import i3_rofi_mark.i3_rofi_mark as app
HERE = os.path.dirname(__file__)
def make_readme_text():
parser = app.build_parser()
help_text = parser.format_help()
with open('README.template') as stream:
return '<!-- This is generated by make-readme.py do not edit -->\n' + stream.read().format(
usage=help_text,
)
def backticks(command, stdin=None, shell=False):
stdin_arg = subprocess.PIPE if stdin is not None else None
process = subprocess.Popen(command, stdout=subprocess.PIPE, stdin=stdin_arg, shell=shell)
result, _ = process.communicate(stdin)
if process.returncode != 0:
raise Exception('{!r} returned non-zero return code {!r}'.format(command, process.returncode))
result = result.decode('utf8')
return result
def main():
PARSER = argparse.ArgumentParser(description='Write readme.md')
PARSER.add_argument('--stdout', action='store_true', help='Write to standard out rather than README.md')
options = PARSER.parse_args()
output = make_readme_text()
if options.stdout:
print(output, end='')
else:
if os.path.exists('README.md'):
os.chmod('README.md', 0o700)
with open('README.md', 'w') as out_stream:
out_stream.write(output)
os.chmod('README.md', 0o400)
if __name__ == '__main__':
main()