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']
79 def __init__(self, name, display_name, description, platform,
80 launch, interface, clients, icon=
None):
94 d[s] = [c.as_dict()
for c
in self.
clients]
96 d[s] = getattr(self, s)
101 if not isinstance(other, AppDefinition):
103 return self.
name == other.name
and \
106 self.
platform == other.platform
and \
107 self.
launch == other.launch
and \
109 self.
clients == other.clients
and \
110 self.
icon == other.icon
114 @return: filepath of resource. Does not validate if filepath actually exists. 116 @raise ValueError: if resource is not a valid resource name. 117 @raise rospkg.ResourceNotFound: if package referred 118 to in resource name cannot be found. 119 @raise NotFoundException: if resource does not exist. 121 p, a = roslib.names.package_resource_name(resource)
123 raise ValueError(
"Resource is missing package name: %s"%(resource))
124 matches = roslib.packages.find_resource(p, a)
126 if len(matches) == 1:
129 raise NotFoundException(
"No resource [%s]"%(resource))
131 raise ValueError(
"Multiple resources named [%s]"%(resource))
135 @raise IOError: I/O error reading file (e.g. does not exist) 136 @raise InvalidAppException: if app file is invalid 138 with open(filename,
'r') as f: 139 y = yaml.load(f.read()) 142 subscribed_topics = y.get(
'subscribed_topics', {})
143 published_topics = y.get(
'published_topics', {})
145 raise InvalidAppException(
"Malformed interface, missing keys")
146 return Interface(published_topics=published_topics, subscribed_topics=subscribed_topics)
150 @raise InvalidAppExcetion: if app definition is invalid. 154 icon_resource = app_data.get(
'icon',
'')
155 if icon_resource ==
'':
158 if not icon_filename
or not os.path.exists(icon_filename):
161 except ValueError
as e:
162 raise InvalidAppException(
"Malformed appfile [%s]: bad icon entry: %s"%(appfile, e))
163 except NotFoundException:
165 raise InvalidAppException(
"App file [%s] refers to icon that cannot be found"%(appfile))
166 except ResourceNotFound
as e:
167 raise InvalidAppException(
"App file [%s] refers to package that is not installed: %s"%(appfile, str(e)))
171 @raise InvalidAppExcetion: if app definition is invalid. 176 if not os.path.exists(launch):
177 raise InvalidAppException(
"Malformed appfile [%s]: refers to launch that does not exist."%(appfile))
179 except ValueError
as e:
180 raise InvalidAppException(
"Malformed appfile [%s]: bad launch entry: %s"%(appfile, e))
181 except NotFoundException:
182 raise InvalidAppException(
"App file [%s] refers to launch that is not installed"%(appfile))
183 except ResourceNotFound
as e:
184 raise InvalidAppException(
"App file [%s] refers to package that is not installed: %s"%(appfile, str(e)))
188 @raise InvalidAppExcetion: if app definition is invalid. 194 if e.errno == errno.ENOENT:
195 raise InvalidAppException(
"Malformed appfile [%s]: refers to interface file that does not exist"%(appfile))
197 raise InvalidAppException(
"Error with appfile [%s]: cannot read interface file"%(appfile))
199 raise InvalidAppException(
"Malformed appfile [%s]: bad interface entry"%(appfile))
200 except ResourceNotFound
as e:
201 raise InvalidAppException(
"App file [%s] refers to package that is not installed: %s"%(appfile, str(e)))
205 @raise InvalidAppExcetion: if app definition is invalid. 207 clients_data = app_data.get(
'clients', [])
209 for c
in clients_data:
210 for reqd
in [
'type',
'manager']:
212 raise InvalidAppException(
"Malformed appfile [%s], missing required key [%s]"%(appfile, reqd))
213 client_type = c[
'type']
214 manager_data = c[
'manager']
215 if not type(manager_data) == dict:
216 raise InvalidAppException(
"Malformed appfile [%s]: manager data must be a map"%(appfile))
218 app_data = c.get(
'app', {})
219 if not type(app_data) == dict:
220 raise InvalidAppException(
"Malformed appfile [%s]: app data must be a map"%(appfile))
222 clients.append(
Client(client_type, manager_data, app_data))
227 @raise InvalidAppExcetion: if app definition is invalid. 228 @raise IOError: I/O error reading appfile (e.g. file does not exist). 230 with open(appfile,
'r') as f: 231 app_data = yaml.load(f.read()) 232 for reqd
in [
'launch',
'interface',
'platform']:
233 if not reqd
in app_data:
234 raise InvalidAppException(
"Malformed appfile [%s], missing required key [%s]"%(appfile, reqd))
236 display_name = app_data.get(
'display', appname)
237 description = app_data.get(
'description',
'')
238 platform = app_data[
'platform']
246 return AppDefinition(appname, display_name, description, platform,
247 launch, interface, clients, icon)
251 @raise InvalidAppExcetion: if app definition is invalid. 252 @raise NotFoundExcetion: if app definition is not installed. 253 @raise ValueError: if appname is invalid. 256 raise ValueError(
"app name is empty")
260 except ResourceNotFound
as e:
261 raise NotFoundException(
"Cannot locate app file for %s: package is not installed."%(appname))
266 if e.errno == errno.ENOENT:
267 raise NotFoundException(
"Cannot locate app file for %s."%(appname))
269 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)
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)