index.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 
00019 import os
00020 import sys
00021 import rospy
00022 import rospkg
00023 
00024 from airbus_docgen.common import html
00025 from airbus_docgen.common.html import HtmlElementTree
00026 from airbus_docgen import env
00027 from airbus_docgen.docgen.menu import Menu
00028 import catkin_pkg.workspaces
00029 
00030 class AbstractIndex(HtmlElementTree):
00031     
00032     def __init__(self):
00033         HtmlElementTree.__init__(self,
00034                     html.loadHtml(os.path.join(env.ROSDOC_TEMPLATES,'index.html')))
00035         
00036         self._header_item  = self.getroot().find("./body/div/header")
00037         self._nav_item     = self.getroot().find("./body/div/nav")
00038         
00039     def setNavigation(self, nav):
00040         self._nav_item.append(nav)
00041         
00042     def save(self):
00043         html.indent(self.getroot())
00044         self.write(os.path.join(env.ROSDOC_GEN, "index.html"),
00045                    encoding="utf8",
00046                    method="xml")
00047     
00048     def __str__(self):
00049         html.indent(self.getroot())
00050         return html.tostring(self.getroot())
00051     
00052 class Index(AbstractIndex):
00053     os.system("cp -r "+env.ROSDOC_ROOT+"/resources/* %s"%env.OUTPUT)
00054     os.system("mkdir -p "+env.ROSDOC_DOT+"/gen")
00055     def __init__(self, dir_path):
00056         AbstractIndex.__init__(self)
00057         
00058         self._menu = Menu()
00059         self._menu.parse(dir_path)
00060         self.setNavigation(self._menu)
00061         # Generate all html documentations
00062         self._menu.generate(self)
00063 
00064 if __name__ == '__main__':
00065   rospy.init_node('index')
00066 
00067   rospy.loginfo("Output path: %s"%env.ROSDOC_GEN)
00068 
00069   if rospy.has_param('/airbus_docgen/pkg_dir'):
00070     ROS_PKG = rospy.get_param('/airbus_docgen/pkg_dir')
00071     rospack = rospkg.RosPack()
00072     try:
00073       ROS_WS = rospack.get_path(ROS_PKG)
00074       dir_path = ROS_WS
00075       rospy.loginfo("Generating documentation for the package: %s"%ROS_PKG)
00076     except:
00077       ROS_WS = ROS_PKG
00078       dir_path = ROS_WS + "/src"
00079       rospy.loginfo("Generationg documentation for the workspace: %s"%ROS_PKG)
00080       if not os.path.isdir(ROS_PKG+"/src"):
00081         rospy.logerr("Please define a valid workspace, %s doesn't contain a workspace"%ROS_WS)
00082         sys.exit(0)
00083   else:
00084     ROS_WSs = catkin_pkg.workspaces.get_spaces()
00085     ROS_WS = os.path.dirname(ROS_WSs[0])
00086     dir_path = ROS_WS + "/src"
00087     rospy.loginfo("Generationg documentation for the current workspace: %s"%ROS_WS)
00088     sys.path.append(os.path.join(ROS_WS,'src'))
00089     sys.path.append(os.path.join(env.ROSDOC_ROOT,'scripts'))
00090 
00091   index = Index(dir_path)
00092   index.save()
00093 
00094 


airbus_docgen
Author(s): Matignon Martin
autogenerated on Thu Jun 6 2019 17:59:08