__init__.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 import os
00019 import re
00020 from airbus_docgen import env
00021 from airbus_docgen.common import html
00022 from airbus_docgen.common.html import HtmlElement, HtmlElementTree
00023 
00024 from airbus_docgen.docgen.pkg.summary import PackageSummary
00025 from airbus_docgen.docgen.pkg.description import PackageDescription
00026 from airbus_docgen.docgen.pkg.dependencies import PackageDependencies
00027 from airbus_docgen.docgen.pkg.generations import PackageGenerations
00028 from airbus_docgen.docgen.pkg.node import RosNode
00029 
00030 class AgiDoc(HtmlElement):
00031     
00032     def __init__(self):
00033         HtmlElement.__init__(self,
00034                              tag=html.Sections.section,
00035                              attrib={"class":"nodes"})
00036     
00037     def read(self, pkgdir, agi_xml, index):
00038         
00039         index_node=0
00040         
00041         for node_xml in agi_xml.iter('node'):
00042             index_node+=1
00043             title = HtmlElement(html.Sections.h3)
00044             node_name = node_xml.attrib['name']
00045             title.text = "%i.%i. %s"%(index, index_node, node_name)
00046             self.append(title)
00047             
00048             try:
00049                 ros_node = RosNode()
00050                 if ros_node.read(node_name, node_xml, index, index_node) is True:
00051                     self.append(ros_node)
00052             except Exception as ex:
00053                 html.HTMLException(ex, self)
00054             
00055         if index_node is 0:
00056             return False
00057         else:
00058             return True
00059 
00060 class RosPackage(HtmlElement):
00061     
00062     def __init__(self, pkgdir):
00063         HtmlElement.__init__(self,
00064                              tag=html.Sections.section,
00065                              attrib={"class":"package"})
00066         self._h2_index = 0
00067         self._dep_pkg = None
00068         pkg_xml = None
00069         # Load and read package.xml ressource
00070         pkg_xml_dir = pkgdir+'/package.xml'
00071         if os.access(pkg_xml_dir, os.R_OK):
00072             pkg_xml = html.loadHtml(pkg_xml_dir)
00073             self._read_pkg_xml(pkgdir, pkg_xml)
00074         else:
00075             html.HTMLException("Cannot found %s !"%pkg_xml_dir, self)
00076         
00077         # Load and read CMakeLists.txt ressource
00078         cmakelists_dir = pkgdir+'/CMakeLists.txt'
00079         if os.access(cmakelists_dir, os.R_OK):
00080             with open(cmakelists_dir) as fp:
00081                 cmakelists = fp.read()
00082                 self._read_cmakelists(pkgdir, cmakelists)
00083         else:
00084             html.HTMLException("Cannot found %s !"%cmakelists_dir, self)
00085             
00086         if pkg_xml is not None:
00087             self._read_agi_doc_xml(pkgdir, pkg_xml)
00088     
00089     def _read_pkg_xml(self, pkgdir, pkg_xml):
00090         
00091         pkg_name = HtmlElement(html.Sections.h1)
00092         pkg_name.text = pkg_xml.find("./name").text
00093         self.append(pkg_name)
00094         
00095         p = HtmlElement(html.Grouping.p)
00096         p.set("align","center")
00097         img = HtmlElement(html.EmbeddedContent.img)
00098         img.set("src","../dot/gen/%s.png"%pkg_xml.find("./name").text)
00099         
00100         p.append(img)
00101         self.append(p)
00102         
00103         pkg_summary_title = HtmlElement(html.Sections.h2)
00104         pkg_summary_title.text = "%i. Package Summary"%self.index_h2()
00105         self.append(pkg_summary_title)
00106         
00107         try:
00108             self.append(PackageSummary(pkgdir, pkg_xml))
00109         except Exception as ex:
00110             html.HTMLException(ex, self)
00111             
00112         pkg_desc_title = HtmlElement(html.Sections.h2)
00113         pkg_desc_title.text = "%i. Package description"%self.index_h2()
00114         self.append(pkg_desc_title)
00115         
00116         try:
00117             self.append(PackageDescription(pkgdir, pkg_xml))
00118         except Exception as ex:
00119             html.HTMLException(ex, self)
00120             
00121         pkg_dep_title = HtmlElement(html.Sections.h2)
00122         pkg_dep_title.text = "%i. Package dependencies"%self.index_h2()
00123         self.append(pkg_dep_title)
00124         
00125         try:
00126             self._dep_pkg = PackageDependencies(pkgdir, pkg_xml)
00127             self.append(self._dep_pkg)
00128         except Exception as ex:
00129             html.HTMLException(ex, self)
00130         
00131     def _read_cmakelists(self, pkgdir, cmakefile):
00132         
00133         try:
00134             pkg = PackageGenerations()
00135             dep_list = self._dep_pkg.get_dependencies_lists()
00136             if pkg.read(pkgdir, cmakefile, dep_list) is True:
00137                 pkg_build_title = HtmlElement(html.Sections.h2)
00138                 pkg_build_title.text = "%i. Package generation(s)"%self.index_h2()
00139                 self.append(pkg_build_title)
00140                 self.append(pkg)
00141         except Exception as ex:
00142             html.HTMLException(ex, self)
00143             
00144     def _read_agi_doc_xml(self, pkgdir, pkg_xml):
00145         
00146         agidoc_elem = pkg_xml.find("./export/agidoc")
00147         
00148         if agidoc_elem is not None:
00149             if 'src' in agidoc_elem.attrib:
00150                 fdoc = os.path.join(pkgdir, agidoc_elem.attrib['src'])
00151                 if os.path.isfile(fdoc):
00152                     agi = AgiDoc()
00153                     if agi.read(pkgdir, html.loadHtml(fdoc), self._h2_index+1) is True:
00154                         title = HtmlElement(html.Sections.h2)
00155                         title.text = "%i. More description"%self.index_h2()
00156                         self.append(title)
00157                         self.append(agi)
00158                 else:
00159                     html.HTMLException("Cannot open agidoc '%s'"%fdoc, self)
00160         else:
00161             html.HTMLException("AGI documentation not found !", self)
00162             
00163     def index_h2(self):
00164         self._h2_index+=1
00165         return self._h2_index
00166 
00167 class HtmlPkgFileGenerator(HtmlElementTree):
00168     
00169     def __init__(self, index, pkg_dir, pkg_name):
00170         HtmlElementTree.__init__(self, index.getroot())
00171         self._pkg_name = pkg_name
00172         
00173         div = self.getroot().find("./body/div")
00174         
00175         try:
00176             pkg = RosPackage(pkg_dir)
00177             div.append(pkg)
00178         except Exception as ex:
00179             html.HTMLException(ex, div)
00180         
00181     def save(self):
00182         html.indent(self.getroot())
00183         #print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",os.path.join(env.ROSDOC_ROOT, "%s.html"%self._pkg_name)
00184         self.write(os.path.join(env.ROSDOC_GEN, "%s.html"%self._pkg_name),
00185                    encoding="utf8",
00186                    method="xml")
00187     
00188     def __str__(self):
00189         html.indent(self.getroot())
00190         return html.tostring(self.getroot())
00191 


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