Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/rpms/sugar/microformat-updater.patch
blob: a97d7474768bbc925aa51dd4bde17ff721b8d8b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
From: anishmangal2002 <anishmangal2002@gmail.com>
To: Bernie Innocenti <bernie@codewiz.org>, tch@sugarlabs.org
Date: Mon,  9 Aug 2010 21:48:03 +0530
Cc: anishmangal2002 <anishmangal2002@gmail.com>,
 dextrose@lists.sugarlabs.org
Subject: [Dextrose] [PATCH] Add microformat support to updater.


Signed-off-by: anishmangal2002 <anishmangal2002@gmail.com>
---
 .../cpsection/updater/backends/microformat.py      |  125 ++++++++++++++++++++
 extensions/cpsection/updater/model.py              |   13 +-
 2 files changed, 131 insertions(+), 7 deletions(-)
 create mode 100644 extensions/cpsection/updater/backends/microformat.py

diff --git a/extensions/cpsection/updater/backends/microformat.py b/extensions/cpsection/updater/backends/microformat.py
new file mode 100644
index 0000000..ea7dda1
--- /dev/null
+++ b/extensions/cpsection/updater/backends/microformat.py
@@ -0,0 +1,125 @@
+#!/usr/bin/python
+# Copyright (C) 2009, Sugar Labs
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+import logging
+from HTMLParser import HTMLParser
+
+import gio
+
+from jarabe import config
+
+#_UPDATE_PATH = 'http://activities.sugarlabs.org/services/update-aslo.php'
+_UPDATE_PATH = 'http://wiki.paraguayeduca.org/index.php/Actividades_Dextrose_1'
+
+_fetcher = None
+# flag indicating whether we've parsed the url once or not
+_activity_list_populated = False
+
+_ACTIVITIES_LIST = {}
+
+class _UpdateFetcher(HTMLParser):
+
+    def __init__(self, bundle, completion_cb):
+        # ASLO knows only about stable SP releases
+        major, minor = config.version.split('.')[0:2]
+        sp_version = '%s.%s' % (major, int(minor) + int(minor) % 2)
+        # Reset the HTMLParser.
+        # FIXME: Check why it does not get reset on its own.
+        self.reset()
+        self._activity_id = ''
+        self._activity_url = ''
+        self._activity_version = ''
+        self._inside_activity_version = False
+        self._inside_activity_id = False
+        self._inside_activity_url = False
+
+        url = _UPDATE_PATH
+
+        self._completion_cb = completion_cb
+        self._file = gio.File(url)
+        self._bundle = bundle
+        logging.debug('Fetch %s', url)
+        self._file.load_contents_async(self.__download_file_complete_cb)
+
+    def __download_file_complete_cb(self, gdaemonfile, result):
+        content = self._file.load_contents_finish(result)[0]
+        self.feed(content)
+
+    def handle_endtag(self, tag):
+        if tag == 'body':
+            self._completion_cb(None, None, None, None, None)
+
+    def handle_starttag(self, tag, attrs):
+        if tag == 'span':
+            for attribute,value in attrs:
+                if value == 'olpc-activity-id':
+                    self._inside_activity_id = True
+                elif value == 'olpc-activity-version':
+                    self._inside_activity_version = True
+                elif value == 'olpc-activity-url':
+                    self._inside_activity_url = True
+
+        elif tag == 'a':
+            if self._inside_activity_url:
+                for attribute,value in attrs:
+                    if attribute == 'href':
+                        self._activity_url = value
+                        self._inside_activity_url = False
+
+    def handle_data(self, data):
+        if self._inside_activity_version:
+            self._activity_version = int(data)
+            self._inside_activity_version = False
+            _ACTIVITIES_LIST[self._activity_id] = \
+                    {'version':self._activity_version,
+                            'url':self._activity_url,
+                            'size':1}
+            global _activity_list_populated
+            _activity_list_populated = True
+            if self._bundle._bundle_id == self._activity_id:
+                self._completion_cb(self._bundle, self._activity_version,
+                        self._activity_url, 0, None)
+        elif self._inside_activity_id:
+            self._activity_id = data
+            self._inside_activity_id = False
+
+def fetch_update_info(bundle, completion_cb):
+    '''Queries the server for a newer version of the ActivityBundle.
+
+       completion_cb receives bundle, version, link, size and possibly an error
+       message:
+
+       def completion_cb(bundle, version, link, size, error_message):
+    '''
+    global _fetcher
+
+    if bundle._bundle_id in _ACTIVITIES_LIST:
+        _fetcher = None
+        completion_cb(bundle,
+                _ACTIVITIES_LIST[bundle._bundle_id]['version'],
+                _ACTIVITIES_LIST[bundle._bundle_id]['url'],
+                _ACTIVITIES_LIST[bundle._bundle_id]['size'], None)
+        return
+
+    global _activity_list_populated
+    if _activity_list_populated == True:
+        completion_cb(bundle, None, None, None, None)
+    else:
+        if _fetcher is not None:
+            raise RuntimeError('Multiple simultaneous requests are not supported')
+
+        _fetcher = _UpdateFetcher(bundle, completion_cb)
diff --git a/extensions/cpsection/updater/model.py b/extensions/cpsection/updater/model.py
index 9845371..3ec6888 100755
--- a/extensions/cpsection/updater/model.py
+++ b/extensions/cpsection/updater/model.py
@@ -36,8 +36,7 @@ from sugar.bundle.activitybundle import ActivityBundle
 
 from jarabe.model import bundleregistry
 
-from backends import aslo
-
+from backends import microformat
 
 class UpdateModel(gobject.GObject):
     __gtype_name__ = 'SugarUpdateModel'
@@ -70,11 +69,11 @@ class UpdateModel(gobject.GObject):
         total = len(bundleregistry.get_registry())
         current = total - len(self._bundles_to_check)
 
-        bundle = self._bundles_to_check.pop()
-        self.emit('progress', UpdateModel.ACTION_CHECKING, bundle.get_name(),
-                  current, total)
-
-        aslo.fetch_update_info(bundle, self.__check_completed_cb)
+        if len(self._bundles_to_check):
+            bundle = self._bundles_to_check.pop()
+            self.emit('progress', UpdateModel.ACTION_CHECKING, bundle.get_name(),
+                      current, total)
+            microformat.fetch_update_info(bundle, self.__check_completed_cb)
 
     def __check_completed_cb(self, bundle, version, link, size, error_message):
         if error_message is not None:
--- sugar-0.88.1/extensions/cpsection/updater/backends/Makefile.am.orig	2010-08-13 14:18:36.000000000 -0400
+++ sugar-0.88.1/extensions/cpsection/updater/backends/Makefile.am	2010-08-13 14:21:12.000000000 -0400
@@ -2,4 +2,6 @@ sugardir = $(pkgdatadir)/extensions/cpse
 
 sugar_PYTHON = 		\
 	aslo.py		\
-	__init__.py
+	microformat.py	\
+	__init__.py	\
+	#
-- 
1.7.2.1

_______________________________________________
Dextrose mailing list
Dextrose@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/dextrose