-
Notifications
You must be signed in to change notification settings - Fork 190
/
generate_readme.py
executable file
·158 lines (122 loc) · 4.71 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
import datetime
import glob
import math
import os.path as osp
import subprocess
import sys
import cv2
import tabulate
import jsk_recognition_utils
here = osp.dirname(osp.realpath(__file__))
PACKAGES = [
'jsk_recognition_msgs',
'jsk_perception',
'jsk_pcl_ros',
'jsk_pcl_ros_utils',
'resized_image_transport',
'jsk_recognition_utils',
'checkerboard_detector',
'imagesift',
]
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, 'nodes/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)
cv2.imwrite(fname, tiled)
content.append('### [%s](%s)' % (pkg, website_url.text))
content.append('')
content.append('[![](%s)](%s)' % (osp.relpath(fname, here),
website_url.text))
content.append('')
return '\n'.join(content)
def get_package_table():
headers = ['Package', 'Description', 'Documentation', 'Code']
rows = []
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')
if website_url:
doc_url = '[![](https://img.shields.io/badge/docs-here-brightgreen.svg)](%s)' % website_url.text
else:
doc_url = ''
repo_url = soup.find('url', type='repository')
if repo_url:
code_url = '[![](https://img.shields.io/badge/code-here-brightgreen.svg)](%s)' % \
osp.join(repo_url.text, 'tree/master', pkg)
else:
code_url = ''
desc = filter(None, soup.find('description').text.splitlines())[0].strip()
desc = desc[:50]
if not desc.endswith('.'):
desc += '...'
row = [pkg, desc, doc_url, code_url]
rows.append(row)
return tabulate.tabulate(rows, headers=headers, tablefmt='pipe')
def get_deb_status_table():
cmd = 'rosrun jsk_tools generate_deb_status_table.py jsk_recognition'
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\_recognition
===============
[![GitHub version](https://badge.fury.io/gh/jsk-ros-pkg%2Fjsk_recognition.svg)](https://badge.fury.io/gh/jsk-ros-pkg%2Fjsk_recognition)
[![Build Status](https://travis-ci.org/jsk-ros-pkg/jsk_recognition.svg)](https://travis-ci.org/jsk-ros-pkg/jsk_recognition)
[![Read the Docs](https://readthedocs.org/projects/jsk-recognition/badge/?version=latest)](https://jsk-docs.readthedocs.io/projects/jsk_recognition/en/latest/)
jsk_recognition is a stack for the perception packages which are used in JSK lab.
ROS packages
------------
{PACKAGES_TABLE}
Gallery
-------
{GALLERY}
Deb build status
----------------
{DEB_STATUS_TABLE}
Deprecated packages
-------------------
* [cr\_calibration](https://github.com/jsk-ros-pkg/jsk_recognition/tree/master/cr_calibration)
* [cr\_capture](https://github.com/jsk-ros-pkg/jsk_recognition/tree/master/cr_capture)
* [orbit\_pantilt](https://github.com/jsk-ros-pkg/jsk_recognition/tree/master/orbit_pantilt)
* [posedetectiondb](https://github.com/jsk-ros-pkg/jsk_recognition/tree/master/posedetectiondb)
* [jsk\_libfreenect2](https://github.com/jsk-ros-pkg/jsk_recognition/tree/master/jsk_libfreenect2)
'''
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(),
PACKAGES_TABLE=get_package_table(),
)
)
if __name__ == '__main__':
main()