Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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