forked from jsk-ros-pkg/jsk_visualization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_readme.py
executable file
·111 lines (81 loc) · 2.81 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
import datetime
import glob
import math
import os
import os.path as osp
import subprocess
import sys
import cv2
import jsk_recognition_utils
here = osp.dirname(osp.realpath(__file__))
PACKAGES = [
'jsk_rviz_plugins',
'jsk_rqt_plugins',
]
def get_gallery():
content = []
for pkg in PACKAGES:
# TODO(wkentaro): Scrape pacakge.xml only once by creating a class.
from bs4 import BeautifulSoup
with open(osp.join(pkg, 'package.xml')) as f:
soup = BeautifulSoup(f.read(), 'lxml')
website_url = soup.find('url', type='website')
imgs = []
for ext in ['*.png', '*.jpg']:
pattern = osp.join(here, 'doc', pkg, 'plugins/images', ext)
for fname in glob.glob(pattern):
img = cv2.imread(fname)
scale = math.sqrt(1. * 200 * 200 / img.shape[0] / img.shape[1])
img = cv2.resize(img, None, None, fx=scale, fy=scale)
imgs.append(img)
if len(imgs) >= 15:
break
if not imgs:
continue
cols = 5
rows = max(len(imgs) // cols, 1)
tiled = jsk_recognition_utils.get_tile_image(
imgs, tile_shape=(cols, rows), margin_color=[255, 255, 255])
fname = osp.join(here, '.readme/gallery_%s.jpg' % pkg)
if not osp.exists(osp.dirname(fname)):
os.makedirs(osp.dirname(fname))
cv2.imwrite(fname, tiled)
doc_url = website_url.text if website_url else ''
content.append('### [%s](%s)' % (pkg, doc_url))
content.append('')
content.append('[![](%s)](%s)' % (osp.relpath(fname, here), doc_url))
content.append('')
return '\n'.join(content)
def get_deb_status_table():
cmd = 'rosrun jsk_tools generate_deb_status_table.py jsk_visualization -f i -t k'
return subprocess.check_output(cmd, shell=True).strip()
template = '''\
<!--
DO NOT EDIT THIS FILE BY HAND.
This file is automatically generated by {SCRIPT} at {TIMESTAMP}.
-->
jsk\_visualization
=================
[![Build Status](https://travis-ci.org/jsk-ros-pkg/jsk_visualization.svg?branch=master)](https://travis-ci.org/jsk-ros-pkg/jsk_visualization)
[![Read the Docs](https://readthedocs.org/projects/pip/badge/?version=latest)](https://jsk-visualization.readthedocs.org)
jsk visualization ros package.
See [read the docs](http://jsk-visualization.readthedocs.org/en/latest/).
Gallery
-------
{GALLERY}
Deb build status
----------------
{DEB_STATUS_TABLE}
'''
def main():
sys.stdout.write(
template.format(
SCRIPT=osp.realpath(__file__),
TIMESTAMP=datetime.datetime.now().isoformat(),
DEB_STATUS_TABLE=get_deb_status_table(),
GALLERY=get_gallery(),
)
)
if __name__ == '__main__':
main()