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)):
68 print 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()
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")
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 print "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 print sys.stderr >> val
201 print sys.stderr >>
"Wget failed" 204 p = subprocess.Popen([
"sudo",
"rosget",
"update"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
205 data = p.communicate()
206 val = (data[0]
or '').strip()
207 if (p.returncode != 0):
208 self.
_on_error(
"Invalid return of update: " + str(data))
210 if (p.returncode != 0):
222 if (
not exchange_data):
224 for app
in exchange_data[
'apps']:
226 appc.name = app[
'app']
227 appc.display_name = app[
'display']
229 self.
_debs[app[
'app']] = deb
238 local_path = os.path.join(self.
_directory, app[
'app'])
239 if (os.path.exists(local_path)):
241 if (os.path.exists(os.path.join(local_path,
"app.yaml"))):
243 data = yaml.load(open(os.path.join(local_path,
"app.yaml")))
245 appc.description = data[
'description']
248 appc.description =
"Descriptionless hidden app" 250 appc.description =
"No description set, likely an error in the yaml file" 252 format = data[
'icon_format']
255 if (os.path.exists(os.path.join(local_path,
"icon" + format))
and format !=
""):
257 icon.format = format.strip(
".")
258 if (icon.format ==
"jpg"): icon.format =
"jpeg" 259 icon.data = open(os.path.join(local_path,
"icon" + format),
"rb").read()
263 installed_apps.append(appc)
264 file_apps.append(app)
266 available_apps.append(appc)
269 yaml.dump({
"apps": file_apps}, f)
def get_available_apps(self)
def get_installed_apps(self)
def get_available_version(self, deb)
def get_app_details(self, name)
def is_installed(self, deb)
def __init__(self, url, directory, on_error=lambda(x):None)
def uninstall_app(self, app)
def install_app(self, app)
def get_installed_version(self, deb)