39 Implements exchange part of app_manager, which handles listing of 40 avialable and removable applications. 48 from std_msgs.msg
import String
49 from .msg
import ExchangeApp, Icon
52 def __init__(self, url, directory, on_error = lambda x: None):
62 if (
not os.path.exists(d)):
65 rospy.loginfo(
"Directory: {}".format(self.
_directory))
68 rospy.loginfo(subprocess.Popen([
"whoami"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate())
71 data = subprocess.Popen([
"dpkg",
"-l", deb], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
72 val = (data[0]
or '').strip()
73 for i
in val.split(
'\n'):
74 if (i.find(deb) > 0
and i.find(
"ii") == 0):
75 return [s
for s
in i.strip().split(
" ")
if s][2]
76 self.
_on_error(
"Failed to get installed version: " + str(data))
80 data = subprocess.Popen([
"apt-cache",
"showpkg", deb], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
81 val = (data[0]
or '').strip()
83 for i
in val.split(
'\n'):
85 return i.strip().split(
" ")[0].strip()
86 if (i.strip() ==
"Versions:"):
88 self.
_on_error(
"Failed to get available version: " + str(data))
92 data = subprocess.Popen([
"dpkg",
"-l", deb], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
93 val = (data[0]
or '').strip()
94 for i
in val.split(
"\n"):
96 return (i.find(
"ii") == 0)
97 self.
_on_error(
"Error getting installed packages: " + str(data))
107 local_path = os.path.join(self.
_directory, name)
108 if (
not os.path.exists(local_path)):
109 os.makedirs(local_path)
110 data = subprocess.Popen([
"wget",
"-O", os.path.join(local_path,
"app.yaml"), (self._url.strip(
'/') +
"/" + name +
".yaml")], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
111 val = (data[0]
or '').strip()
114 data = yaml.load(open(os.path.join(local_path,
"app.yaml")))
115 icon_url = data[
"icon_url"]
116 icon_format = data[
"icon_format"]
117 val = (subprocess.Popen([
"wget",
"-O", os.path.join(local_path,
"icon" + icon_format), icon_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
or '').strip()
120 rospy.logerr(
"No icon")
128 self.
_on_error(
"Problem getting app details: " + str(data))
137 deb = self.
_debs[i.name]
142 deb = self.
_debs[i.name]
144 self.
_on_error(
"No debian found for install")
146 rospy.loginfo(
"install app")
147 p = subprocess.Popen([
"sudo",
"rosget",
"install", deb], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
150 pub = rospy.Publisher(
'install_status', String)
152 for line
in iter(p.stdout.readline,
''):
153 if line.rstrip() !=
'':
154 pub.publish(line.rstrip())
159 for line
in iter(p.stderr.readline,
''):
160 if line.rstrip() !=
'':
161 pub.publish(line.rstrip())
166 data = (
''.join(l1),
''.join(l2))
167 val = (data[0]
or '').strip()
173 self.
_on_error(
"Invalid return for install: " + str(data))
182 deb = self.
_debs[i.name]
184 self.
_on_error(
"No debian found for uninstall")
186 rospy.loginfo(
"uninstall app")
187 data = subprocess.Popen([
"sudo",
"rosget",
"remove", deb], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
188 val = (data[0]
or '').strip()
193 self.
_on_error(
"Invalid return for uninstall: " + str(data))
198 val = (subprocess.Popen([
"wget",
"-O", self.
_exchange_local, self.
_url +
"/applications.yaml"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
or '').strip()
200 rospy.logerr(
"Wget failed: {}".format(val))
203 p = subprocess.Popen([
"sudo",
"rosget",
"update"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
204 data = p.communicate()
205 val = (data[0]
or '').strip()
206 if (p.returncode != 0):
207 self.
_on_error(
"Invalid return of update: " + str(data))
209 if (p.returncode != 0):
221 if (
not exchange_data):
223 for app
in exchange_data[
'apps']:
225 appc.name = app[
'app']
226 appc.display_name = app[
'display']
228 self.
_debs[app[
'app']] = deb
237 local_path = os.path.join(self.
_directory, app[
'app'])
238 if (os.path.exists(local_path)):
240 if (os.path.exists(os.path.join(local_path,
"app.yaml"))):
241 rospy.logwarn(local_path)
242 data = yaml.load(open(os.path.join(local_path,
"app.yaml")))
244 appc.description = data[
'description']
247 appc.description =
"Descriptionless hidden app" 249 appc.description =
"No description set, likely an error in the yaml file" 251 format = data[
'icon_format']
254 if (os.path.exists(os.path.join(local_path,
"icon" + format))
and format !=
""):
256 icon.format = format.strip(
".")
257 if (icon.format ==
"jpg"): icon.format =
"jpeg" 258 icon.data = open(os.path.join(local_path,
"icon" + format),
"rb").read()
262 installed_apps.append(appc)
263 file_apps.append(app)
265 available_apps.append(appc)
268 yaml.dump({
"apps": file_apps}, f)
def get_available_apps(self)
def __init__(self, url, directory, on_error=lambda x:None)
def get_installed_apps(self)
def get_available_version(self, deb)
def get_app_details(self, name)
def is_installed(self, deb)
def uninstall_app(self, app)
def install_app(self, app)
def get_installed_version(self, deb)