42 from rospkg
import ResourceNotFound
43 from .exceptions
import AppException, InvalidAppException, NotFoundException, InternalAppException
46 def __init__(self, subscribed_topics, published_topics):
51 if not isinstance(other, Interface):
57 __slots__ = [
'client_type',
'manager_data',
'app_data']
58 def __init__(self, client_type, manager_data, app_data):
67 if not isinstance(other, Client):
74 return yaml.dump(self.
as_dict())
77 __slots__ = [
'name',
'display_name',
'description',
'platform',
78 'launch',
'interface',
'clients',
'icon',
'plugins',
'plugin_order',
80 def __init__(self, name, display_name, description, platform,
81 launch, interface, clients, icon=
None, plugins=
None, plugin_order=
None,
99 d[s] = [c.as_dict()
for c
in self.
clients]
101 d[s] = getattr(self, s)
106 if not isinstance(other, AppDefinition):
108 return self.
name == other.name
and \
111 self.
platform == other.platform
and \
112 self.
launch == other.launch
and \
114 self.
clients == other.clients
and \
115 self.
icon == other.icon
119 @return: filepath of resource. Does not validate if filepath actually exists. 121 @raise ValueError: if resource is not a valid resource name. 122 @raise rospkg.ResourceNotFound: if package referred 123 to in resource name cannot be found. 124 @raise NotFoundException: if resource does not exist. 126 p, a = roslib.names.package_resource_name(resource)
128 raise ValueError(
"Resource is missing package name: %s"%(resource))
129 matches = roslib.packages.find_resource(p, a)
131 if len(matches) == 1:
134 raise NotFoundException(
"No resource [%s]"%(resource))
136 raise ValueError(
"Multiple resources named [%s]"%(resource))
140 @raise IOError: I/O error reading file (e.g. does not exist) 141 @raise InvalidAppException: if app file is invalid 143 with open(filename,
'r') as f: 144 y = yaml.load(f.read()) 147 subscribed_topics = y.get(
'subscribed_topics', {})
148 published_topics = y.get(
'published_topics', {})
150 raise InvalidAppException(
"Malformed interface, missing keys")
151 return Interface(published_topics=published_topics, subscribed_topics=subscribed_topics)
155 @raise InvalidAppExcetion: if app definition is invalid. 159 icon_resource = app_data.get(
'icon',
'')
160 if icon_resource ==
'':
163 if not icon_filename
or not os.path.exists(icon_filename):
166 except ValueError
as e:
167 raise InvalidAppException(
"Malformed appfile [%s]: bad icon entry: %s"%(appfile, e))
168 except NotFoundException:
170 raise InvalidAppException(
"App file [%s] refers to icon that cannot be found"%(appfile))
171 except ResourceNotFound
as e:
172 raise InvalidAppException(
"App file [%s] refers to package that is not installed: %s"%(appfile, str(e)))
176 @raise InvalidAppExcetion: if app definition is invalid. 181 if not os.path.exists(launch):
182 raise InvalidAppException(
"Malformed appfile [%s]: refers to launch that does not exist."%(appfile))
184 except ValueError
as e:
185 raise InvalidAppException(
"Malformed appfile [%s]: bad launch entry: %s"%(appfile, e))
186 except NotFoundException:
187 raise InvalidAppException(
"App file [%s] refers to launch that is not installed"%(appfile))
188 except ResourceNotFound
as e:
189 raise InvalidAppException(
"App file [%s] refers to package that is not installed: %s"%(appfile, str(e)))
193 @raise InvalidAppExcetion: if app definition is invalid. 199 if e.errno == errno.ENOENT:
200 raise InvalidAppException(
"Malformed appfile [%s]: refers to interface file that does not exist"%(appfile))
202 raise InvalidAppException(
"Error with appfile [%s]: cannot read interface file"%(appfile))
204 raise InvalidAppException(
"Malformed appfile [%s]: bad interface entry"%(appfile))
205 except ResourceNotFound
as e:
206 raise InvalidAppException(
"App file [%s] refers to package that is not installed: %s"%(appfile, str(e)))
210 @raise InvalidAppExcetion: if app definition is invalid. 212 clients_data = app_data.get(
'clients', [])
214 for c
in clients_data:
215 for reqd
in [
'type',
'manager']:
217 raise InvalidAppException(
"Malformed appfile [%s], missing required key [%s]"%(appfile, reqd))
218 client_type = c[
'type']
219 manager_data = c[
'manager']
220 if not type(manager_data) == dict:
221 raise InvalidAppException(
"Malformed appfile [%s]: manager data must be a map"%(appfile))
223 app_data = c.get(
'app', {})
224 if not type(app_data) == dict:
225 raise InvalidAppException(
"Malformed appfile [%s]: app data must be a map"%(appfile))
227 clients.append(
Client(client_type, manager_data, app_data))
233 @raise InvalidAppException: if app definition is invalid. 237 plugins = app_data.get(
'plugins',
'')
241 except ValueError
as e:
242 raise InvalidAppException(
"Malformed appfile [%s]: bad plugins entry: %s"%(appfile, e))
247 @raise InvalidAppException: if app definition is invalid. 251 plugin_order = app_data.get(
'plugin_order',
'')
252 if plugin_order ==
'':
255 except ValueError
as e:
256 raise InvalidAppException(
"Malformed appfile [%s]: bad plugin_order entry: %s"%(appfile, e))
261 @raise InvalidAppException: if app definition is invalid. 265 timeout = app_data.get(
'timeout',
'')
269 except ValueError
as e:
270 raise InvalidAppException(
"Malformed appfile [%s]: bad timeout entry: %s"%(appfile, e))
276 @raise InvalidAppExcetion: if app definition is invalid. 277 @raise IOError: I/O error reading appfile (e.g. file does not exist). 279 with open(appfile,
'r') as f: 280 app_data = yaml.load(f.read()) 281 for reqd
in [
'launch',
'interface',
'platform']:
282 if not reqd
in app_data:
283 raise InvalidAppException(
"Malformed appfile [%s], missing required key [%s]"%(appfile, reqd))
285 display_name = app_data.get(
'display', appname)
286 description = app_data.get(
'description',
'')
287 platform = app_data[
'platform']
298 return AppDefinition(appname, display_name, description, platform,
299 launch, interface, clients, icon,
300 plugins, plugin_order, timeout)
304 @raise InvalidAppExcetion: if app definition is invalid. 305 @raise NotFoundExcetion: if app definition is not installed. 306 @raise ValueError: if appname is invalid. 309 raise ValueError(
"app name is empty")
313 except ResourceNotFound
as e:
314 raise NotFoundException(
"Cannot locate app file for %s: package is not installed."%(appname))
319 if e.errno == errno.ENOENT:
320 raise NotFoundException(
"Cannot locate app file for %s."%(appname))
322 raise InternalAppException(
"I/O error loading AppDefinition file: %s."%(e.errno))
def _AppDefinition_load_launch_entry(app_data, appfile="UNKNOWN")
def load_AppDefinition_from_file(appfile, appname)
def find_resource(resource)
def __init__(self, name, display_name, description, platform, launch, interface, clients, icon=None, plugins=None, plugin_order=None, timeout=None)
def __init__(self, subscribed_topics, published_topics)
def _AppDefinition_load_interface_entry(app_data, appfile="UNKNOWN")
def _AppDefinition_load_icon_entry(app_data, appfile="UNKNOWN")
def _AppDefinition_load_clients_entry(app_data, appfile="UNKNOWN")
def __init__(self, client_type, manager_data, app_data)
def load_AppDefinition_by_name(appname)
def load_Interface_from_file(filename)
def _AppDefinition_load_plugin_order_entry(app_data, appfile="UNKNOWN")
def _AppDefinition_load_timeout_entry(app_data, appfile="UNKNOWN")
def _AppDefinition_load_plugins_entry(app_data, appfile="UNKNOWN")