app.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2008, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 # Revision $Id$
00035 
00036 import sys
00037 import yaml
00038 import subprocess
00039 import os.path
00040 
00041 def getPackagePath(pkg):
00042   cmd = ["rospack", "find", pkg]
00043   pkgpath = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].strip()
00044   return pkgpath
00045 
00046 class App:
00047   app_keys_lists = ('provides', 'depends')
00048   app_keys = ('name', 'package', 'launch_file', 'description', 
00049               'icon') + app_keys_lists
00050   def __init__(self, taskid):
00051     if not taskid.endswith(".app"):
00052       taskid = taskid + ".app"
00053     self.taskid = taskid
00054     self.package, self.app_file = self.taskid.split('/', 1)
00055     self.path = None
00056 
00057   def fn(self):
00058     if self.path: return self.path
00059     self.path = getPackagePath(self.package)
00060     fn = os.path.join(self.path, self.app_file)
00061     return fn
00062 
00063   def load_yaml(self):
00064     fn = self.fn()
00065     # TODO catch file system exception
00066     doc = yaml.load(open(fn))
00067     return doc
00068 
00069   def load(self):
00070     doc = self.load_yaml()
00071     try:
00072       for key in self.app_keys:
00073         if doc.has_key(key):
00074           val = doc[key]
00075           if val is not None:
00076             if type(val) != list: 
00077               val = val.strip()
00078             if key in self.app_keys_lists:
00079               if type(val) == list: 
00080                 val.sort()
00081                 val = tuple(val)
00082               else:
00083                 val = tuple([val])
00084           setattr(self, key, val)
00085     except KeyError:
00086       print "Invalid YAML file"
00087 


launchman
Author(s): Scott Hassan
autogenerated on Wed Apr 23 2014 10:35:46