Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-04-04 16:22:10 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-04-04 16:22:10 (GMT)
commit6b830fd21b03002eb30bd9dea01a18b7219b3dd5 (patch)
treef88a5b3f90806fc087b683862c559f59ddd1846c
parent156ebc6ff05565f4ab1f55a60bd94d7d2f5984c3 (diff)
fix downloads again
-rw-r--r--canvas.py41
-rw-r--r--utils.py30
2 files changed, 53 insertions, 18 deletions
diff --git a/canvas.py b/canvas.py
index 8e48af9..78f57fb 100644
--- a/canvas.py
+++ b/canvas.py
@@ -42,12 +42,17 @@ _logger = utils.get_logger()
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
+match_dict = {}
+
def _gen_activity(_id, parent):
+ global match_dict
_id = _id
_activity_props = parent._list[_id]
+ #print 'prop', _activity_props
bold = '<b>%s </b>'
text1 = bold % _("Description:") + _activity_props[3]
+ text7 = bold % _("ID:") + _activity_props[0]
text2 = bold % _("Version:") + _activity_props[4]
text3 = bold % _("Works with:") + (_activity_props[5] + ' - ' +\
_activity_props[6])
@@ -55,7 +60,7 @@ def _gen_activity(_id, parent):
text5 = bold % _("Downloads:") + _activity_props[8]
text6 = bold % _("Homepage:") + _activity_props[9]
text = text1 + "\n" + text2 + "\n" + text3 + "\n" + text4 + "\n" +\
- text5 + "\n" + text6
+ text5 + "\n" + text7 + "\n" + text6
pixbuf_icon = _activity_props[0]
name = "<b>%s</b>" % _activity_props[2]
@@ -66,6 +71,8 @@ def _gen_activity(_id, parent):
else:
status = _("Public")
+ match_dict[_id] = _activity_props[2]
+
info = [pixbuf_icon, name, text, status]
return info
@@ -168,6 +175,7 @@ class List(gtk.TreeView):
self.current -= 1
def _download(self, widget, row, col):
+ global match_dict
model = widget.get_model()
name = str(model[row][1]).replace("<b>", "").replace("</b>", "")
_logger.debug(_("Started download of activity: %s") % name)
@@ -179,6 +187,17 @@ class List(gtk.TreeView):
i: self._activity.remove_alert(x))
# add to download
self.download_list.add_download(name)
+ self.download_list.di[self.download_list.pos] = name
+ activity_id = -1
+ for n in match_dict:
+ if match_dict[n] == name:
+ activity_id = n
+ break
+ row = self.download_list.pos
+ #print 'el ide es', activity_id, 'down row: ', row
+ if not(activity_id) == -1:
+ utils.download_activity(int(activity_id), row, self.download_list.set_download_progress)
+ self.download_list.pos = self.download_list.pos + 1
return True
def stop_search(self, *args):
@@ -207,6 +226,8 @@ class List(gtk.TreeView):
gobject.idle_add(self.search, entry)
def _search(self):
+ global match_dict
+ match_dict = {}
w = str(self.w)
_id = -1
for iter in ITERS:
@@ -222,12 +243,14 @@ class List(gtk.TreeView):
self._add_activity(activity_widget)
self.can_search = True
-
class DownloadList(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
+ self.di = {}
+ self.pos = 0
+
self._model = gtk.ListStore(str, str, int)
self.set_model(self._model)
@@ -246,21 +269,25 @@ class DownloadList(gtk.TreeView):
self.show_all()
+
+
def add_download(self, name):
_iter = self._model.append([name, _("Starting download..."), 0])
return _iter
def set_download_progress(self, _id, progress):
+ #print 'llega id:', _id
+ i = _id
if progress <= 100:
- self._model[_id][2] = int(progress)
+ self._model[i][2] = int(progress)
if progress > 0:
- self._model[_id][1] = _("Downloading...")
+ self._model[i][1] = _("Downloading...")
if progress >= 150:
- self._model[_id][1] = _("Installing...")
- self._model[_id][2] = 100
+ self._model[i][1] = _("Installing...")
+ self._model[i][2] = 100
if progress == 200:
- self._model[_id][1] = _("Installed!")
+ self._model[i][1] = _("Installed!")
diff --git a/utils.py b/utils.py
index 86e0eb2..3238e9e 100644
--- a/utils.py
+++ b/utils.py
@@ -119,26 +119,28 @@ def get_icon(activity_id):
return pixbuf
-def download_activity(_id, progress_function):
+def download_activity(_id, row, progress_function):
"""Download (and install) an activity"""
store_list = get_store_list()
+ #print 'store', store_list
activity_obj = store_list[_id]
- name = activity_obj[1]
+ name = activity_obj[2]
name = name.lower()
name = name.replace(' ', '_')
n = activity_obj[0]
web = 'http://activities.sugarlabs.org/es-ES/sugar/downloads/latest/'
web = web + n + '/addon-' + n + '-latest.xo'
- version = activity_obj[3]
+ version = activity_obj[4]
def progress_changed(block, block_size, total_size):
downloaded = block * block_size
progress = downloaded * 100 / total_size
-
- progress_function(progress)
+ #print 'la ro', row
+ progress_function(row, progress)
xo = name + '-' + version + '.xo'
+ #print 'alan', web, xo
file_path = os.path.join(activity.get_activity_root(), "data", xo)
_logger.info(_("Downloading activity (%s)") % name)
@@ -147,23 +149,29 @@ def download_activity(_id, progress_function):
reporthook=progress_changed)
_logger.info(_("Installing activity (%s)") % name)
- install_activity(file_path, progress_function)
+ install_activity(file_path, row, progress_function)
+
+
-def install_activity(xofile, progress_function):
+
+def install_activity(xofile, row, progress_function):
"""Install an downloaded activity"""
# Show "Installing..." message
- progress_function(150)
+ progress_function(row, 150)
# Install the .xo
- bundle = ActivityBundle(xofile)
- bundle.install()
+ try:
+ bundle = ActivityBundle(xofile)
+ bundle.install()
+ except:
+ print 'fallo install'
# Remove the .xo
os.remove(xofile)
# Show "Installed..." message
- progress_function(200)
+ progress_function(row, 200)
_logger.info(_("Activity installed!"))