forked from bikeshedder/deadpool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-readme.py
executable file
·36 lines (32 loc) · 1009 Bytes
/
sync-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
#!/bin/env python
import os
import itertools
BASE_DIR = os.path.dirname(__file__)
CRATES = [
'.',
'postgres',
'redis',
'lapin',
'sqlite',
]
if __name__ == '__main__':
for crate_name in CRATES:
readme_filename = os.path.join(BASE_DIR, crate_name, 'README.md')
src_filename = os.path.join(BASE_DIR, crate_name, 'src', 'lib.rs')
with open(readme_filename) as fh:
readme = fh.readlines()
with open(src_filename) as fh:
it = iter(fh.readlines())
for line in it:
if not line.startswith("//!"):
break
code = ''.join(itertools.chain([line], it))
with open(src_filename + '.new', 'w') as fh:
for line in readme:
if line.rstrip():
fh.write('//! ')
else:
fh.write('//!')
fh.write(line)
fh.write(code)
os.rename(src_filename + '.new', src_filename)