main.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2020 Copter Express Technologies
4 #
5 # Author: Oleg Kalachev <okalachev@gmail.com>
6 #
7 # Distributed under MIT License (available at https://opensource.org/licenses/MIT).
8 # The above copyright notice and this permission notice shall be included in all
9 # copies or substantial portions of the Software.
10 
11 # TODO: add custom header, footer
12 # TODO: symlinks or copy param
13 
14 import os
15 import shutil
16 import rospy
17 import rospkg
18 
19 rospy.init_node('roswww_static')
20 
21 rospack = rospkg.RosPack()
22 
23 www = rospkg.get_ros_home() + '/www'
24 index_file = rospy.get_param('~index_file', None)
25 default_package = rospy.get_param('~default_package', None)
26 
27 shutil.rmtree(www, ignore_errors=True) # reset www directory content
28 os.mkdir(www)
29 
30 packages = rospack.list()
31 
32 index = '<h1>Packages list</h1>\n<ul>\n'
33 
34 for name in packages:
35  path = rospack.get_path(name)
36  if os.path.exists(path + '/www'):
37  rospy.loginfo('found www path for %s package', name)
38  os.symlink(path + '/www', www + '/' + name)
39  index += '<li><a href="{name}/">{name}</a></li>'.format(name=name)
40 
41 if default_package is not None:
42  redirect_html = '<meta http-equiv=refresh content="0; url={name}/">'.format(name=default_package)
43  open(www + '/index.html', 'w').write(redirect_html)
44 elif index_file is not None:
45  rospy.loginfo('symlinking index file')
46  os.symlink(index_file, www + '/index.html')
47 else:
48  open(www + '/index.html', 'w').write(index)


roswww_static
Author(s):
autogenerated on Mon Feb 28 2022 22:08:37