Merge lp:~elachuni/software-center/pep8-test-part22 into lp:software-center
- pep8-test-part22
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 2879 |
Proposed branch: | lp:~elachuni/software-center/pep8-test-part22 |
Merge into: | lp:software-center |
Prerequisite: | lp:~elachuni/software-center/pep8-test-part21 |
Diff against target: |
1439 lines (+352/-291) 12 files modified
softwarecenter/backend/channel.py (+74/-54) softwarecenter/backend/fake_review_settings.py (+68/-64) softwarecenter/backend/installbackend.py (+36/-19) softwarecenter/backend/launchpad.py (+24/-13) softwarecenter/backend/login.py (+16/-14) softwarecenter/backend/login_sso.py (+29/-22) softwarecenter/backend/recagent.py (+67/-66) softwarecenter/backend/scagent.py (+27/-21) softwarecenter/hw.py (+5/-2) softwarecenter/testutils.py (+2/-3) softwarecenter/utils.py (+1/-1) test/test_pep8.py (+3/-12) |
To merge this branch: | bzr merge lp:~elachuni/software-center/pep8-test-part22 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kiwinote | Approve | ||
Review via email: mp+98205@code.launchpad.net |
Commit message
Description of the change
All code under softwarecenter/ now passes the pep8 test.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'softwarecenter/backend/channel.py' | |||
2 | --- softwarecenter/backend/channel.py 2011-12-02 14:33:49 +0000 | |||
3 | +++ softwarecenter/backend/channel.py 2012-03-19 14:27:20 +0000 | |||
4 | @@ -24,13 +24,14 @@ | |||
5 | 24 | 24 | ||
6 | 25 | from softwarecenter.distro import get_distro | 25 | from softwarecenter.distro import get_distro |
7 | 26 | 26 | ||
9 | 27 | from softwarecenter.enums import (SortMethods, | 27 | from softwarecenter.enums import (SortMethods, |
10 | 28 | Icons, | 28 | Icons, |
11 | 29 | ViewPages, | 29 | ViewPages, |
12 | 30 | ) | 30 | ) |
13 | 31 | 31 | ||
14 | 32 | LOG = logging.getLogger(__name__) | 32 | LOG = logging.getLogger(__name__) |
15 | 33 | 33 | ||
16 | 34 | |||
17 | 34 | class ChannelsManager(object): | 35 | class ChannelsManager(object): |
18 | 35 | def __init__(self, db, **kwargs): | 36 | def __init__(self, db, **kwargs): |
19 | 36 | self.distro = get_distro() | 37 | self.distro = get_distro() |
20 | @@ -52,10 +53,11 @@ | |||
21 | 52 | # private | 53 | # private |
22 | 53 | def _get_channels_from_db(self, installed_only=False): | 54 | def _get_channels_from_db(self, installed_only=False): |
23 | 54 | """ | 55 | """ |
25 | 55 | (internal) implements 'channels()' and 'channels_installed_only()' properties | 56 | (internal) implements 'channels()' and 'channels_installed_only()' |
26 | 57 | properties | ||
27 | 56 | """ | 58 | """ |
28 | 57 | distro_channel_origin = self.distro.get_distro_channel_name() | 59 | distro_channel_origin = self.distro.get_distro_channel_name() |
30 | 58 | 60 | ||
31 | 59 | # gather the set of software channels and order them | 61 | # gather the set of software channels and order them |
32 | 60 | other_channel_list = [] | 62 | other_channel_list = [] |
33 | 61 | cached_origins = [] | 63 | cached_origins = [] |
34 | @@ -64,12 +66,13 @@ | |||
35 | 64 | continue | 66 | continue |
36 | 65 | channel_name = channel_iter.term[3:] | 67 | channel_name = channel_iter.term[3:] |
37 | 66 | channel_origin = "" | 68 | channel_origin = "" |
39 | 67 | 69 | ||
40 | 68 | # get origin information for this channel | 70 | # get origin information for this channel |
41 | 69 | m = self.db.xapiandb.postlist_begin(channel_iter.term) | 71 | m = self.db.xapiandb.postlist_begin(channel_iter.term) |
42 | 70 | doc = self.db.xapiandb.get_document(m.get_docid()) | 72 | doc = self.db.xapiandb.get_document(m.get_docid()) |
43 | 71 | for term_iter in doc.termlist(): | 73 | for term_iter in doc.termlist(): |
45 | 72 | if term_iter.term.startswith("XOO") and len(term_iter.term) > 3: | 74 | if (term_iter.term.startswith("XOO") and |
46 | 75 | len(term_iter.term) > 3): | ||
47 | 73 | channel_origin = term_iter.term[3:] | 76 | channel_origin = term_iter.term[3:] |
48 | 74 | break | 77 | break |
49 | 75 | LOG.debug("channel_name: %s" % channel_name) | 78 | LOG.debug("channel_name: %s" % channel_name) |
50 | @@ -77,7 +80,7 @@ | |||
51 | 77 | if channel_origin not in cached_origins: | 80 | if channel_origin not in cached_origins: |
52 | 78 | other_channel_list.append((channel_name, channel_origin)) | 81 | other_channel_list.append((channel_name, channel_origin)) |
53 | 79 | cached_origins.append(channel_origin) | 82 | cached_origins.append(channel_origin) |
55 | 80 | 83 | ||
56 | 81 | dist_channel = None | 84 | dist_channel = None |
57 | 82 | other_channels = [] | 85 | other_channels = [] |
58 | 83 | unknown_channel = [] | 86 | unknown_channel = [] |
59 | @@ -85,26 +88,30 @@ | |||
60 | 85 | 88 | ||
61 | 86 | for (channel_name, channel_origin) in other_channel_list: | 89 | for (channel_name, channel_origin) in other_channel_list: |
62 | 87 | if not channel_name: | 90 | if not channel_name: |
67 | 88 | unknown_channel.append(SoftwareChannel(channel_name, | 91 | unknown_channel.append(SoftwareChannel( |
68 | 89 | channel_origin, | 92 | channel_name, |
69 | 90 | None, | 93 | channel_origin, |
70 | 91 | installed_only=installed_only)) | 94 | None, |
71 | 95 | installed_only=installed_only)) | ||
72 | 92 | elif channel_origin == distro_channel_origin: | 96 | elif channel_origin == distro_channel_origin: |
77 | 93 | dist_channel = (SoftwareChannel(channel_name, | 97 | dist_channel = (SoftwareChannel( |
78 | 94 | channel_origin, | 98 | channel_name, |
79 | 95 | None, | 99 | channel_origin, |
80 | 96 | installed_only=installed_only)) | 100 | None, |
81 | 101 | installed_only=installed_only)) | ||
82 | 97 | elif channel_name == "notdownloadable": | 102 | elif channel_name == "notdownloadable": |
83 | 98 | if installed_only: | 103 | if installed_only: |
88 | 99 | local_channel = SoftwareChannel(channel_name, | 104 | local_channel = SoftwareChannel( |
89 | 100 | None, | 105 | channel_name, |
90 | 101 | None, | 106 | None, |
91 | 102 | installed_only=installed_only) | 107 | None, |
92 | 108 | installed_only=installed_only) | ||
93 | 103 | else: | 109 | else: |
98 | 104 | other_channels.append(SoftwareChannel(channel_name, | 110 | other_channels.append(SoftwareChannel( |
99 | 105 | channel_origin, | 111 | channel_name, |
100 | 106 | None, | 112 | channel_origin, |
101 | 107 | installed_only=installed_only)) | 113 | None, |
102 | 114 | installed_only=installed_only)) | ||
103 | 108 | 115 | ||
104 | 109 | # set them in order | 116 | # set them in order |
105 | 110 | channels = [] | 117 | channels = [] |
106 | @@ -122,13 +129,14 @@ | |||
107 | 122 | channel._channel_view_id = ViewPages.AVAILABLE | 129 | channel._channel_view_id = ViewPages.AVAILABLE |
108 | 123 | return channels | 130 | return channels |
109 | 124 | 131 | ||
110 | 132 | |||
111 | 125 | class SoftwareChannel(object): | 133 | class SoftwareChannel(object): |
112 | 126 | """ | 134 | """ |
113 | 127 | class to represent a software channel | 135 | class to represent a software channel |
114 | 128 | """ | 136 | """ |
116 | 129 | 137 | ||
117 | 130 | ICON_SIZE = 24 | 138 | ICON_SIZE = 24 |
119 | 131 | 139 | ||
120 | 132 | def __init__(self, channel_name, channel_origin, channel_component, | 140 | def __init__(self, channel_name, channel_origin, channel_component, |
121 | 133 | source_entry=None, installed_only=False, | 141 | source_entry=None, installed_only=False, |
122 | 134 | channel_icon=None, channel_query=None, | 142 | channel_icon=None, channel_query=None, |
123 | @@ -148,13 +156,16 @@ | |||
124 | 148 | # distro specific stuff | 156 | # distro specific stuff |
125 | 149 | self.distro = get_distro() | 157 | self.distro = get_distro() |
126 | 150 | # configure the channel | 158 | # configure the channel |
128 | 151 | self._channel_display_name = self._get_display_name_for_channel(channel_name, channel_origin, channel_component) | 159 | self._channel_display_name = self._get_display_name_for_channel( |
129 | 160 | channel_name, channel_origin, channel_component) | ||
130 | 152 | if channel_icon is None: | 161 | if channel_icon is None: |
132 | 153 | self._channel_icon = self._get_icon_for_channel(channel_name, channel_origin, channel_component) | 162 | self._channel_icon = self._get_icon_for_channel( |
133 | 163 | channel_name, channel_origin, channel_component) | ||
134 | 154 | else: | 164 | else: |
135 | 155 | self._channel_icon = channel_icon | 165 | self._channel_icon = channel_icon |
136 | 156 | if channel_query is None: | 166 | if channel_query is None: |
138 | 157 | self._channel_query = self._get_channel_query_for_channel(channel_name, channel_origin, channel_component) | 167 | self._channel_query = self._get_channel_query_for_channel( |
139 | 168 | channel_name, channel_origin, channel_component) | ||
140 | 158 | else: | 169 | else: |
141 | 159 | self._channel_query = channel_query | 170 | self._channel_query = channel_query |
142 | 160 | # a sources.list entry attached to the channel (this is currently | 171 | # a sources.list entry attached to the channel (this is currently |
143 | @@ -162,36 +173,36 @@ | |||
144 | 162 | self._source_entry = source_entry | 173 | self._source_entry = source_entry |
145 | 163 | # when the channel needs to be added to the systems sources.list | 174 | # when the channel needs to be added to the systems sources.list |
146 | 164 | self.needs_adding = False | 175 | self.needs_adding = False |
148 | 165 | 176 | ||
149 | 166 | @property | 177 | @property |
150 | 167 | def name(self): | 178 | def name(self): |
151 | 168 | """ | 179 | """ |
152 | 169 | return the channel name as represented in the xapian database | 180 | return the channel name as represented in the xapian database |
153 | 170 | """ | 181 | """ |
154 | 171 | return self._channel_name | 182 | return self._channel_name |
157 | 172 | 183 | ||
158 | 173 | @property | 184 | @property |
159 | 174 | def origin(self): | 185 | def origin(self): |
160 | 175 | """ | 186 | """ |
161 | 176 | return the channel origin as represented in the xapian database | 187 | return the channel origin as represented in the xapian database |
162 | 177 | """ | 188 | """ |
163 | 178 | return self._channel_origin | 189 | return self._channel_origin |
166 | 179 | 190 | ||
167 | 180 | @property | 191 | @property |
168 | 181 | def component(self): | 192 | def component(self): |
169 | 182 | """ | 193 | """ |
170 | 183 | return the channel component as represented in the xapian database | 194 | return the channel component as represented in the xapian database |
171 | 184 | """ | 195 | """ |
172 | 185 | return self._channel_component | 196 | return self._channel_component |
175 | 186 | 197 | ||
176 | 187 | @property | 198 | @property |
177 | 188 | def display_name(self): | 199 | def display_name(self): |
178 | 189 | """ | 200 | """ |
179 | 190 | return the display name for the corresponding channel for use in the UI | 201 | return the display name for the corresponding channel for use in the UI |
180 | 191 | """ | 202 | """ |
181 | 192 | return self._channel_display_name | 203 | return self._channel_display_name |
184 | 193 | 204 | ||
185 | 194 | @property | 205 | @property |
186 | 195 | def icon(self): | 206 | def icon(self): |
187 | 196 | """ | 207 | """ |
188 | 197 | return the icon that corresponds to each channel based | 208 | return the icon that corresponds to each channel based |
189 | @@ -205,18 +216,19 @@ | |||
190 | 205 | return the xapian query to be used with this software channel | 216 | return the xapian query to be used with this software channel |
191 | 206 | """ | 217 | """ |
192 | 207 | return self._channel_query | 218 | return self._channel_query |
195 | 208 | 219 | ||
196 | 209 | @property | 220 | @property |
197 | 210 | def sort_mode(self): | 221 | def sort_mode(self): |
198 | 211 | """ | 222 | """ |
199 | 212 | return the sort mode for this software channel | 223 | return the sort mode for this software channel |
200 | 213 | """ | 224 | """ |
201 | 214 | return self._channel_sort_mode | 225 | return self._channel_sort_mode |
203 | 215 | 226 | ||
204 | 216 | # TODO: implement __cmp__ so that sort for channels is encapsulated | 227 | # TODO: implement __cmp__ so that sort for channels is encapsulated |
205 | 217 | # here as well | 228 | # here as well |
206 | 218 | 229 | ||
208 | 219 | def _get_display_name_for_channel(self, channel_name, channel_origin, channel_component): | 230 | def _get_display_name_for_channel(self, channel_name, channel_origin, |
209 | 231 | channel_component): | ||
210 | 220 | if channel_component == "partner": | 232 | if channel_component == "partner": |
211 | 221 | channel_display_name = _("Canonical Partners") | 233 | channel_display_name = _("Canonical Partners") |
212 | 222 | elif not channel_origin: | 234 | elif not channel_origin: |
213 | @@ -232,8 +244,9 @@ | |||
214 | 232 | else: | 244 | else: |
215 | 233 | return channel_name | 245 | return channel_name |
216 | 234 | return channel_display_name | 246 | return channel_display_name |
219 | 235 | 247 | ||
220 | 236 | def _get_icon_for_channel(self, channel_name, channel_origin, channel_component): | 248 | def _get_icon_for_channel(self, channel_name, channel_origin, |
221 | 249 | channel_component): | ||
222 | 237 | if channel_component == "partner": | 250 | if channel_component == "partner": |
223 | 238 | channel_icon = "partner" | 251 | channel_icon = "partner" |
224 | 239 | elif not channel_name: | 252 | elif not channel_name: |
225 | @@ -253,16 +266,17 @@ | |||
226 | 253 | else: | 266 | else: |
227 | 254 | channel_icon = "unknown-channel" | 267 | channel_icon = "unknown-channel" |
228 | 255 | return channel_icon | 268 | return channel_icon |
232 | 256 | 269 | ||
233 | 257 | def _get_channel_query_for_channel(self, channel_name, channel_origin, channel_component): | 270 | def _get_channel_query_for_channel(self, channel_name, channel_origin, |
234 | 258 | 271 | channel_component): | |
235 | 272 | |||
236 | 259 | if channel_component == "partner": | 273 | if channel_component == "partner": |
237 | 260 | q1 = xapian.Query("XOCpartner") | 274 | q1 = xapian.Query("XOCpartner") |
238 | 261 | q2 = xapian.Query("AH%s-partner" % self.distro.get_codename()) | 275 | q2 = xapian.Query("AH%s-partner" % self.distro.get_codename()) |
239 | 262 | channel_query = xapian.Query(xapian.Query.OP_OR, q1, q2) | 276 | channel_query = xapian.Query(xapian.Query.OP_OR, q1, q2) |
240 | 263 | # show only apps when displaying the new apps archive | 277 | # show only apps when displaying the new apps archive |
241 | 264 | elif channel_name == "Application Review Board PPA": | 278 | elif channel_name == "Application Review Board PPA": |
243 | 265 | channel_query = xapian.Query(xapian.Query.OP_AND, | 279 | channel_query = xapian.Query(xapian.Query.OP_AND, |
244 | 266 | xapian.Query("XOL" + channel_name), | 280 | xapian.Query("XOL" + channel_name), |
245 | 267 | xapian.Query("ATapplication")) | 281 | xapian.Query("ATapplication")) |
246 | 268 | elif channel_origin: | 282 | elif channel_origin: |
247 | @@ -292,14 +306,14 @@ | |||
248 | 292 | self, channel_name, "all", None, | 306 | self, channel_name, "all", None, |
249 | 293 | installed_only=installed_only, | 307 | installed_only=installed_only, |
250 | 294 | channel_icon=Icons.FALLBACK) | 308 | channel_icon=Icons.FALLBACK) |
251 | 295 | return | ||
252 | 296 | 309 | ||
253 | 297 | # overrides | 310 | # overrides |
255 | 298 | def _get_display_name_for_channel(self, channel_name, channel_origin, channel_component): | 311 | def _get_display_name_for_channel(self, channel_name, channel_origin, |
256 | 312 | channel_component): | ||
257 | 299 | return channel_name | 313 | return channel_name |
258 | 300 | 314 | ||
259 | 301 | def _get_channel_query_for_channel(self, *args): | 315 | def _get_channel_query_for_channel(self, *args): |
261 | 302 | return None | 316 | pass |
262 | 303 | 317 | ||
263 | 304 | 318 | ||
264 | 305 | class AllAvailableChannel(AllChannel): | 319 | class AllAvailableChannel(AllChannel): |
265 | @@ -313,28 +327,34 @@ | |||
266 | 313 | def __init__(self): | 327 | def __init__(self): |
267 | 314 | AllChannel.__init__(self, _("All Installed"), True) | 328 | AllChannel.__init__(self, _("All Installed"), True) |
268 | 315 | 329 | ||
269 | 330 | |||
270 | 316 | # singleton | 331 | # singleton |
271 | 317 | channels_manager = None | 332 | channels_manager = None |
272 | 333 | |||
273 | 334 | |||
274 | 318 | def get_channels_manager(db): | 335 | def get_channels_manager(db): |
275 | 319 | global channels_manager | 336 | global channels_manager |
276 | 320 | if channels_manager is None: | 337 | if channels_manager is None: |
277 | 321 | from softwarecenter.enums import USE_PACKAGEKIT_BACKEND | 338 | from softwarecenter.enums import USE_PACKAGEKIT_BACKEND |
278 | 322 | if not USE_PACKAGEKIT_BACKEND: | 339 | if not USE_PACKAGEKIT_BACKEND: |
280 | 323 | from softwarecenter.backend.channel_impl.aptchannels import AptChannelsManager | 340 | from softwarecenter.backend.channel_impl.aptchannels import ( |
281 | 341 | AptChannelsManager) | ||
282 | 324 | channels_manager = AptChannelsManager(db) | 342 | channels_manager = AptChannelsManager(db) |
283 | 325 | else: | 343 | else: |
284 | 326 | channels_manager = ChannelsManager(db) | 344 | channels_manager = ChannelsManager(db) |
285 | 327 | return channels_manager | 345 | return channels_manager |
286 | 328 | 346 | ||
287 | 347 | |||
288 | 329 | def is_channel_available(channelname): | 348 | def is_channel_available(channelname): |
290 | 330 | from softwarecenter.backend.channel_impl.aptchannels import AptChannelsManager | 349 | from softwarecenter.backend.channel_impl.aptchannels import ( |
291 | 350 | AptChannelsManager) | ||
292 | 331 | return AptChannelsManager.channel_available(channelname) | 351 | return AptChannelsManager.channel_available(channelname) |
293 | 332 | 352 | ||
294 | 333 | if __name__ == "__main__": | 353 | if __name__ == "__main__": |
295 | 334 | distro = get_distro() | 354 | distro = get_distro() |
297 | 335 | channel = SoftwareChannel(distro.get_distro_channel_name(), | 355 | channel = SoftwareChannel(distro.get_distro_channel_name(), |
298 | 336 | None, None) | 356 | None, None) |
299 | 337 | print(channel) | 357 | print(channel) |
301 | 338 | channel = SoftwareChannel(distro.get_distro_channel_name(), None, "partner") | 358 | channel = SoftwareChannel(distro.get_distro_channel_name(), None, |
302 | 359 | "partner") | ||
303 | 339 | print(channel) | 360 | print(channel) |
304 | 340 | |||
305 | 341 | 361 | ||
306 | === modified file 'softwarecenter/backend/fake_review_settings.py' | |||
307 | --- softwarecenter/backend/fake_review_settings.py 2011-08-09 08:47:43 +0000 | |||
308 | +++ softwarecenter/backend/fake_review_settings.py 2012-03-19 14:27:20 +0000 | |||
309 | @@ -4,7 +4,8 @@ | |||
310 | 4 | import pickle | 4 | import pickle |
311 | 5 | from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR | 5 | from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR |
312 | 6 | 6 | ||
314 | 7 | # decorator to add a fake network delay if set | 7 | |
315 | 8 | # decorator to add a fake network delay if set | ||
316 | 8 | # in FakeReviewSettings.fake_network_delay | 9 | # in FakeReviewSettings.fake_network_delay |
317 | 9 | def network_delay(fn): | 10 | def network_delay(fn): |
318 | 10 | def slp(self, *args, **kwargs): | 11 | def slp(self, *args, **kwargs): |
319 | @@ -14,23 +15,25 @@ | |||
320 | 14 | time.sleep(delay) | 15 | time.sleep(delay) |
321 | 15 | return fn(self, *args, **kwargs) | 16 | return fn(self, *args, **kwargs) |
322 | 16 | return slp | 17 | return slp |
324 | 17 | 18 | ||
325 | 19 | |||
326 | 18 | class FakeReviewSettings(object): | 20 | class FakeReviewSettings(object): |
337 | 19 | '''An object that simply holds settings which are used by RatingsAndReviewsAPI | 21 | '''An object that simply holds settings which are used by |
338 | 20 | in the rnrclient_fake module. Using this module allows a developer to test | 22 | RatingsAndReviewsAPI in the rnrclient_fake module. Using this module |
339 | 21 | the reviews functionality without any interaction with a reviews server. | 23 | allows a developer to test the reviews functionality without any |
340 | 22 | Each setting here provides complete control over how the 'server' will | 24 | interaction with a reviews server. Each setting here provides complete |
341 | 23 | respond. Changes to these settings should be made to the class attributes | 25 | control over how the 'server' will respond. Changes to these settings |
342 | 24 | directly without creating an instance of this class. | 26 | should be made to the class attributes directly without creating an |
343 | 25 | The intended usage is for unit tests where a predictable response is | 27 | instance of this class. |
344 | 26 | required and where the application should THINK it has spoken to a | 28 | The intended usage is for unit tests where a predictable response is |
345 | 27 | server. | 29 | required and where the application should THINK it has spoken to a |
346 | 28 | The unit test would make changes to settings in this class before | 30 | server. |
347 | 31 | The unit test would make changes to settings in this class before | ||
348 | 29 | running the unit test. | 32 | running the unit test. |
349 | 30 | ''' | 33 | ''' |
351 | 31 | 34 | ||
352 | 32 | _FAKE_SETTINGS = {} | 35 | _FAKE_SETTINGS = {} |
354 | 33 | 36 | ||
355 | 34 | #general settings | 37 | #general settings |
356 | 35 | #***************************** | 38 | #***************************** |
357 | 36 | #delay (in seconds) before returning from any of the fake rnr methods | 39 | #delay (in seconds) before returning from any of the fake rnr methods |
358 | @@ -41,45 +44,46 @@ | |||
359 | 41 | #***************************** | 44 | #***************************** |
360 | 42 | #raises APIError if True | 45 | #raises APIError if True |
361 | 43 | _FAKE_SETTINGS['server_response_error'] = False | 46 | _FAKE_SETTINGS['server_response_error'] = False |
363 | 44 | 47 | ||
364 | 45 | #review stats | 48 | #review stats |
365 | 46 | #***************************** | 49 | #***************************** |
366 | 47 | #raises APIError if True | 50 | #raises APIError if True |
369 | 48 | _FAKE_SETTINGS['review_stats_error'] = False | 51 | _FAKE_SETTINGS['review_stats_error'] = False |
370 | 49 | 52 | ||
371 | 50 | #the following has no effect if review_stats_error = True | 53 | #the following has no effect if review_stats_error = True |
374 | 51 | #determines the number of package stats (i.e. ReviewStats list size) to return | 54 | #determines the number of package stats (i.e. ReviewStats list size) to |
375 | 52 | #max 15 packages (any number higher than 15 will still return 15) | 55 | #return max 15 packages (any number higher than 15 will still return 15) |
376 | 53 | _FAKE_SETTINGS['packages_returned'] = 10 | 56 | _FAKE_SETTINGS['packages_returned'] = 10 |
378 | 54 | 57 | ||
379 | 55 | #get reviews | 58 | #get reviews |
380 | 56 | #***************************** | 59 | #***************************** |
381 | 57 | #raises APIError if True | 60 | #raises APIError if True |
382 | 58 | _FAKE_SETTINGS['get_reviews_error'] = False | 61 | _FAKE_SETTINGS['get_reviews_error'] = False |
383 | 59 | 62 | ||
386 | 60 | #number of pages of 10 reviews to return before returning the number specified | 63 | #number of pages of 10 reviews to return before returning the number |
387 | 61 | #in the reviews_returned value below | 64 | # specified in the reviews_returned value below |
388 | 62 | _FAKE_SETTINGS['review_pages'] = 1 | 65 | _FAKE_SETTINGS['review_pages'] = 1 |
389 | 63 | 66 | ||
390 | 64 | #the following has no effect if get_reviews_error = True | 67 | #the following has no effect if get_reviews_error = True |
392 | 65 | #determines number of reviews to return | 68 | #determines number of reviews to return |
393 | 66 | # (Accepts 0 to n but should really be between 1 and 10) | 69 | # (Accepts 0 to n but should really be between 1 and 10) |
394 | 67 | _FAKE_SETTINGS['reviews_returned'] = 3 | 70 | _FAKE_SETTINGS['reviews_returned'] = 3 |
396 | 68 | 71 | ||
397 | 69 | #get review | 72 | #get review |
398 | 70 | #***************************** | 73 | #***************************** |
399 | 71 | #raises APIError if True | 74 | #raises APIError if True |
400 | 72 | _FAKE_SETTINGS['get_review_error'] = False | 75 | _FAKE_SETTINGS['get_review_error'] = False |
402 | 73 | 76 | ||
403 | 74 | #submit review | 77 | #submit review |
404 | 75 | #***************************** | 78 | #***************************** |
405 | 76 | #raises APIError if True | 79 | #raises APIError if True |
406 | 77 | _FAKE_SETTINGS['submit_review_error'] = False | 80 | _FAKE_SETTINGS['submit_review_error'] = False |
408 | 78 | #fake username(str) and review_id(int) to give back with a successful review | 81 | #fake username(str) and review_id(int) to give back with a successful |
409 | 82 | # review | ||
410 | 79 | #leave as None to generate a random username and review_id | 83 | #leave as None to generate a random username and review_id |
411 | 80 | _FAKE_SETTINGS['reviewer_username'] = None | 84 | _FAKE_SETTINGS['reviewer_username'] = None |
412 | 81 | _FAKE_SETTINGS['submit_review_id'] = None | 85 | _FAKE_SETTINGS['submit_review_id'] = None |
414 | 82 | 86 | ||
415 | 83 | #flag review | 87 | #flag review |
416 | 84 | #***************************** | 88 | #***************************** |
417 | 85 | #raises APIError if True | 89 | #raises APIError if True |
418 | @@ -88,43 +92,43 @@ | |||
419 | 88 | _FAKE_SETTINGS['flagger_username'] = None | 92 | _FAKE_SETTINGS['flagger_username'] = None |
420 | 89 | #fake package name (str) to give back as flagged app | 93 | #fake package name (str) to give back as flagged app |
421 | 90 | _FAKE_SETTINGS['flag_package_name'] = None | 94 | _FAKE_SETTINGS['flag_package_name'] = None |
423 | 91 | 95 | ||
424 | 92 | #submit usefulness | 96 | #submit usefulness |
425 | 93 | #***************************** | 97 | #***************************** |
426 | 94 | #raises APIError if True | 98 | #raises APIError if True |
427 | 95 | _FAKE_SETTINGS['submit_usefulness_error'] = False | 99 | _FAKE_SETTINGS['submit_usefulness_error'] = False |
429 | 96 | 100 | ||
430 | 97 | #the following has no effect if submit_usefulness_error = True | 101 | #the following has no effect if submit_usefulness_error = True |
431 | 98 | #which string to pretend the server returned | 102 | #which string to pretend the server returned |
432 | 99 | #choices are "Created", "Updated", "Not modified" | 103 | #choices are "Created", "Updated", "Not modified" |
433 | 100 | _FAKE_SETTINGS['usefulness_response_string'] = "Created" | 104 | _FAKE_SETTINGS['usefulness_response_string'] = "Created" |
435 | 101 | 105 | ||
436 | 102 | #get usefulness | 106 | #get usefulness |
437 | 103 | #***************************** | 107 | #***************************** |
438 | 104 | #raises APIError if True | 108 | #raises APIError if True |
439 | 105 | _FAKE_SETTINGS['get_usefulness_error'] = False | 109 | _FAKE_SETTINGS['get_usefulness_error'] = False |
441 | 106 | 110 | ||
442 | 107 | #the following has no effect if get_usefulness_error = True | 111 | #the following has no effect if get_usefulness_error = True |
443 | 108 | #how many usefulness votes to return | 112 | #how many usefulness votes to return |
444 | 109 | _FAKE_SETTINGS['votes_returned'] = 5 | 113 | _FAKE_SETTINGS['votes_returned'] = 5 |
447 | 110 | 114 | ||
448 | 111 | #pre-configured review ids to return in the result | 115 | #pre-configured review ids to return in the result |
449 | 112 | #if you don't complete this or enter less review ids than votes_returned | 116 | #if you don't complete this or enter less review ids than votes_returned |
450 | 113 | #above, it will be random | 117 | #above, it will be random |
453 | 114 | _FAKE_SETTINGS['required_review_ids'] = [3,6,15] | 118 | _FAKE_SETTINGS['required_review_ids'] = [3, 6, 15] |
454 | 115 | 119 | ||
455 | 116 | #THE FOLLOWING SETTINGS RELATE TO LOGIN SSO FUNCTIONALITY | 120 | #THE FOLLOWING SETTINGS RELATE TO LOGIN SSO FUNCTIONALITY |
456 | 117 | # LoginBackendDbusSSO | 121 | # LoginBackendDbusSSO |
457 | 118 | # login() | 122 | # login() |
458 | 119 | #*********************** | 123 | #*********************** |
460 | 120 | # what to fake the login response as | 124 | # what to fake the login response as |
461 | 121 | # choices (strings): "successful", "failed", "denied" | 125 | # choices (strings): "successful", "failed", "denied" |
462 | 122 | _FAKE_SETTINGS['login_response'] = "successful" | 126 | _FAKE_SETTINGS['login_response'] = "successful" |
464 | 123 | 127 | ||
465 | 124 | # UbuntuSSOAPI | 128 | # UbuntuSSOAPI |
466 | 125 | # whoami() | 129 | # whoami() |
467 | 126 | #*********************** | 130 | #*********************** |
469 | 127 | # what to fake whoami response as | 131 | # what to fake whoami response as |
470 | 128 | # choices (strings): "whoami", "error" | 132 | # choices (strings): "whoami", "error" |
471 | 129 | _FAKE_SETTINGS['whoami_response'] = "whoami" | 133 | _FAKE_SETTINGS['whoami_response'] = "whoami" |
472 | 130 | #this only has effect if whoami_response = 'whoami' | 134 | #this only has effect if whoami_response = 'whoami' |
473 | @@ -132,65 +136,65 @@ | |||
474 | 132 | #expects a string or None (for a random username) | 136 | #expects a string or None (for a random username) |
475 | 133 | _FAKE_SETTINGS['whoami_username'] = None | 137 | _FAKE_SETTINGS['whoami_username'] = None |
476 | 134 | 138 | ||
477 | 135 | |||
478 | 136 | def __init__(self, defaults=False): | 139 | def __init__(self, defaults=False): |
484 | 137 | '''Initialises the object and loads the settings into the _FAKE_SETTINGS | 140 | '''Initialises the object and loads the settings into the |
485 | 138 | dict.. If defaults is passed as True any existing settings in the cache | 141 | _FAKE_SETTINGS dict.. If defaults is passed as True any existing |
486 | 139 | file are ignored and the cache file is overwritten with the defaults | 142 | settings in the cache file are ignored and the cache file is |
487 | 140 | set in the class. This is useful if you don't want previously used | 143 | overwritten with the defaults set in the class. This is useful if |
488 | 141 | settings from the cache file being used again''' | 144 | you don't want previously used settings from the cache file being |
489 | 145 | used again''' | ||
490 | 142 | fname = 'fake_review_settings.p' | 146 | fname = 'fake_review_settings.p' |
491 | 143 | self.LOCATION = os.path.join(SOFTWARE_CENTER_CACHE_DIR, fname) | 147 | self.LOCATION = os.path.join(SOFTWARE_CENTER_CACHE_DIR, fname) |
492 | 144 | if defaults: | 148 | if defaults: |
493 | 145 | self._save_settings() | 149 | self._save_settings() |
494 | 146 | else: | 150 | else: |
495 | 147 | self._update_from_file() | 151 | self._update_from_file() |
498 | 148 | return | 152 | |
497 | 149 | |||
499 | 150 | def update_setting(self, key_name, new_value): | 153 | def update_setting(self, key_name, new_value): |
502 | 151 | '''Takes a string (key_name) which corresponds to a setting in this object | 154 | '''Takes a string (key_name) which corresponds to a setting in this |
503 | 152 | and updates it with the value passed in (new_value). | 155 | object and updates it with the value passed in (new_value). |
504 | 153 | Raises a NameError if the setting name doesn't exist''' | 156 | Raises a NameError if the setting name doesn't exist''' |
506 | 154 | 157 | ||
507 | 155 | if not key_name in self._FAKE_SETTINGS: | 158 | if not key_name in self._FAKE_SETTINGS: |
509 | 156 | raise NameError ('Setting key name %s does not exist' % key_name) | 159 | raise NameError('Setting key name %s does not exist' % key_name) |
510 | 157 | else: | 160 | else: |
511 | 158 | self._FAKE_SETTINGS[key_name] = new_value | 161 | self._FAKE_SETTINGS[key_name] = new_value |
512 | 159 | self._save_settings() | 162 | self._save_settings() |
513 | 160 | return | 163 | return |
515 | 161 | 164 | ||
516 | 162 | def update_multiple(self, settings): | 165 | def update_multiple(self, settings): |
520 | 163 | '''Takes a dict (settings) of key,value pairs to perform multiple updates | 166 | '''Takes a dict (settings) of key,value pairs to perform multiple |
521 | 164 | in one action, then saves. Dict being passed should contain only keys that | 167 | updates in one action, then saves. Dict being passed should contain |
522 | 165 | match settings in this object or a NameError will be raised''' | 168 | only keys that match settings in this object or a NameError will be |
523 | 169 | raised''' | ||
524 | 166 | for key, value in settings.items(): | 170 | for key, value in settings.items(): |
525 | 167 | if not key in self._FAKE_SETTINGS: | 171 | if not key in self._FAKE_SETTINGS: |
528 | 168 | raise NameError ('Setting key name %s does not exist' % key) | 172 | raise NameError('Setting key name %s does not exist' % key) |
529 | 169 | 173 | ||
530 | 170 | for key, value in settings.items(): | 174 | for key, value in settings.items(): |
531 | 171 | self._FAKE_SETTINGS[key] = value | 175 | self._FAKE_SETTINGS[key] = value |
532 | 172 | self._save_settings() | 176 | self._save_settings() |
533 | 173 | return | 177 | return |
535 | 174 | 178 | ||
536 | 175 | def get_setting(self, key_name): | 179 | def get_setting(self, key_name): |
540 | 176 | '''Takes a string (key_name) which corresponds to a setting in this object, | 180 | '''Takes a string (key_name) which corresponds to a setting in this |
541 | 177 | gets the latest copy of it from the file and returns the setting. | 181 | object, gets the latest copy of it from the file and returns the |
542 | 178 | Raises a NameError if the setting name doesn't exist''' | 182 | setting. Raises a NameError if the setting name doesn't exist''' |
543 | 179 | if not key_name in self._FAKE_SETTINGS: | 183 | if not key_name in self._FAKE_SETTINGS: |
545 | 180 | raise NameError ('Setting %s does not exist' % key_name) | 184 | raise NameError('Setting %s does not exist' % key_name) |
546 | 181 | else: | 185 | else: |
547 | 182 | self._update_from_file() | 186 | self._update_from_file() |
548 | 183 | return self._FAKE_SETTINGS[key_name] | 187 | return self._FAKE_SETTINGS[key_name] |
550 | 184 | 188 | ||
551 | 185 | def _update_from_file(self): | 189 | def _update_from_file(self): |
552 | 186 | '''Loads existing settings from cache file into _FAKE_SETTINGS dict''' | 190 | '''Loads existing settings from cache file into _FAKE_SETTINGS dict''' |
553 | 187 | if os.path.exists(self.LOCATION): | 191 | if os.path.exists(self.LOCATION): |
554 | 188 | try: | 192 | try: |
555 | 189 | self._FAKE_SETTINGS = pickle.load(open(self.LOCATION)) | 193 | self._FAKE_SETTINGS = pickle.load(open(self.LOCATION)) |
556 | 190 | except: | 194 | except: |
558 | 191 | os.rename(self.LOCATION, self.LOCATION+".fail") | 195 | os.rename(self.LOCATION, self.LOCATION + ".fail") |
559 | 192 | return | 196 | return |
561 | 193 | 197 | ||
562 | 194 | def _save_settings(self): | 198 | def _save_settings(self): |
563 | 195 | """write the dict out to cache file""" | 199 | """write the dict out to cache file""" |
564 | 196 | try: | 200 | try: |
565 | 197 | 201 | ||
566 | === modified file 'softwarecenter/backend/installbackend.py' | |||
567 | --- softwarecenter/backend/installbackend.py 2012-02-07 16:56:40 +0000 | |||
568 | +++ softwarecenter/backend/installbackend.py 2012-03-19 14:27:20 +0000 | |||
569 | @@ -18,32 +18,46 @@ | |||
570 | 18 | 18 | ||
571 | 19 | from softwarecenter.utils import UnimplementedError | 19 | from softwarecenter.utils import UnimplementedError |
572 | 20 | 20 | ||
573 | 21 | |||
574 | 21 | class InstallBackend(object): | 22 | class InstallBackend(object): |
575 | 22 | def __init__(self): | 23 | def __init__(self): |
576 | 23 | self.pending_transactions = {} | 24 | self.pending_transactions = {} |
577 | 24 | self.pending_purchases = [] | 25 | self.pending_purchases = [] |
578 | 25 | 26 | ||
591 | 26 | def upgrade(self, app, iconname, addons_install=[], addons_remove=[], metadata=None): | 27 | def upgrade(self, app, iconname, addons_install=[], addons_remove=[], |
592 | 27 | pass | 28 | metadata=None): |
593 | 28 | def remove(self, app, iconname, addons_install=[], addons_remove=[], metadata=None): | 29 | pass |
594 | 29 | pass | 30 | |
595 | 30 | def remove_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None): | 31 | def remove(self, app, iconname, addons_install=[], addons_remove=[], |
596 | 31 | pass | 32 | metadata=None): |
597 | 32 | def install(self, app, iconname, filename=None, addons_install=[], addons_remove=[], metadata=None): | 33 | pass |
598 | 33 | pass | 34 | |
599 | 34 | def install_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None): | 35 | def remove_multiple(self, apps, iconnames, addons_install=[], |
600 | 35 | pass | 36 | addons_remove=[], metadatas=None): |
601 | 36 | def apply_changes(self, app, iconname, addons_install=[], addons_remove=[], metadata=None): | 37 | pass |
602 | 37 | pass | 38 | |
603 | 39 | def install(self, app, iconname, filename=None, addons_install=[], | ||
604 | 40 | addons_remove=[], metadata=None): | ||
605 | 41 | pass | ||
606 | 42 | |||
607 | 43 | def install_multiple(self, apps, iconnames, addons_install=[], | ||
608 | 44 | addons_remove=[], metadatas=None): | ||
609 | 45 | pass | ||
610 | 46 | |||
611 | 47 | def apply_changes(self, app, iconname, addons_install=[], | ||
612 | 48 | addons_remove=[], metadata=None): | ||
613 | 49 | pass | ||
614 | 50 | |||
615 | 38 | def reload(self, sources_list=None, metadata=None): | 51 | def reload(self, sources_list=None, metadata=None): |
616 | 39 | """ reload package list """ | 52 | """ reload package list """ |
617 | 40 | pass | 53 | pass |
618 | 41 | 54 | ||
619 | 55 | |||
620 | 42 | class InstallBackendUI(object): | 56 | class InstallBackendUI(object): |
621 | 43 | 57 | ||
622 | 44 | def ask_config_file_conflict(self, old, new): | 58 | def ask_config_file_conflict(self, old, new): |
623 | 45 | """ show a conffile conflict and ask what to do | 59 | """ show a conffile conflict and ask what to do |
625 | 46 | Return "keep" to keep the old one | 60 | Return "keep" to keep the old one |
626 | 47 | "replace" to replace the old with the new one | 61 | "replace" to replace the old with the new one |
627 | 48 | """ | 62 | """ |
628 | 49 | raise UnimplementedError("need custom ask_config_file_conflict method") | 63 | raise UnimplementedError("need custom ask_config_file_conflict method") |
629 | @@ -53,24 +67,27 @@ | |||
630 | 53 | return True if medium is provided, False to cancel | 67 | return True if medium is provided, False to cancel |
631 | 54 | """ | 68 | """ |
632 | 55 | raise UnimplementedError("need custom ask_medium_required method") | 69 | raise UnimplementedError("need custom ask_medium_required method") |
635 | 56 | 70 | ||
636 | 57 | def error(self, parent, primary, secondary, details=None, alternative_action=None): | 71 | def error(self, parent, primary, secondary, details=None, |
637 | 72 | alternative_action=None): | ||
638 | 58 | """ show an error dialog """ | 73 | """ show an error dialog """ |
639 | 59 | raise UnimplementedError("need custom error method") | 74 | raise UnimplementedError("need custom error method") |
640 | 60 | 75 | ||
641 | 61 | 76 | ||
642 | 62 | # singleton | 77 | # singleton |
643 | 63 | install_backend = None | 78 | install_backend = None |
644 | 79 | |||
645 | 80 | |||
646 | 64 | def get_install_backend(): | 81 | def get_install_backend(): |
647 | 65 | global install_backend | 82 | global install_backend |
648 | 66 | if install_backend is None: | 83 | if install_backend is None: |
649 | 67 | from softwarecenter.enums import USE_PACKAGEKIT_BACKEND | 84 | from softwarecenter.enums import USE_PACKAGEKIT_BACKEND |
650 | 68 | if not USE_PACKAGEKIT_BACKEND: | 85 | if not USE_PACKAGEKIT_BACKEND: |
652 | 69 | from softwarecenter.backend.installbackend_impl.aptd import AptdaemonBackend | 86 | from softwarecenter.backend.installbackend_impl.aptd import ( |
653 | 87 | AptdaemonBackend) | ||
654 | 70 | install_backend = AptdaemonBackend() | 88 | install_backend = AptdaemonBackend() |
655 | 71 | else: | 89 | else: |
657 | 72 | from softwarecenter.backend.installbackend_impl.packagekitd import PackagekitBackend | 90 | from softwarecenter.backend.installbackend_impl.packagekitd \ |
658 | 91 | import PackagekitBackend | ||
659 | 73 | install_backend = PackagekitBackend() | 92 | install_backend = PackagekitBackend() |
660 | 74 | return install_backend | 93 | return install_backend |
661 | 75 | |||
662 | 76 | |||
663 | 77 | 94 | ||
664 | === modified file 'softwarecenter/backend/launchpad.py' | |||
665 | --- softwarecenter/backend/launchpad.py 2012-02-13 19:56:12 +0000 | |||
666 | +++ softwarecenter/backend/launchpad.py 2012-03-19 14:27:20 +0000 | |||
667 | @@ -35,7 +35,7 @@ | |||
668 | 35 | # py3 compat | 35 | # py3 compat |
669 | 36 | try: | 36 | try: |
670 | 37 | from queue import Queue | 37 | from queue import Queue |
672 | 38 | Queue # pyflakes | 38 | Queue # pyflakes |
673 | 39 | except ImportError: | 39 | except ImportError: |
674 | 40 | from Queue import Queue | 40 | from Queue import Queue |
675 | 41 | 41 | ||
676 | @@ -55,16 +55,18 @@ | |||
677 | 55 | LOGIN_STATE_AUTH_FAILURE = "auth-fail" | 55 | LOGIN_STATE_AUTH_FAILURE = "auth-fail" |
678 | 56 | LOGIN_STATE_USER_CANCEL = "user-cancel" | 56 | LOGIN_STATE_USER_CANCEL = "user-cancel" |
679 | 57 | 57 | ||
680 | 58 | |||
681 | 58 | class UserCancelException(Exception): | 59 | class UserCancelException(Exception): |
682 | 59 | """ user pressed cancel """ | 60 | """ user pressed cancel """ |
683 | 60 | pass | 61 | pass |
684 | 61 | 62 | ||
685 | 63 | |||
686 | 62 | class LaunchpadlibWorker(threading.Thread): | 64 | class LaunchpadlibWorker(threading.Thread): |
687 | 63 | """The launchpadlib worker thread - it does not touch the UI | 65 | """The launchpadlib worker thread - it does not touch the UI |
688 | 64 | and only communicates via the following: | 66 | and only communicates via the following: |
689 | 65 | 67 | ||
690 | 66 | "login_state" - the current LOGIN_STATE_* value | 68 | "login_state" - the current LOGIN_STATE_* value |
692 | 67 | 69 | ||
693 | 68 | To input reviews call "queue_review()" | 70 | To input reviews call "queue_review()" |
694 | 69 | When no longer needed, call "shutdown()" | 71 | When no longer needed, call "shutdown()" |
695 | 70 | """ | 72 | """ |
696 | @@ -128,7 +130,7 @@ | |||
697 | 128 | try: | 130 | try: |
698 | 129 | self._launchpad = Launchpad.login_with( | 131 | self._launchpad = Launchpad.login_with( |
699 | 130 | 'software-center', SERVICE_ROOT, cachedir, | 132 | 'software-center', SERVICE_ROOT, cachedir, |
701 | 131 | allow_access_levels = access_level, | 133 | allow_access_levels=access_level, |
702 | 132 | authorizer_class=AuthorizeRequestTokenFromThread) | 134 | authorizer_class=AuthorizeRequestTokenFromThread) |
703 | 133 | self.display_name = self._launchpad.me.display_name | 135 | self.display_name = self._launchpad.me.display_name |
704 | 134 | except Exception as e: | 136 | except Exception as e: |
705 | @@ -141,7 +143,8 @@ | |||
706 | 141 | (service_root, launchpadlib_dir, cache_path, | 143 | (service_root, launchpadlib_dir, cache_path, |
707 | 142 | service_root_dir) = Launchpad._get_paths(SERVICE_ROOT, cachedir) | 144 | service_root_dir) = Launchpad._get_paths(SERVICE_ROOT, cachedir) |
708 | 143 | credentials_path = os.path.join(service_root_dir, 'credentials') | 145 | credentials_path = os.path.join(service_root_dir, 'credentials') |
710 | 144 | consumer_credentials_path = os.path.join(credentials_path, 'software-center') | 146 | consumer_credentials_path = os.path.join(credentials_path, |
711 | 147 | 'software-center') | ||
712 | 145 | # --- | 148 | # --- |
713 | 146 | if os.path.exists(consumer_credentials_path): | 149 | if os.path.exists(consumer_credentials_path): |
714 | 147 | os.remove(consumer_credentials_path) | 150 | os.remove(consumer_credentials_path) |
715 | @@ -150,11 +153,12 @@ | |||
716 | 150 | self.login_state = LOGIN_STATE_SUCCESS | 153 | self.login_state = LOGIN_STATE_SUCCESS |
717 | 151 | self._logger.debug("/done %s" % self._launchpad) | 154 | self._logger.debug("/done %s" % self._launchpad) |
718 | 152 | 155 | ||
719 | 156 | |||
720 | 153 | class AuthorizeRequestTokenFromThread(RequestTokenAuthorizationEngine): | 157 | class AuthorizeRequestTokenFromThread(RequestTokenAuthorizationEngine): |
721 | 154 | """ Internal helper that updates the login_state of | 158 | """ Internal helper that updates the login_state of |
722 | 155 | the modul global lp_worker_thread object | 159 | the modul global lp_worker_thread object |
723 | 156 | """ | 160 | """ |
725 | 157 | def __init__ (self, *args, **kwargs): | 161 | def __init__(self, *args, **kwargs): |
726 | 158 | super(AuthorizeRequestTokenFromThread, self).__init__(*args, **kwargs) | 162 | super(AuthorizeRequestTokenFromThread, self).__init__(*args, **kwargs) |
727 | 159 | self._logger = logging.getLogger("softwarecenter.backend") | 163 | self._logger = logging.getLogger("softwarecenter.backend") |
728 | 160 | 164 | ||
729 | @@ -167,7 +171,7 @@ | |||
730 | 167 | return o | 171 | return o |
731 | 168 | 172 | ||
732 | 169 | def input_username(self, cached_username, suggested_message): | 173 | def input_username(self, cached_username, suggested_message): |
734 | 170 | self._logger.debug( "input_username: %s" %self.lp_worker.login_state) | 174 | self._logger.debug("input_username: %s" % self.lp_worker.login_state) |
735 | 171 | # otherwise go into ASK state | 175 | # otherwise go into ASK state |
736 | 172 | if not self.lp_worker.login_state in (LOGIN_STATE_ASK_USER_AND_PASS, | 176 | if not self.lp_worker.login_state in (LOGIN_STATE_ASK_USER_AND_PASS, |
737 | 173 | LOGIN_STATE_AUTH_FAILURE, | 177 | LOGIN_STATE_AUTH_FAILURE, |
738 | @@ -185,7 +189,8 @@ | |||
739 | 185 | return self.lp_worker.login_username | 189 | return self.lp_worker.login_username |
740 | 186 | 190 | ||
741 | 187 | def input_password(self, suggested_message): | 191 | def input_password(self, suggested_message): |
743 | 188 | self._logger.debug( "Input password size %s" % len(self.lp_worker.login_password)) | 192 | self._logger.debug("Input password size %s" % |
744 | 193 | len(self.lp_worker.login_password)) | ||
745 | 189 | return self.lp_worker.login_password | 194 | return self.lp_worker.login_password |
746 | 190 | 195 | ||
747 | 191 | def input_access_level(self, available_levels, suggested_message, | 196 | def input_access_level(self, available_levels, suggested_message, |
748 | @@ -217,7 +222,7 @@ | |||
749 | 217 | """ | 222 | """ |
750 | 218 | 223 | ||
751 | 219 | NEW_ACCOUNT_URL = "https://login.launchpad.net/+standalone-login" | 224 | NEW_ACCOUNT_URL = "https://login.launchpad.net/+standalone-login" |
753 | 220 | FORGOT_PASSWORD_URL = "https://login.launchpad.net/+standalone-login" | 225 | FORGOT_PASSWORD_URL = "https://login.launchpad.net/+standalone-login" |
754 | 221 | 226 | ||
755 | 222 | def __init__(self): | 227 | def __init__(self): |
756 | 223 | LoginBackend.__init__(self) | 228 | LoginBackend.__init__(self) |
757 | @@ -238,13 +243,13 @@ | |||
758 | 238 | lp_worker_thread.shutdown() | 243 | lp_worker_thread.shutdown() |
759 | 239 | 244 | ||
760 | 240 | def enter_username_password(self, user, password): | 245 | def enter_username_password(self, user, password): |
762 | 241 | """ | 246 | """ |
763 | 242 | provider username and password, ususally used when the | 247 | provider username and password, ususally used when the |
764 | 243 | need-username-password signal was send | 248 | need-username-password signal was send |
765 | 244 | """ | 249 | """ |
766 | 245 | lp_worker_thread.login_username = user | 250 | lp_worker_thread.login_username = user |
767 | 246 | lp_worker_thread.login_password = password | 251 | lp_worker_thread.login_password = password |
769 | 247 | lp_worker_thread.login_state = LOGIN_STATE_HAS_USER_AND_PASS | 252 | lp_worker_thread.login_state = LOGIN_STATE_HAS_USER_AND_PASS |
770 | 248 | 253 | ||
771 | 249 | def login(self, username=None, password=None): | 254 | def login(self, username=None, password=None): |
772 | 250 | if username and password: | 255 | if username and password: |
773 | @@ -254,17 +259,17 @@ | |||
774 | 254 | 259 | ||
775 | 255 | def cancel_login(self): | 260 | def cancel_login(self): |
776 | 256 | lp_worker_thread.login_state = LOGIN_STATE_USER_CANCEL | 261 | lp_worker_thread.login_state = LOGIN_STATE_USER_CANCEL |
778 | 257 | 262 | ||
779 | 258 | def get_subscribed_archives(self): | 263 | def get_subscribed_archives(self): |
780 | 259 | """ return list of sources.list entries """ | 264 | """ return list of sources.list entries """ |
781 | 260 | urls = lp_worker_thread._launchpad.me.getArchiveSubscriptionURLs() | 265 | urls = lp_worker_thread._launchpad.me.getArchiveSubscriptionURLs() |
782 | 261 | return self._format_archive_subscription_urls_as_deb_lines(urls) | 266 | return self._format_archive_subscription_urls_as_deb_lines(urls) |
784 | 262 | 267 | ||
785 | 263 | def _format_archive_subscription_urls_as_deb_lines(self, urls): | 268 | def _format_archive_subscription_urls_as_deb_lines(self, urls): |
786 | 264 | deb_lines = ["deb %s %s main" % (url, self.distro.get_codename()) \ | 269 | deb_lines = ["deb %s %s main" % (url, self.distro.get_codename()) \ |
787 | 265 | for url in urls] | 270 | for url in urls] |
788 | 266 | return deb_lines | 271 | return deb_lines |
790 | 267 | 272 | ||
791 | 268 | def get_subscribed_archives_async(self, callback): | 273 | def get_subscribed_archives_async(self, callback): |
792 | 269 | """ get the available subscribed archives and run 'callback' when | 274 | """ get the available subscribed archives and run 'callback' when |
793 | 270 | they become availalbe | 275 | they become availalbe |
794 | @@ -300,10 +305,16 @@ | |||
795 | 300 | print ("success %s" % lp) | 305 | print ("success %s" % lp) |
796 | 301 | print(lp.get_subscribed_archives()) | 306 | print(lp.get_subscribed_archives()) |
797 | 302 | print(lp.get_subscribed_archives_async(_result_callback)) | 307 | print(lp.get_subscribed_archives_async(_result_callback)) |
798 | 308 | |||
799 | 309 | |||
800 | 303 | def _login_failed(lp): | 310 | def _login_failed(lp): |
801 | 304 | print ("fail %s" % lp) | 311 | print ("fail %s" % lp) |
802 | 312 | |||
803 | 313 | |||
804 | 305 | def _result_callback(result_list): | 314 | def _result_callback(result_list): |
805 | 306 | print("_result_callback %s" % result_list) | 315 | print("_result_callback %s" % result_list) |
806 | 316 | |||
807 | 317 | |||
808 | 307 | def _login_need_user_and_password(lp): | 318 | def _login_need_user_and_password(lp): |
809 | 308 | import sys | 319 | import sys |
810 | 309 | sys.stdout.write("user: ") | 320 | sys.stdout.write("user: ") |
811 | 310 | 321 | ||
812 | === modified file 'softwarecenter/backend/login.py' | |||
813 | --- softwarecenter/backend/login.py 2012-01-05 15:01:43 +0000 | |||
814 | +++ softwarecenter/backend/login.py 2012-03-19 14:27:20 +0000 | |||
815 | @@ -21,31 +21,33 @@ | |||
816 | 21 | 21 | ||
817 | 22 | from gi.repository import GObject | 22 | from gi.repository import GObject |
818 | 23 | 23 | ||
819 | 24 | |||
820 | 24 | class LoginBackend(GObject.GObject): | 25 | class LoginBackend(GObject.GObject): |
821 | 25 | 26 | ||
822 | 26 | NEW_ACCOUNT_URL = None | 27 | NEW_ACCOUNT_URL = None |
823 | 27 | FORGOT_PASSWORD_URL = None | 28 | FORGOT_PASSWORD_URL = None |
824 | 28 | 29 | ||
825 | 29 | __gsignals__ = { | 30 | __gsignals__ = { |
828 | 30 | "login-successful" : (GObject.SIGNAL_RUN_LAST, | 31 | "login-successful": (GObject.SIGNAL_RUN_LAST, |
829 | 31 | GObject.TYPE_NONE, | 32 | GObject.TYPE_NONE, |
830 | 32 | (GObject.TYPE_PYOBJECT,), | 33 | (GObject.TYPE_PYOBJECT,), |
831 | 33 | ), | 34 | ), |
844 | 34 | "login-failed" : (GObject.SIGNAL_RUN_LAST, | 35 | "login-failed": (GObject.SIGNAL_RUN_LAST, |
845 | 35 | GObject.TYPE_NONE, | 36 | GObject.TYPE_NONE, |
846 | 36 | (), | 37 | (), |
847 | 37 | ), | 38 | ), |
848 | 38 | "login-canceled" : (GObject.SIGNAL_RUN_LAST, | 39 | "login-canceled": (GObject.SIGNAL_RUN_LAST, |
849 | 39 | GObject.TYPE_NONE, | 40 | GObject.TYPE_NONE, |
850 | 40 | (), | 41 | (), |
851 | 41 | ), | 42 | ), |
852 | 42 | "need-username-password" : (GObject.SIGNAL_RUN_LAST, | 43 | "need-username-password": (GObject.SIGNAL_RUN_LAST, |
853 | 43 | GObject.TYPE_NONE, | 44 | GObject.TYPE_NONE, |
854 | 44 | (), | 45 | (), |
855 | 45 | ), | 46 | ), |
856 | 46 | } | 47 | } |
857 | 47 | 48 | ||
858 | 48 | def login(self, username=None, password=None): | 49 | def login(self, username=None, password=None): |
859 | 49 | raise NotImplemented | 50 | raise NotImplemented |
860 | 51 | |||
861 | 50 | def cancel_login(self): | 52 | def cancel_login(self): |
862 | 51 | self.emit("login-canceled") | 53 | self.emit("login-canceled") |
863 | 52 | 54 | ||
864 | === modified file 'softwarecenter/backend/login_sso.py' | |||
865 | --- softwarecenter/backend/login_sso.py 2012-03-14 15:45:47 +0000 | |||
866 | +++ softwarecenter/backend/login_sso.py 2012-03-19 14:27:20 +0000 | |||
867 | @@ -36,6 +36,7 @@ | |||
868 | 36 | 36 | ||
869 | 37 | LOG = logging.getLogger(__name__) | 37 | LOG = logging.getLogger(__name__) |
870 | 38 | 38 | ||
871 | 39 | |||
872 | 39 | class LoginBackendDbusSSO(LoginBackend): | 40 | class LoginBackendDbusSSO(LoginBackend): |
873 | 40 | 41 | ||
874 | 41 | def __init__(self, window_id, appname, help_text): | 42 | def __init__(self, window_id, appname, help_text): |
875 | @@ -45,11 +46,11 @@ | |||
876 | 45 | self.bus = dbus.SessionBus() | 46 | self.bus = dbus.SessionBus() |
877 | 46 | self.proxy = self.bus.get_object( | 47 | self.proxy = self.bus.get_object( |
878 | 47 | 'com.ubuntu.sso', '/com/ubuntu/sso/credentials') | 48 | 'com.ubuntu.sso', '/com/ubuntu/sso/credentials') |
880 | 48 | self.proxy.connect_to_signal("CredentialsFound", | 49 | self.proxy.connect_to_signal("CredentialsFound", |
881 | 49 | self._on_credentials_found) | 50 | self._on_credentials_found) |
883 | 50 | self.proxy.connect_to_signal("CredentialsError", | 51 | self.proxy.connect_to_signal("CredentialsError", |
884 | 51 | self._on_credentials_error) | 52 | self._on_credentials_error) |
886 | 52 | self.proxy.connect_to_signal("AuthorizationDenied", | 53 | self.proxy.connect_to_signal("AuthorizationDenied", |
887 | 53 | self._on_authorization_denied) | 54 | self._on_authorization_denied) |
888 | 54 | self._window_id = window_id | 55 | self._window_id = window_id |
889 | 55 | self._credentials = None | 56 | self._credentials = None |
890 | @@ -66,7 +67,7 @@ | |||
891 | 66 | LOG.debug("login()") | 67 | LOG.debug("login()") |
892 | 67 | self._credentials = None | 68 | self._credentials = None |
893 | 68 | self.proxy.login(self.appname, self._get_params()) | 69 | self.proxy.login(self.appname, self._get_params()) |
895 | 69 | 70 | ||
896 | 70 | def login_or_register(self): | 71 | def login_or_register(self): |
897 | 71 | LOG.debug("login_or_register()") | 72 | LOG.debug("login_or_register()") |
898 | 72 | self._credentials = None | 73 | self._credentials = None |
899 | @@ -82,7 +83,6 @@ | |||
900 | 82 | if self._credentials != credentials: | 83 | if self._credentials != credentials: |
901 | 83 | self.emit("login-successful", credentials) | 84 | self.emit("login-successful", credentials) |
902 | 84 | self._credentials = credentials | 85 | self._credentials = credentials |
903 | 85 | |||
904 | 86 | 86 | ||
905 | 87 | def _on_credentials_error(self, app_name, error, detailed_error=""): | 87 | def _on_credentials_error(self, app_name, error, detailed_error=""): |
906 | 88 | LOG.error("_on_credentails_error for %s: %s (%s)" % ( | 88 | LOG.error("_on_credentails_error for %s: %s (%s)" % ( |
907 | @@ -107,55 +107,62 @@ | |||
908 | 107 | self.help_text = help_text | 107 | self.help_text = help_text |
909 | 108 | self._window_id = window_id | 108 | self._window_id = window_id |
910 | 109 | self._fake_settings = FakeReviewSettings() | 109 | self._fake_settings = FakeReviewSettings() |
912 | 110 | 110 | ||
913 | 111 | @network_delay | 111 | @network_delay |
914 | 112 | def login(self, username=None, password=None): | 112 | def login(self, username=None, password=None): |
915 | 113 | response = self._fake_settings.get_setting('login_response') | 113 | response = self._fake_settings.get_setting('login_response') |
917 | 114 | 114 | ||
918 | 115 | if response == "successful": | 115 | if response == "successful": |
919 | 116 | self.emit("login-successful", self._return_credentials()) | 116 | self.emit("login-successful", self._return_credentials()) |
920 | 117 | elif response == "failed": | 117 | elif response == "failed": |
921 | 118 | self.emit("login-failed") | 118 | self.emit("login-failed") |
922 | 119 | elif response == "denied": | 119 | elif response == "denied": |
923 | 120 | self.cancel_login() | 120 | self.cancel_login() |
925 | 121 | 121 | ||
926 | 122 | return | 122 | return |
928 | 123 | 123 | ||
929 | 124 | def login_or_register(self): | 124 | def login_or_register(self): |
930 | 125 | #fake functionality for this is no different to fake login() | 125 | #fake functionality for this is no different to fake login() |
931 | 126 | self.login() | 126 | self.login() |
932 | 127 | return | 127 | return |
934 | 128 | 128 | ||
935 | 129 | def _random_unicode_string(self, length): | 129 | def _random_unicode_string(self, length): |
936 | 130 | retval = '' | 130 | retval = '' |
938 | 131 | for i in range(0,length): | 131 | for i in range(0, length): |
939 | 132 | retval = retval + random.choice(string.letters + string.digits) | 132 | retval = retval + random.choice(string.letters + string.digits) |
940 | 133 | return retval.decode('utf-8') | 133 | return retval.decode('utf-8') |
942 | 134 | 134 | ||
943 | 135 | def _return_credentials(self): | 135 | def _return_credentials(self): |
945 | 136 | c = dbus.Dictionary( | 136 | c = dbus.Dictionary( |
946 | 137 | { | 137 | { |
953 | 138 | dbus.String(u'consumer_secret'): dbus.String(self._random_unicode_string(30)), | 138 | dbus.String(u'consumer_secret'): dbus.String( |
954 | 139 | dbus.String(u'token') : dbus.String(self._random_unicode_string(50)), | 139 | self._random_unicode_string(30)), |
955 | 140 | dbus.String(u'consumer_key') : dbus.String(self._random_unicode_string(7)), | 140 | dbus.String(u'token'): dbus.String( |
956 | 141 | dbus.String(u'name') : dbus.String('Ubuntu Software Center @ ' + self._random_unicode_string(6)), | 141 | self._random_unicode_string(50)), |
957 | 142 | dbus.String(u'token_secret') : dbus.String(self._random_unicode_string(50)) | 142 | dbus.String(u'consumer_key'): dbus.String( |
958 | 143 | }, | 143 | self._random_unicode_string(7)), |
959 | 144 | dbus.String(u'name'): dbus.String('Ubuntu Software Center @ ' + | ||
960 | 145 | self._random_unicode_string(6)), | ||
961 | 146 | dbus.String(u'token_secret'): dbus.String( | ||
962 | 147 | self._random_unicode_string(50)) | ||
963 | 148 | }, | ||
964 | 144 | signature=dbus.Signature('ss') | 149 | signature=dbus.Signature('ss') |
965 | 145 | ) | 150 | ) |
966 | 146 | return c | 151 | return c |
967 | 147 | 152 | ||
968 | 153 | |||
969 | 148 | def get_sso_backend(window_id, appname, help_text): | 154 | def get_sso_backend(window_id, appname, help_text): |
971 | 149 | """ | 155 | """ |
972 | 150 | factory that returns an sso loader singelton | 156 | factory that returns an sso loader singelton |
973 | 151 | """ | 157 | """ |
974 | 152 | if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ: | 158 | if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ: |
975 | 153 | sso_class = LoginBackendDbusSSOFake(window_id, appname, help_text) | 159 | sso_class = LoginBackendDbusSSOFake(window_id, appname, help_text) |
977 | 154 | LOG.warn('Using fake login SSO functionality. Only meant for testing purposes') | 160 | LOG.warn('Using fake login SSO functionality. Only meant for ' |
978 | 161 | 'testing purposes') | ||
979 | 155 | else: | 162 | else: |
980 | 156 | sso_class = LoginBackendDbusSSO(window_id, appname, help_text) | 163 | sso_class = LoginBackendDbusSSO(window_id, appname, help_text) |
981 | 157 | return sso_class | 164 | return sso_class |
983 | 158 | 165 | ||
984 | 159 | if __name__ == "__main__": | 166 | if __name__ == "__main__": |
985 | 160 | logging.basicConfig(level=logging.DEBUG) | 167 | logging.basicConfig(level=logging.DEBUG) |
986 | 161 | 168 | ||
987 | 162 | 169 | ||
988 | === modified file 'softwarecenter/backend/recagent.py' | |||
989 | --- softwarecenter/backend/recagent.py 2012-03-12 21:28:10 +0000 | |||
990 | +++ softwarecenter/backend/recagent.py 2012-03-19 14:27:20 +0000 | |||
991 | @@ -31,47 +31,48 @@ | |||
992 | 31 | 31 | ||
993 | 32 | LOG = logging.getLogger(__name__) | 32 | LOG = logging.getLogger(__name__) |
994 | 33 | 33 | ||
995 | 34 | |||
996 | 34 | class RecommenderAgent(GObject.GObject): | 35 | class RecommenderAgent(GObject.GObject): |
997 | 35 | 36 | ||
998 | 36 | __gsignals__ = { | 37 | __gsignals__ = { |
1035 | 37 | "server-status" : (GObject.SIGNAL_RUN_LAST, | 38 | "server-status": (GObject.SIGNAL_RUN_LAST, |
1036 | 38 | GObject.TYPE_NONE, | 39 | GObject.TYPE_NONE, |
1037 | 39 | (GObject.TYPE_PYOBJECT,), | 40 | (GObject.TYPE_PYOBJECT,), |
1038 | 40 | ), | 41 | ), |
1039 | 41 | "profile" : (GObject.SIGNAL_RUN_LAST, | 42 | "profile": (GObject.SIGNAL_RUN_LAST, |
1040 | 42 | GObject.TYPE_NONE, | 43 | GObject.TYPE_NONE, |
1041 | 43 | (GObject.TYPE_PYOBJECT,), | 44 | (GObject.TYPE_PYOBJECT,), |
1042 | 44 | ), | 45 | ), |
1043 | 45 | "submit-profile-finished" : (GObject.SIGNAL_RUN_LAST, | 46 | "submit-profile-finished": (GObject.SIGNAL_RUN_LAST, |
1044 | 46 | GObject.TYPE_NONE, | 47 | GObject.TYPE_NONE, |
1045 | 47 | (GObject.TYPE_PYOBJECT, str), | 48 | (GObject.TYPE_PYOBJECT, str), |
1046 | 48 | ), | 49 | ), |
1047 | 49 | "submit-anon-profile-finished" : (GObject.SIGNAL_RUN_LAST, | 50 | "submit-anon-profile-finished": (GObject.SIGNAL_RUN_LAST, |
1048 | 50 | GObject.TYPE_NONE, | 51 | GObject.TYPE_NONE, |
1049 | 51 | (GObject.TYPE_PYOBJECT,), | 52 | (GObject.TYPE_PYOBJECT,), |
1050 | 52 | ), | 53 | ), |
1051 | 53 | "recommend-me" : (GObject.SIGNAL_RUN_LAST, | 54 | "recommend-me": (GObject.SIGNAL_RUN_LAST, |
1052 | 54 | GObject.TYPE_NONE, | 55 | GObject.TYPE_NONE, |
1053 | 55 | (GObject.TYPE_PYOBJECT,), | 56 | (GObject.TYPE_PYOBJECT,), |
1054 | 56 | ), | 57 | ), |
1055 | 57 | "recommend-app" : (GObject.SIGNAL_RUN_LAST, | 58 | "recommend-app": (GObject.SIGNAL_RUN_LAST, |
1056 | 58 | GObject.TYPE_NONE, | 59 | GObject.TYPE_NONE, |
1057 | 59 | (GObject.TYPE_PYOBJECT,), | 60 | (GObject.TYPE_PYOBJECT,), |
1058 | 60 | ), | 61 | ), |
1059 | 61 | "recommend-all-apps" : (GObject.SIGNAL_RUN_LAST, | 62 | "recommend-all-apps": (GObject.SIGNAL_RUN_LAST, |
1060 | 62 | GObject.TYPE_NONE, | 63 | GObject.TYPE_NONE, |
1061 | 63 | (GObject.TYPE_PYOBJECT,), | 64 | (GObject.TYPE_PYOBJECT,), |
1062 | 64 | ), | 65 | ), |
1063 | 65 | "recommend-top" : (GObject.SIGNAL_RUN_LAST, | 66 | "recommend-top": (GObject.SIGNAL_RUN_LAST, |
1064 | 66 | GObject.TYPE_NONE, | 67 | GObject.TYPE_NONE, |
1065 | 67 | (GObject.TYPE_PYOBJECT,), | 68 | (GObject.TYPE_PYOBJECT,), |
1066 | 68 | ), | 69 | ), |
1067 | 69 | "error" : (GObject.SIGNAL_RUN_LAST, | 70 | "error": (GObject.SIGNAL_RUN_LAST, |
1068 | 70 | GObject.TYPE_NONE, | 71 | GObject.TYPE_NONE, |
1069 | 71 | (str,), | 72 | (str,), |
1070 | 72 | ), | 73 | ), |
1071 | 73 | } | 74 | } |
1073 | 74 | 75 | ||
1074 | 75 | def __init__(self, xid=None): | 76 | def __init__(self, xid=None): |
1075 | 76 | GObject.GObject.__init__(self) | 77 | GObject.GObject.__init__(self) |
1076 | 77 | self.xid = xid | 78 | self.xid = xid |
1077 | @@ -86,17 +87,17 @@ | |||
1078 | 86 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) | 87 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) |
1079 | 87 | spawner.run_generic_piston_helper( | 88 | spawner.run_generic_piston_helper( |
1080 | 88 | "SoftwareCenterRecommenderAPI", "server_status") | 89 | "SoftwareCenterRecommenderAPI", "server_status") |
1082 | 89 | 90 | ||
1083 | 90 | def post_submit_profile(self, db): | 91 | def post_submit_profile(self, db): |
1084 | 91 | """ This will post the users profile to the recommender server | 92 | """ This will post the users profile to the recommender server |
1086 | 92 | and also generate the UUID for the user if that is not | 93 | and also generate the UUID for the user if that is not |
1087 | 93 | there yet | 94 | there yet |
1088 | 94 | """ | 95 | """ |
1089 | 95 | # if we have not already set a recommender UUID, now is the time | 96 | # if we have not already set a recommender UUID, now is the time |
1090 | 96 | # to do it | 97 | # to do it |
1091 | 97 | if not self.recommender_uuid: | 98 | if not self.recommender_uuid: |
1092 | 98 | self.recommender_uuid = get_uuid() | 99 | self.recommender_uuid = get_uuid() |
1094 | 99 | installed_pkglist = [app.pkgname | 100 | installed_pkglist = [app.pkgname |
1095 | 100 | for app in get_installed_apps_list(db)] | 101 | for app in get_installed_apps_list(db)] |
1096 | 101 | data = self._generate_submit_profile_data(self.recommender_uuid, | 102 | data = self._generate_submit_profile_data(self.recommender_uuid, |
1097 | 102 | installed_pkglist) | 103 | installed_pkglist) |
1098 | @@ -110,7 +111,7 @@ | |||
1099 | 110 | "SoftwareCenterRecommenderAPI", | 111 | "SoftwareCenterRecommenderAPI", |
1100 | 111 | "submit_profile", | 112 | "submit_profile", |
1101 | 112 | data=data) | 113 | data=data) |
1103 | 113 | 114 | ||
1104 | 114 | def post_submit_anon_profile(self, uuid, installed_packages, extra): | 115 | def post_submit_anon_profile(self, uuid, installed_packages, extra): |
1105 | 115 | # build the command | 116 | # build the command |
1106 | 116 | spawner = SpawnHelper() | 117 | spawner = SpawnHelper() |
1107 | @@ -124,7 +125,7 @@ | |||
1108 | 124 | uuid=uuid, | 125 | uuid=uuid, |
1109 | 125 | installed_packages=installed_packages, | 126 | installed_packages=installed_packages, |
1110 | 126 | extra=extra) | 127 | extra=extra) |
1112 | 127 | 128 | ||
1113 | 128 | def query_profile(self, pkgnames): | 129 | def query_profile(self, pkgnames): |
1114 | 129 | # build the command | 130 | # build the command |
1115 | 130 | spawner = SpawnHelper() | 131 | spawner = SpawnHelper() |
1116 | @@ -146,7 +147,7 @@ | |||
1117 | 146 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) | 147 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) |
1118 | 147 | spawner.run_generic_piston_helper( | 148 | spawner.run_generic_piston_helper( |
1119 | 148 | "SoftwareCenterRecommenderAPI", "recommend_me") | 149 | "SoftwareCenterRecommenderAPI", "recommend_me") |
1121 | 149 | 150 | ||
1122 | 150 | def query_recommend_app(self, pkgname): | 151 | def query_recommend_app(self, pkgname): |
1123 | 151 | # build the command | 152 | # build the command |
1124 | 152 | spawner = SpawnHelper() | 153 | spawner = SpawnHelper() |
1125 | @@ -157,7 +158,7 @@ | |||
1126 | 157 | "SoftwareCenterRecommenderAPI", | 158 | "SoftwareCenterRecommenderAPI", |
1127 | 158 | "recommend_app", | 159 | "recommend_app", |
1128 | 159 | pkgname=pkgname) | 160 | pkgname=pkgname) |
1130 | 160 | 161 | ||
1131 | 161 | def query_recommend_all_apps(self): | 162 | def query_recommend_all_apps(self): |
1132 | 162 | # build the command | 163 | # build the command |
1133 | 163 | spawner = SpawnHelper() | 164 | spawner = SpawnHelper() |
1134 | @@ -166,7 +167,7 @@ | |||
1135 | 166 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) | 167 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) |
1136 | 167 | spawner.run_generic_piston_helper( | 168 | spawner.run_generic_piston_helper( |
1137 | 168 | "SoftwareCenterRecommenderAPI", "recommend_all_apps") | 169 | "SoftwareCenterRecommenderAPI", "recommend_all_apps") |
1139 | 169 | 170 | ||
1140 | 170 | def query_recommend_top(self): | 171 | def query_recommend_top(self): |
1141 | 171 | # build the command | 172 | # build the command |
1142 | 172 | spawner = SpawnHelper() | 173 | spawner = SpawnHelper() |
1143 | @@ -175,7 +176,7 @@ | |||
1144 | 175 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) | 176 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) |
1145 | 176 | spawner.run_generic_piston_helper( | 177 | spawner.run_generic_piston_helper( |
1146 | 177 | "SoftwareCenterRecommenderAPI", "recommend_top") | 178 | "SoftwareCenterRecommenderAPI", "recommend_top") |
1148 | 178 | 179 | ||
1149 | 179 | def is_opted_in(self): | 180 | def is_opted_in(self): |
1150 | 180 | """ | 181 | """ |
1151 | 181 | Return True is the user is currently opted-in to the recommender | 182 | Return True is the user is currently opted-in to the recommender |
1152 | @@ -185,33 +186,34 @@ | |||
1153 | 185 | return True | 186 | return True |
1154 | 186 | else: | 187 | else: |
1155 | 187 | return False | 188 | return False |
1157 | 188 | 189 | ||
1158 | 189 | def _on_server_status_data(self, spawner, piston_server_status): | 190 | def _on_server_status_data(self, spawner, piston_server_status): |
1159 | 190 | self.emit("server-status", piston_server_status) | 191 | self.emit("server-status", piston_server_status) |
1161 | 191 | 192 | ||
1162 | 192 | def _on_profile_data(self, spawner, piston_profile): | 193 | def _on_profile_data(self, spawner, piston_profile): |
1163 | 193 | self.emit("profile", piston_profile) | 194 | self.emit("profile", piston_profile) |
1165 | 194 | 195 | ||
1166 | 195 | def _on_submit_profile_data(self, spawner, piston_submit_profile): | 196 | def _on_submit_profile_data(self, spawner, piston_submit_profile): |
1169 | 196 | self.emit("submit-profile-finished", | 197 | self.emit("submit-profile-finished", |
1170 | 197 | piston_submit_profile, | 198 | piston_submit_profile, |
1171 | 198 | self.recommender_uuid) | 199 | self.recommender_uuid) |
1174 | 199 | 200 | ||
1175 | 200 | def _on_submit_anon_profile_data(self, spawner, piston_submit_anon_profile): | 201 | def _on_submit_anon_profile_data(self, spawner, |
1176 | 202 | piston_submit_anon_profile): | ||
1177 | 201 | self.emit("submit-anon_profile", piston_submit_anon_profile) | 203 | self.emit("submit-anon_profile", piston_submit_anon_profile) |
1178 | 202 | 204 | ||
1179 | 203 | def _on_recommend_me_data(self, spawner, piston_me_apps): | 205 | def _on_recommend_me_data(self, spawner, piston_me_apps): |
1180 | 204 | self.emit("recommend-me", piston_me_apps) | 206 | self.emit("recommend-me", piston_me_apps) |
1182 | 205 | 207 | ||
1183 | 206 | def _on_recommend_app_data(self, spawner, piston_app): | 208 | def _on_recommend_app_data(self, spawner, piston_app): |
1184 | 207 | self.emit("recommend-app", piston_app) | 209 | self.emit("recommend-app", piston_app) |
1186 | 208 | 210 | ||
1187 | 209 | def _on_recommend_all_apps_data(self, spawner, piston_all_apps): | 211 | def _on_recommend_all_apps_data(self, spawner, piston_all_apps): |
1188 | 210 | self.emit("recommend-all-apps", piston_all_apps) | 212 | self.emit("recommend-all-apps", piston_all_apps) |
1190 | 211 | 213 | ||
1191 | 212 | def _on_recommend_top_data(self, spawner, piston_top_apps): | 214 | def _on_recommend_top_data(self, spawner, piston_top_apps): |
1192 | 213 | self.emit("recommend-top", piston_top_apps) | 215 | self.emit("recommend-top", piston_top_apps) |
1194 | 214 | 216 | ||
1195 | 215 | def _get_recommender_uuid(self): | 217 | def _get_recommender_uuid(self): |
1196 | 216 | """ returns the recommender UUID value, which can be empty if it | 218 | """ returns the recommender UUID value, which can be empty if it |
1197 | 217 | has not yet been set (indicating that the user has not yet | 219 | has not yet been set (indicating that the user has not yet |
1198 | @@ -223,24 +225,24 @@ | |||
1199 | 223 | if recommender_uuid: | 225 | if recommender_uuid: |
1200 | 224 | return recommender_uuid | 226 | return recommender_uuid |
1201 | 225 | return "" | 227 | return "" |
1203 | 226 | 228 | ||
1204 | 227 | def _generate_submit_profile_data(self, recommender_uuid, package_list): | 229 | def _generate_submit_profile_data(self, recommender_uuid, package_list): |
1211 | 228 | submit_profile_data = [ | 230 | submit_profile_data = [{ |
1212 | 229 | { | 231 | 'uuid': recommender_uuid, |
1213 | 230 | 'uuid': recommender_uuid, | 232 | 'package_list': package_list |
1214 | 231 | 'package_list': package_list | 233 | }] |
1209 | 232 | } | ||
1210 | 233 | ] | ||
1215 | 234 | return submit_profile_data | 234 | return submit_profile_data |
1216 | 235 | 235 | ||
1218 | 236 | 236 | ||
1219 | 237 | if __name__ == "__main__": | 237 | if __name__ == "__main__": |
1220 | 238 | from gi.repository import Gtk | 238 | from gi.repository import Gtk |
1221 | 239 | 239 | ||
1222 | 240 | def _recommend_top(agent, top_apps): | 240 | def _recommend_top(agent, top_apps): |
1223 | 241 | print ("_recommend_top: %s" % top_apps) | 241 | print ("_recommend_top: %s" % top_apps) |
1224 | 242 | |||
1225 | 242 | def _recommend_me(agent, top_apps): | 243 | def _recommend_me(agent, top_apps): |
1226 | 243 | print ("_recommend_me: %s" % top_apps) | 244 | print ("_recommend_me: %s" % top_apps) |
1227 | 245 | |||
1228 | 244 | def _error(agent, msg): | 246 | def _error(agent, msg): |
1229 | 245 | print ("got a error: %s" % msg) | 247 | print ("got a error: %s" % msg) |
1230 | 246 | Gtk.main_quit() | 248 | Gtk.main_quit() |
1231 | @@ -256,5 +258,4 @@ | |||
1232 | 256 | agent.query_recommend_top() | 258 | agent.query_recommend_top() |
1233 | 257 | agent.query_recommend_me() | 259 | agent.query_recommend_me() |
1234 | 258 | 260 | ||
1235 | 259 | |||
1236 | 260 | Gtk.main() | 261 | Gtk.main() |
1237 | 261 | 262 | ||
1238 | === modified file 'softwarecenter/backend/scagent.py' | |||
1239 | --- softwarecenter/backend/scagent.py 2012-01-17 15:56:14 +0000 | |||
1240 | +++ softwarecenter/backend/scagent.py 2012-03-19 14:27:20 +0000 | |||
1241 | @@ -29,27 +29,28 @@ | |||
1242 | 29 | 29 | ||
1243 | 30 | LOG = logging.getLogger(__name__) | 30 | LOG = logging.getLogger(__name__) |
1244 | 31 | 31 | ||
1245 | 32 | |||
1246 | 32 | class SoftwareCenterAgent(GObject.GObject): | 33 | class SoftwareCenterAgent(GObject.GObject): |
1247 | 33 | 34 | ||
1248 | 34 | __gsignals__ = { | 35 | __gsignals__ = { |
1265 | 35 | "available-for-me" : (GObject.SIGNAL_RUN_LAST, | 36 | "available-for-me": (GObject.SIGNAL_RUN_LAST, |
1266 | 36 | GObject.TYPE_NONE, | 37 | GObject.TYPE_NONE, |
1267 | 37 | (GObject.TYPE_PYOBJECT,), | 38 | (GObject.TYPE_PYOBJECT,), |
1268 | 38 | ), | 39 | ), |
1269 | 39 | "available" : (GObject.SIGNAL_RUN_LAST, | 40 | "available": (GObject.SIGNAL_RUN_LAST, |
1270 | 40 | GObject.TYPE_NONE, | 41 | GObject.TYPE_NONE, |
1271 | 41 | (GObject.TYPE_PYOBJECT,), | 42 | (GObject.TYPE_PYOBJECT,), |
1272 | 42 | ), | 43 | ), |
1273 | 43 | "exhibits" : (GObject.SIGNAL_RUN_LAST, | 44 | "exhibits": (GObject.SIGNAL_RUN_LAST, |
1274 | 44 | GObject.TYPE_NONE, | 45 | GObject.TYPE_NONE, |
1275 | 45 | (GObject.TYPE_PYOBJECT,), | 46 | (GObject.TYPE_PYOBJECT,), |
1276 | 46 | ), | 47 | ), |
1277 | 47 | "error" : (GObject.SIGNAL_RUN_LAST, | 48 | "error": (GObject.SIGNAL_RUN_LAST, |
1278 | 48 | GObject.TYPE_NONE, | 49 | GObject.TYPE_NONE, |
1279 | 49 | (str,), | 50 | (str,), |
1280 | 50 | ), | 51 | ), |
1281 | 51 | } | 52 | } |
1283 | 52 | 53 | ||
1284 | 53 | def __init__(self, ignore_cache=False, xid=None): | 54 | def __init__(self, ignore_cache=False, xid=None): |
1285 | 54 | GObject.GObject.__init__(self) | 55 | GObject.GObject.__init__(self) |
1286 | 55 | self.distro = get_distro() | 56 | self.distro = get_distro() |
1287 | @@ -103,7 +104,8 @@ | |||
1288 | 103 | "SoftwareCenterAgentAPI", "subscriptions_for_me", | 104 | "SoftwareCenterAgentAPI", "subscriptions_for_me", |
1289 | 104 | complete_only=True) | 105 | complete_only=True) |
1290 | 105 | 106 | ||
1292 | 106 | def _on_query_available_for_me_data(self, spawner, piston_available_for_me): | 107 | def _on_query_available_for_me_data(self, spawner, |
1293 | 108 | piston_available_for_me): | ||
1294 | 107 | self.emit("available-for-me", piston_available_for_me) | 109 | self.emit("available-for-me", piston_available_for_me) |
1295 | 108 | 110 | ||
1296 | 109 | def query_exhibits(self): | 111 | def query_exhibits(self): |
1297 | @@ -113,7 +115,7 @@ | |||
1298 | 113 | spawner.connect("data-available", self._on_exhibits_data_available) | 115 | spawner.connect("data-available", self._on_exhibits_data_available) |
1299 | 114 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) | 116 | spawner.connect("error", lambda spawner, err: self.emit("error", err)) |
1300 | 115 | spawner.run_generic_piston_helper( | 117 | spawner.run_generic_piston_helper( |
1302 | 116 | "SoftwareCenterAgentAPI", "exhibits", | 118 | "SoftwareCenterAgentAPI", "exhibits", |
1303 | 117 | lang=get_language(), series=self.distro.get_codename()) | 119 | lang=get_language(), series=self.distro.get_codename()) |
1304 | 118 | 120 | ||
1305 | 119 | def _on_exhibits_data_available(self, spawner, exhibits): | 121 | def _on_exhibits_data_available(self, spawner, exhibits): |
1306 | @@ -123,18 +125,22 @@ | |||
1307 | 123 | if not hasattr(exhibit, "title_translated"): | 125 | if not hasattr(exhibit, "title_translated"): |
1308 | 124 | if exhibit.html: | 126 | if exhibit.html: |
1309 | 125 | from softwarecenter.utils import get_title_from_html | 127 | from softwarecenter.utils import get_title_from_html |
1311 | 126 | exhibit.title_translated = get_title_from_html(exhibit.html) | 128 | exhibit.title_translated = get_title_from_html( |
1312 | 129 | exhibit.html) | ||
1313 | 127 | else: | 130 | else: |
1314 | 128 | exhibit.title_translated = "" | 131 | exhibit.title_translated = "" |
1315 | 129 | self.emit("exhibits", exhibits) | 132 | self.emit("exhibits", exhibits) |
1317 | 130 | 133 | ||
1318 | 131 | if __name__ == "__main__": | 134 | if __name__ == "__main__": |
1319 | 132 | def _available(agent, available): | 135 | def _available(agent, available): |
1320 | 133 | print ("_available: %s" % available) | 136 | print ("_available: %s" % available) |
1321 | 137 | |||
1322 | 134 | def _available_for_me(agent, available_for_me): | 138 | def _available_for_me(agent, available_for_me): |
1323 | 135 | print ("_availalbe_for_me: %s" % available_for_me) | 139 | print ("_availalbe_for_me: %s" % available_for_me) |
1324 | 140 | |||
1325 | 136 | def _exhibits(agent, exhibits): | 141 | def _exhibits(agent, exhibits): |
1326 | 137 | print ("exhibits: " % exhibits) | 142 | print ("exhibits: " % exhibits) |
1327 | 143 | |||
1328 | 138 | def _error(agent, msg): | 144 | def _error(agent, msg): |
1329 | 139 | print ("got a error" % msg) | 145 | print ("got a error" % msg) |
1330 | 140 | #gtk.main_quit() | 146 | #gtk.main_quit() |
1331 | 141 | 147 | ||
1332 | === modified file 'softwarecenter/hw.py' | |||
1333 | --- softwarecenter/hw.py 2012-03-19 11:32:58 +0000 | |||
1334 | +++ softwarecenter/hw.py 2012-03-19 14:27:20 +0000 | |||
1335 | @@ -79,10 +79,12 @@ | |||
1336 | 79 | u'computer is using.'), | 79 | u'computer is using.'), |
1337 | 80 | } | 80 | } |
1338 | 81 | 81 | ||
1339 | 82 | |||
1340 | 82 | def get_hw_short_description(tag): | 83 | def get_hw_short_description(tag): |
1341 | 83 | s = TAG_DESCRIPTION.get(tag) | 84 | s = TAG_DESCRIPTION.get(tag) |
1342 | 84 | return utf8(s) | 85 | return utf8(s) |
1343 | 85 | 86 | ||
1344 | 87 | |||
1345 | 86 | def get_hw_missing_long_description(tags): | 88 | def get_hw_missing_long_description(tags): |
1346 | 87 | s = "" | 89 | s = "" |
1347 | 88 | # build string | 90 | # build string |
1348 | @@ -94,7 +96,7 @@ | |||
1349 | 94 | else: | 96 | else: |
1350 | 95 | # deal with generic tags | 97 | # deal with generic tags |
1351 | 96 | prefix, sep, postfix = tag.rpartition(":") | 98 | prefix, sep, postfix = tag.rpartition(":") |
1353 | 97 | descr = TAG_MISSING_DESCRIPTION.get(prefix+sep) | 99 | descr = TAG_MISSING_DESCRIPTION.get(prefix + sep) |
1354 | 98 | descr = descr % postfix | 100 | descr = descr % postfix |
1355 | 99 | if descr: | 101 | if descr: |
1356 | 100 | s += "%s\n" % descr | 102 | s += "%s\n" % descr |
1357 | @@ -116,8 +118,9 @@ | |||
1358 | 116 | res[tag] = debtagshw.enums.HardwareSupported.YES | 118 | res[tag] = debtagshw.enums.HardwareSupported.YES |
1359 | 117 | return res | 119 | return res |
1360 | 118 | 120 | ||
1361 | 121 | |||
1362 | 119 | def get_hardware_support_for_tags(tags): | 122 | def get_hardware_support_for_tags(tags): |
1364 | 120 | """ wrapper around the DebtagsAvailalbeHW to support adding our own | 123 | """ wrapper around the DebtagsAvailalbeHW to support adding our own |
1365 | 121 | private tag extension (like opengl-driver) | 124 | private tag extension (like opengl-driver) |
1366 | 122 | """ | 125 | """ |
1367 | 123 | from debtagshw.debtagshw import DebtagsAvailableHW | 126 | from debtagshw.debtagshw import DebtagsAvailableHW |
1368 | 124 | 127 | ||
1369 | === modified file 'softwarecenter/testutils.py' | |||
1370 | --- softwarecenter/testutils.py 2012-03-15 21:19:02 +0000 | |||
1371 | +++ softwarecenter/testutils.py 2012-03-19 14:27:20 +0000 | |||
1372 | @@ -230,7 +230,7 @@ | |||
1373 | 230 | }, | 230 | }, |
1374 | 231 | { | 231 | { |
1375 | 232 | u'package_name': u'mangler' | 232 | u'package_name': u'mangler' |
1377 | 233 | }, | 233 | }, |
1378 | 234 | { | 234 | { |
1379 | 235 | u'package_name': u'nexuiz' | 235 | u'package_name': u'nexuiz' |
1380 | 236 | }, | 236 | }, |
1381 | @@ -254,7 +254,7 @@ | |||
1382 | 254 | }, | 254 | }, |
1383 | 255 | { | 255 | { |
1384 | 256 | u'package_name': u'psi' | 256 | u'package_name': u'psi' |
1386 | 257 | }, | 257 | }, |
1387 | 258 | { | 258 | { |
1388 | 259 | u'package_name': u'midori' | 259 | u'package_name': u'midori' |
1389 | 260 | } | 260 | } |
1390 | @@ -282,7 +282,6 @@ | |||
1391 | 282 | u'phlipple', | 282 | u'phlipple', |
1392 | 283 | u'psi', | 283 | u'psi', |
1393 | 284 | u'midori' | 284 | u'midori' |
1394 | 285 | |||
1395 | 286 | ] | 285 | ] |
1396 | 287 | } | 286 | } |
1397 | 288 | ] | 287 | ] |
1398 | 289 | 288 | ||
1399 | === modified file 'softwarecenter/utils.py' | |||
1400 | --- softwarecenter/utils.py 2012-03-16 17:22:59 +0000 | |||
1401 | +++ softwarecenter/utils.py 2012-03-19 14:27:20 +0000 | |||
1402 | @@ -253,7 +253,7 @@ | |||
1403 | 253 | # well ... it segfaults (thanks pygi) | 253 | # well ... it segfaults (thanks pygi) |
1404 | 254 | key = "org.gnome.system.proxy.http" | 254 | key = "org.gnome.system.proxy.http" |
1405 | 255 | if not key in Gio.Settings.list_schemas(): | 255 | if not key in Gio.Settings.list_schemas(): |
1407 | 256 | raise ValueError, "no key '%s'" % key | 256 | raise ValueError("no key '%s'" % key) |
1408 | 257 | settings = Gio.Settings.new(key) | 257 | settings = Gio.Settings.new(key) |
1409 | 258 | if settings.get_string("host"): | 258 | if settings.get_string("host"): |
1410 | 259 | authentication = "" | 259 | authentication = "" |
1411 | 260 | 260 | ||
1412 | === modified file 'test/test_pep8.py' | |||
1413 | --- test/test_pep8.py 2012-03-19 14:27:20 +0000 | |||
1414 | +++ test/test_pep8.py 2012-03-19 14:27:20 +0000 | |||
1415 | @@ -7,21 +7,12 @@ | |||
1416 | 7 | setup_test_env() | 7 | setup_test_env() |
1417 | 8 | 8 | ||
1418 | 9 | # Only test these two packages for now: | 9 | # Only test these two packages for now: |
1423 | 10 | import softwarecenter.backend | 10 | import softwarecenter |
1420 | 11 | import softwarecenter.db | ||
1421 | 12 | import softwarecenter.ui | ||
1422 | 13 | import softwarecenter.distro | ||
1424 | 14 | 11 | ||
1425 | 15 | class PackagePep8TestCase(unittest.TestCase): | 12 | class PackagePep8TestCase(unittest.TestCase): |
1426 | 16 | maxDiff = None | 13 | maxDiff = None |
1435 | 17 | packages = [softwarecenter.ui, | 14 | packages = [softwarecenter] |
1436 | 18 | softwarecenter.backend, | 15 | exclude = [] |
1429 | 19 | softwarecenter.db, | ||
1430 | 20 | softwarecenter.distro, | ||
1431 | 21 | ] | ||
1432 | 22 | exclude = ['scagent.py', 'recagent.py', 'login_sso.py', 'login.py', | ||
1433 | 23 | 'launchpad.py', 'installbackend.py', 'fake_review_settings.py', | ||
1434 | 24 | 'channel.py'] | ||
1437 | 25 | 16 | ||
1438 | 26 | def message(self, text): | 17 | def message(self, text): |
1439 | 27 | self.errors.append(text) | 18 | self.errors.append(text) |
awesomeness :)