launch.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 from airbus_docgen import env
00020 from airbus_docgen.common import html
00021 from airbus_docgen.common.html import HtmlElement
00022 from airbus_docgen.digraph.digraph import *
00023 from xml.etree import ElementTree
00024 from roslib.packages import get_pkg_dir
00025 
00026 class Prefix:
00027     
00028     KEY_FIND = 'find'
00029     KEY_ARG = 'arg'
00030     
00031     @staticmethod
00032     def is_prefixed(path):
00033         if '$' in path:
00034             return True
00035         else:
00036             return False
00037     
00038     @staticmethod
00039     def get_prefix(path):
00040         
00041         if Prefix.is_prefixed(path):
00042             try:
00043                 
00044                 path_split = path.split(")")
00045                 prefix = path_split[0].split("(")[-1]
00046                 prefix_args = prefix.split(' ')
00047                 key = prefix_args[0]
00048                 value = prefix_args[-1]
00049                 rex = path_split[-1]
00050                 return key, value, rex
00051             except :
00052                 raise Exception("Bad prefix !")
00053         else:
00054             raise Exception("No profixed path !")
00055         
00056     @staticmethod
00057     def find(path):
00058         
00059         if Prefix.is_prefixed(path):
00060             try:
00061                 key, value, rex = Prefix.get_prefix(path)
00062                 if key == Prefix.KEY_FIND:
00063                     return get_pkg_dir(value)+rex
00064                 else:
00065                     raise Exception("Bad prefixed key '%s'"%key)
00066             except Exception as ex:
00067                 raise ex
00068         else:
00069             return path
00070         
00071     @staticmethod
00072     def arg(exp, tree):
00073         
00074         if Prefix.is_prefixed(exp):
00075             try:
00076                 key, value, rex = Prefix.get_prefix(exp)
00077                 if key == Prefix.KEY_ARG:
00078                     node_arg = tree.find('%s[@name="%s"]'%(key,value))
00079                     df = node_arg.attrib["default"]
00080                     if Prefix.is_prefixed(df):
00081                         Prefix.arg(df, tree)
00082                     else:
00083                         return node_arg.attrib["default"]+rex
00084                 else:
00085                     raise Exception("Bad prefixed key '%s'"%key)
00086             except Exception as ex:
00087                 raise ex
00088         else:
00089             return exp
00090 
00091 class ConfigLaunch(HtmlElement):
00092     
00093     def __init__(self):
00094         HtmlElement.__init__(self,
00095                              tag=html.Sections.article)
00096         
00097         
00098     def read(self, launch_file):
00099         
00100         digraph = Digraph("LaunchGraph")
00101         digraph.setAttrib(Digraph.NODESEP, 0.1)
00102 #         digraph.setAttrib(Digraph.RANKDIR, 'LR')
00103          
00104         nconf = NODE("node")
00105         nconf.setAttrib(NODE.SHAPE, SHAPE.Plaintext)
00106         digraph.addNode(nconf)
00107         
00108         name = launch_file.split('/')[-1].split('.')[0]
00109         
00110         pkg = NODE(name)
00111         pkg.setAttrib(NODE.SHAPE, SHAPE.Ellipse)
00112         pkg.setAttrib(NODE.STYLE, STYLE.FILLED)
00113         pkg.setAttrib(NODE.COLOR, RgbColor.CornflowerBlue)
00114         pkg.setAttrib(NODE.FONTSIZE, 22)
00115         digraph.addRootNode(pkg)
00116         
00117         self._parse(launch_file, digraph)
00118         
00119         digraph.saveDot(env.ROSDOC_DOT+"/launch/%s.dot"%name)
00120         digraph.dotToPng(env.ROSDOC_DOT+"/launch/%s.png"%name)
00121         
00122         a = HtmlElement(html.Text.a)
00123         a.set(html.Attrib.href,"../dot/launch/%s.png"%name)
00124         a.set("target", "_blank")
00125         
00126         p = HtmlElement(html.Grouping.p)
00127         p.set("align","center")
00128         img = HtmlElement(html.EmbeddedContent.img)
00129         img.set("src","../dot/launch/%s.png"%name)
00130         
00131         p.append(img)
00132         a.append(p)
00133         self.append(a)
00134     
00135     def _parse(self, launch_file, digraph):
00136         
00137         launch_name = launch_file.split('/')[-1].split('.')[0]
00138         
00139         root = None
00140         try:
00141             root = ElementTree.parse(launch_file)
00142         except Exception as ex:
00143             html.HTMLException(ex, self)
00144             return
00145         
00146         tree = root.getroot()
00147         
00148         for elem in tree:
00149             #<include file="$(find pma_startup)/launch/pma1_driver.launch" />
00150             if elem.tag == 'include':
00151                 
00152                 include_split = elem.attrib["file"].split(")")
00153                 prefix = include_split[0]
00154                 pkg_name = prefix.split(" ")[-1]
00155                 
00156                 child = include_split[-1].split("/")[-1].split('.')[0]
00157                 
00158                 n1 = NODE(launch_name)
00159                 n1.setAttrib(NODE.SHAPE, SHAPE.Box)
00160                 n1.setAttrib(NODE.STYLE, STYLE.FILLED)
00161                 n1.setAttrib(NODE.COLOR, RgbColor.LightGray)
00162                 digraph.addNode(n1)
00163                 
00164                 n2 = NODE(child)
00165                 n2.setAttrib(NODE.SHAPE, SHAPE.Box)
00166                 n2.setAttrib(NODE.STYLE, STYLE.FILLED)
00167                 n2.setAttrib(NODE.COLOR, RgbColor.LightGray)
00168                 digraph.addNode(n2)
00169                 
00170                 digraph.connect(n1, n2)
00171                 
00172                 sub_launch = get_pkg_dir(pkg_name)+include_split[-1]
00173                 
00174                 self._parse(sub_launch, digraph)
00175                 
00176             #<node name="map_server_high_res" pkg="map_server" type="map_server" args="$(arg map_file_high_res)" respawn="false">
00177             elif elem.tag == "node":
00178                  
00179                 parent = launch_name
00180                 child = Prefix.arg(elem.attrib["name"],tree)
00181                 if parent == child:
00182                     child += "_node"
00183                      
00184                 nd = NODE(child)
00185                 nd.setAttrib(NODE.SHAPE, SHAPE.Ellipse)
00186                 nd.setAttrib(NODE.STYLE, STYLE.FILLED)
00187                 nd.setAttrib(NODE.COLOR, RgbColor.LightSeaGreen)
00188                 digraph.addNode(nd)
00189                 digraph.connect(parent, nd)
00190                 
00191         
00192         
00193 if __name__ == '__main__':
00194     
00195     cl = ConfigLaunch()
00196     
00197     


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