19 rospy.init_node(
'roswww_static')
21 rospack = rospkg.RosPack()
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)
27 shutil.rmtree(www, ignore_errors=
True)
30 packages = rospack.list()
32 index =
'<h1>Packages list</h1>\n<ul>\n' 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)
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')
48 open(www +
'/index.html',
'w').write(index)