Merge lp:~elachuni/software-center/pep8-test-part22 into lp:software-center

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
Reviewer Review Type Date Requested Status
Kiwinote Approve
Review via email: mp+98205@code.launchpad.net

Description of the change

All code under softwarecenter/ now passes the pep8 test.

To post a comment you must log in.
Revision history for this message
Kiwinote (kiwinote) wrote :

awesomeness :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'softwarecenter/backend/channel.py'
--- softwarecenter/backend/channel.py 2011-12-02 14:33:49 +0000
+++ softwarecenter/backend/channel.py 2012-03-19 14:27:20 +0000
@@ -24,13 +24,14 @@
2424
25from softwarecenter.distro import get_distro25from softwarecenter.distro import get_distro
2626
27from softwarecenter.enums import (SortMethods, 27from softwarecenter.enums import (SortMethods,
28 Icons,28 Icons,
29 ViewPages,29 ViewPages,
30 )30 )
3131
32LOG = logging.getLogger(__name__)32LOG = logging.getLogger(__name__)
3333
34
34class ChannelsManager(object):35class ChannelsManager(object):
35 def __init__(self, db, **kwargs):36 def __init__(self, db, **kwargs):
36 self.distro = get_distro()37 self.distro = get_distro()
@@ -52,10 +53,11 @@
52 # private53 # private
53 def _get_channels_from_db(self, installed_only=False):54 def _get_channels_from_db(self, installed_only=False):
54 """55 """
55 (internal) implements 'channels()' and 'channels_installed_only()' properties56 (internal) implements 'channels()' and 'channels_installed_only()'
57 properties
56 """58 """
57 distro_channel_origin = self.distro.get_distro_channel_name()59 distro_channel_origin = self.distro.get_distro_channel_name()
58 60
59 # gather the set of software channels and order them61 # gather the set of software channels and order them
60 other_channel_list = []62 other_channel_list = []
61 cached_origins = []63 cached_origins = []
@@ -64,12 +66,13 @@
64 continue66 continue
65 channel_name = channel_iter.term[3:]67 channel_name = channel_iter.term[3:]
66 channel_origin = ""68 channel_origin = ""
67 69
68 # get origin information for this channel70 # get origin information for this channel
69 m = self.db.xapiandb.postlist_begin(channel_iter.term)71 m = self.db.xapiandb.postlist_begin(channel_iter.term)
70 doc = self.db.xapiandb.get_document(m.get_docid())72 doc = self.db.xapiandb.get_document(m.get_docid())
71 for term_iter in doc.termlist():73 for term_iter in doc.termlist():
72 if term_iter.term.startswith("XOO") and len(term_iter.term) > 3: 74 if (term_iter.term.startswith("XOO") and
75 len(term_iter.term) > 3):
73 channel_origin = term_iter.term[3:]76 channel_origin = term_iter.term[3:]
74 break77 break
75 LOG.debug("channel_name: %s" % channel_name)78 LOG.debug("channel_name: %s" % channel_name)
@@ -77,7 +80,7 @@
77 if channel_origin not in cached_origins:80 if channel_origin not in cached_origins:
78 other_channel_list.append((channel_name, channel_origin))81 other_channel_list.append((channel_name, channel_origin))
79 cached_origins.append(channel_origin)82 cached_origins.append(channel_origin)
80 83
81 dist_channel = None84 dist_channel = None
82 other_channels = []85 other_channels = []
83 unknown_channel = []86 unknown_channel = []
@@ -85,26 +88,30 @@
8588
86 for (channel_name, channel_origin) in other_channel_list:89 for (channel_name, channel_origin) in other_channel_list:
87 if not channel_name:90 if not channel_name:
88 unknown_channel.append(SoftwareChannel(channel_name,91 unknown_channel.append(SoftwareChannel(
89 channel_origin,92 channel_name,
90 None,93 channel_origin,
91 installed_only=installed_only))94 None,
95 installed_only=installed_only))
92 elif channel_origin == distro_channel_origin:96 elif channel_origin == distro_channel_origin:
93 dist_channel = (SoftwareChannel(channel_name,97 dist_channel = (SoftwareChannel(
94 channel_origin,98 channel_name,
95 None,99 channel_origin,
96 installed_only=installed_only))100 None,
101 installed_only=installed_only))
97 elif channel_name == "notdownloadable":102 elif channel_name == "notdownloadable":
98 if installed_only:103 if installed_only:
99 local_channel = SoftwareChannel(channel_name,104 local_channel = SoftwareChannel(
100 None,105 channel_name,
101 None,106 None,
102 installed_only=installed_only)107 None,
108 installed_only=installed_only)
103 else:109 else:
104 other_channels.append(SoftwareChannel(channel_name,110 other_channels.append(SoftwareChannel(
105 channel_origin,111 channel_name,
106 None,112 channel_origin,
107 installed_only=installed_only))113 None,
114 installed_only=installed_only))
108115
109 # set them in order116 # set them in order
110 channels = []117 channels = []
@@ -122,13 +129,14 @@
122 channel._channel_view_id = ViewPages.AVAILABLE129 channel._channel_view_id = ViewPages.AVAILABLE
123 return channels130 return channels
124131
132
125class SoftwareChannel(object):133class SoftwareChannel(object):
126 """134 """
127 class to represent a software channel135 class to represent a software channel
128 """136 """
129 137
130 ICON_SIZE = 24138 ICON_SIZE = 24
131 139
132 def __init__(self, channel_name, channel_origin, channel_component,140 def __init__(self, channel_name, channel_origin, channel_component,
133 source_entry=None, installed_only=False,141 source_entry=None, installed_only=False,
134 channel_icon=None, channel_query=None,142 channel_icon=None, channel_query=None,
@@ -148,13 +156,16 @@
148 # distro specific stuff156 # distro specific stuff
149 self.distro = get_distro()157 self.distro = get_distro()
150 # configure the channel158 # configure the channel
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(
160 channel_name, channel_origin, channel_component)
152 if channel_icon is None:161 if channel_icon is None:
153 self._channel_icon = self._get_icon_for_channel(channel_name, channel_origin, channel_component)162 self._channel_icon = self._get_icon_for_channel(
163 channel_name, channel_origin, channel_component)
154 else:164 else:
155 self._channel_icon = channel_icon165 self._channel_icon = channel_icon
156 if channel_query is None:166 if channel_query is None:
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(
168 channel_name, channel_origin, channel_component)
158 else:169 else:
159 self._channel_query = channel_query170 self._channel_query = channel_query
160 # a sources.list entry attached to the channel (this is currently171 # a sources.list entry attached to the channel (this is currently
@@ -162,36 +173,36 @@
162 self._source_entry = source_entry173 self._source_entry = source_entry
163 # when the channel needs to be added to the systems sources.list174 # when the channel needs to be added to the systems sources.list
164 self.needs_adding = False175 self.needs_adding = False
165 176
166 @property177 @property
167 def name(self):178 def name(self):
168 """179 """
169 return the channel name as represented in the xapian database180 return the channel name as represented in the xapian database
170 """181 """
171 return self._channel_name182 return self._channel_name
172 183
173 @property 184 @property
174 def origin(self):185 def origin(self):
175 """186 """
176 return the channel origin as represented in the xapian database187 return the channel origin as represented in the xapian database
177 """188 """
178 return self._channel_origin189 return self._channel_origin
179 190
180 @property 191 @property
181 def component(self):192 def component(self):
182 """193 """
183 return the channel component as represented in the xapian database194 return the channel component as represented in the xapian database
184 """195 """
185 return self._channel_component196 return self._channel_component
186 197
187 @property 198 @property
188 def display_name(self):199 def display_name(self):
189 """200 """
190 return the display name for the corresponding channel for use in the UI201 return the display name for the corresponding channel for use in the UI
191 """202 """
192 return self._channel_display_name203 return self._channel_display_name
193 204
194 @property 205 @property
195 def icon(self):206 def icon(self):
196 """207 """
197 return the icon that corresponds to each channel based208 return the icon that corresponds to each channel based
@@ -205,18 +216,19 @@
205 return the xapian query to be used with this software channel216 return the xapian query to be used with this software channel
206 """217 """
207 return self._channel_query218 return self._channel_query
208 219
209 @property 220 @property
210 def sort_mode(self):221 def sort_mode(self):
211 """222 """
212 return the sort mode for this software channel223 return the sort mode for this software channel
213 """224 """
214 return self._channel_sort_mode225 return self._channel_sort_mode
215 226
216 # TODO: implement __cmp__ so that sort for channels is encapsulated227 # TODO: implement __cmp__ so that sort for channels is encapsulated
217 # here as well228 # here as well
218229
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,
231 channel_component):
220 if channel_component == "partner":232 if channel_component == "partner":
221 channel_display_name = _("Canonical Partners")233 channel_display_name = _("Canonical Partners")
222 elif not channel_origin:234 elif not channel_origin:
@@ -232,8 +244,9 @@
232 else:244 else:
233 return channel_name245 return channel_name
234 return channel_display_name246 return channel_display_name
235 247
236 def _get_icon_for_channel(self, channel_name, channel_origin, channel_component):248 def _get_icon_for_channel(self, channel_name, channel_origin,
249 channel_component):
237 if channel_component == "partner":250 if channel_component == "partner":
238 channel_icon = "partner"251 channel_icon = "partner"
239 elif not channel_name:252 elif not channel_name:
@@ -253,16 +266,17 @@
253 else:266 else:
254 channel_icon = "unknown-channel"267 channel_icon = "unknown-channel"
255 return channel_icon268 return channel_icon
256 269
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,
258 271 channel_component):
272
259 if channel_component == "partner":273 if channel_component == "partner":
260 q1 = xapian.Query("XOCpartner")274 q1 = xapian.Query("XOCpartner")
261 q2 = xapian.Query("AH%s-partner" % self.distro.get_codename())275 q2 = xapian.Query("AH%s-partner" % self.distro.get_codename())
262 channel_query = xapian.Query(xapian.Query.OP_OR, q1, q2)276 channel_query = xapian.Query(xapian.Query.OP_OR, q1, q2)
263 # show only apps when displaying the new apps archive277 # show only apps when displaying the new apps archive
264 elif channel_name == "Application Review Board PPA":278 elif channel_name == "Application Review Board PPA":
265 channel_query = xapian.Query(xapian.Query.OP_AND, 279 channel_query = xapian.Query(xapian.Query.OP_AND,
266 xapian.Query("XOL" + channel_name),280 xapian.Query("XOL" + channel_name),
267 xapian.Query("ATapplication"))281 xapian.Query("ATapplication"))
268 elif channel_origin:282 elif channel_origin:
@@ -292,14 +306,14 @@
292 self, channel_name, "all", None,306 self, channel_name, "all", None,
293 installed_only=installed_only,307 installed_only=installed_only,
294 channel_icon=Icons.FALLBACK)308 channel_icon=Icons.FALLBACK)
295 return
296309
297 # overrides310 # overrides
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,
312 channel_component):
299 return channel_name313 return channel_name
300314
301 def _get_channel_query_for_channel(self, *args):315 def _get_channel_query_for_channel(self, *args):
302 return None316 pass
303317
304318
305class AllAvailableChannel(AllChannel):319class AllAvailableChannel(AllChannel):
@@ -313,28 +327,34 @@
313 def __init__(self):327 def __init__(self):
314 AllChannel.__init__(self, _("All Installed"), True)328 AllChannel.__init__(self, _("All Installed"), True)
315329
330
316# singleton331# singleton
317channels_manager = None332channels_manager = None
333
334
318def get_channels_manager(db):335def get_channels_manager(db):
319 global channels_manager336 global channels_manager
320 if channels_manager is None:337 if channels_manager is None:
321 from softwarecenter.enums import USE_PACKAGEKIT_BACKEND338 from softwarecenter.enums import USE_PACKAGEKIT_BACKEND
322 if not USE_PACKAGEKIT_BACKEND:339 if not USE_PACKAGEKIT_BACKEND:
323 from softwarecenter.backend.channel_impl.aptchannels import AptChannelsManager340 from softwarecenter.backend.channel_impl.aptchannels import (
341 AptChannelsManager)
324 channels_manager = AptChannelsManager(db)342 channels_manager = AptChannelsManager(db)
325 else:343 else:
326 channels_manager = ChannelsManager(db)344 channels_manager = ChannelsManager(db)
327 return channels_manager345 return channels_manager
328346
347
329def is_channel_available(channelname):348def is_channel_available(channelname):
330 from softwarecenter.backend.channel_impl.aptchannels import AptChannelsManager349 from softwarecenter.backend.channel_impl.aptchannels import (
350 AptChannelsManager)
331 return AptChannelsManager.channel_available(channelname)351 return AptChannelsManager.channel_available(channelname)
332352
333if __name__ == "__main__":353if __name__ == "__main__":
334 distro = get_distro()354 distro = get_distro()
335 channel = SoftwareChannel(distro.get_distro_channel_name(), 355 channel = SoftwareChannel(distro.get_distro_channel_name(),
336 None, None)356 None, None)
337 print(channel)357 print(channel)
338 channel = SoftwareChannel(distro.get_distro_channel_name(), None, "partner")358 channel = SoftwareChannel(distro.get_distro_channel_name(), None,
359 "partner")
339 print(channel)360 print(channel)
340
341361
=== modified file 'softwarecenter/backend/fake_review_settings.py'
--- softwarecenter/backend/fake_review_settings.py 2011-08-09 08:47:43 +0000
+++ softwarecenter/backend/fake_review_settings.py 2012-03-19 14:27:20 +0000
@@ -4,7 +4,8 @@
4import pickle4import pickle
5from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR5from softwarecenter.paths import SOFTWARE_CENTER_CACHE_DIR
66
7# decorator to add a fake network delay if set 7
8# decorator to add a fake network delay if set
8# in FakeReviewSettings.fake_network_delay9# in FakeReviewSettings.fake_network_delay
9def network_delay(fn):10def network_delay(fn):
10 def slp(self, *args, **kwargs):11 def slp(self, *args, **kwargs):
@@ -14,23 +15,25 @@
14 time.sleep(delay)15 time.sleep(delay)
15 return fn(self, *args, **kwargs)16 return fn(self, *args, **kwargs)
16 return slp17 return slp
17 18
19
18class FakeReviewSettings(object):20class FakeReviewSettings(object):
19 '''An object that simply holds settings which are used by RatingsAndReviewsAPI21 '''An object that simply holds settings which are used by
20 in the rnrclient_fake module. Using this module allows a developer to test22 RatingsAndReviewsAPI in the rnrclient_fake module. Using this module
21 the reviews functionality without any interaction with a reviews server.23 allows a developer to test the reviews functionality without any
22 Each setting here provides complete control over how the 'server' will 24 interaction with a reviews server. Each setting here provides complete
23 respond. Changes to these settings should be made to the class attributes25 control over how the 'server' will respond. Changes to these settings
24 directly without creating an instance of this class.26 should be made to the class attributes directly without creating an
25 The intended usage is for unit tests where a predictable response is 27 instance of this class.
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
27 server. 29 required and where the application should THINK it has spoken to a
28 The unit test would make changes to settings in this class before 30 server.
31 The unit test would make changes to settings in this class before
29 running the unit test.32 running the unit test.
30 '''33 '''
31 34
32 _FAKE_SETTINGS = {}35 _FAKE_SETTINGS = {}
33 36
34 #general settings37 #general settings
35 #*****************************38 #*****************************
36 #delay (in seconds) before returning from any of the fake rnr methods39 #delay (in seconds) before returning from any of the fake rnr methods
@@ -41,45 +44,46 @@
41 #*****************************44 #*****************************
42 #raises APIError if True45 #raises APIError if True
43 _FAKE_SETTINGS['server_response_error'] = False46 _FAKE_SETTINGS['server_response_error'] = False
44 47
45 #review stats48 #review stats
46 #*****************************49 #*****************************
47 #raises APIError if True50 #raises APIError if True
48 _FAKE_SETTINGS['review_stats_error'] = False 51 _FAKE_SETTINGS['review_stats_error'] = False
49 52
50 #the following has no effect if review_stats_error = True53 #the following has no effect if review_stats_error = True
51 #determines the number of package stats (i.e. ReviewStats list size) to return54 #determines the number of package stats (i.e. ReviewStats list size) to
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)
53 _FAKE_SETTINGS['packages_returned'] = 1056 _FAKE_SETTINGS['packages_returned'] = 10
54 57
55 #get reviews58 #get reviews
56 #*****************************59 #*****************************
57 #raises APIError if True60 #raises APIError if True
58 _FAKE_SETTINGS['get_reviews_error'] = False61 _FAKE_SETTINGS['get_reviews_error'] = False
5962
60 #number of pages of 10 reviews to return before returning the number specified63 #number of pages of 10 reviews to return before returning the number
61 #in the reviews_returned value below64 # specified in the reviews_returned value below
62 _FAKE_SETTINGS['review_pages'] = 165 _FAKE_SETTINGS['review_pages'] = 1
6366
64 #the following has no effect if get_reviews_error = True67 #the following has no effect if get_reviews_error = True
65 #determines number of reviews to return 68 #determines number of reviews to return
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)
67 _FAKE_SETTINGS['reviews_returned'] = 370 _FAKE_SETTINGS['reviews_returned'] = 3
68 71
69 #get review72 #get review
70 #*****************************73 #*****************************
71 #raises APIError if True74 #raises APIError if True
72 _FAKE_SETTINGS['get_review_error'] = False75 _FAKE_SETTINGS['get_review_error'] = False
73 76
74 #submit review77 #submit review
75 #*****************************78 #*****************************
76 #raises APIError if True79 #raises APIError if True
77 _FAKE_SETTINGS['submit_review_error'] = False80 _FAKE_SETTINGS['submit_review_error'] = False
78 #fake username(str) and review_id(int) to give back with a successful review81 #fake username(str) and review_id(int) to give back with a successful
82 # review
79 #leave as None to generate a random username and review_id83 #leave as None to generate a random username and review_id
80 _FAKE_SETTINGS['reviewer_username'] = None84 _FAKE_SETTINGS['reviewer_username'] = None
81 _FAKE_SETTINGS['submit_review_id'] = None85 _FAKE_SETTINGS['submit_review_id'] = None
82 86
83 #flag review87 #flag review
84 #*****************************88 #*****************************
85 #raises APIError if True89 #raises APIError if True
@@ -88,43 +92,43 @@
88 _FAKE_SETTINGS['flagger_username'] = None92 _FAKE_SETTINGS['flagger_username'] = None
89 #fake package name (str) to give back as flagged app93 #fake package name (str) to give back as flagged app
90 _FAKE_SETTINGS['flag_package_name'] = None94 _FAKE_SETTINGS['flag_package_name'] = None
91 95
92 #submit usefulness96 #submit usefulness
93 #*****************************97 #*****************************
94 #raises APIError if True98 #raises APIError if True
95 _FAKE_SETTINGS['submit_usefulness_error'] = False99 _FAKE_SETTINGS['submit_usefulness_error'] = False
96 100
97 #the following has no effect if submit_usefulness_error = True101 #the following has no effect if submit_usefulness_error = True
98 #which string to pretend the server returned102 #which string to pretend the server returned
99 #choices are "Created", "Updated", "Not modified"103 #choices are "Created", "Updated", "Not modified"
100 _FAKE_SETTINGS['usefulness_response_string'] = "Created"104 _FAKE_SETTINGS['usefulness_response_string'] = "Created"
101 105
102 #get usefulness106 #get usefulness
103 #*****************************107 #*****************************
104 #raises APIError if True108 #raises APIError if True
105 _FAKE_SETTINGS['get_usefulness_error'] = False109 _FAKE_SETTINGS['get_usefulness_error'] = False
106 110
107 #the following has no effect if get_usefulness_error = True111 #the following has no effect if get_usefulness_error = True
108 #how many usefulness votes to return112 #how many usefulness votes to return
109 _FAKE_SETTINGS['votes_returned'] = 5113 _FAKE_SETTINGS['votes_returned'] = 5
110 114
111 #pre-configured review ids to return in the result 115 #pre-configured review ids to return in the result
112 #if you don't complete this or enter less review ids than votes_returned116 #if you don't complete this or enter less review ids than votes_returned
113 #above, it will be random117 #above, it will be random
114 _FAKE_SETTINGS['required_review_ids'] = [3,6,15]118 _FAKE_SETTINGS['required_review_ids'] = [3, 6, 15]
115 119
116 #THE FOLLOWING SETTINGS RELATE TO LOGIN SSO FUNCTIONALITY120 #THE FOLLOWING SETTINGS RELATE TO LOGIN SSO FUNCTIONALITY
117 # LoginBackendDbusSSO121 # LoginBackendDbusSSO
118 # login()122 # login()
119 #***********************123 #***********************
120 # what to fake the login response as 124 # what to fake the login response as
121 # choices (strings): "successful", "failed", "denied"125 # choices (strings): "successful", "failed", "denied"
122 _FAKE_SETTINGS['login_response'] = "successful"126 _FAKE_SETTINGS['login_response'] = "successful"
123 127
124 # UbuntuSSOAPI128 # UbuntuSSOAPI
125 # whoami()129 # whoami()
126 #***********************130 #***********************
127 # what to fake whoami response as 131 # what to fake whoami response as
128 # choices (strings): "whoami", "error"132 # choices (strings): "whoami", "error"
129 _FAKE_SETTINGS['whoami_response'] = "whoami"133 _FAKE_SETTINGS['whoami_response'] = "whoami"
130 #this only has effect if whoami_response = 'whoami'134 #this only has effect if whoami_response = 'whoami'
@@ -132,65 +136,65 @@
132 #expects a string or None (for a random username)136 #expects a string or None (for a random username)
133 _FAKE_SETTINGS['whoami_username'] = None137 _FAKE_SETTINGS['whoami_username'] = None
134138
135
136 def __init__(self, defaults=False):139 def __init__(self, defaults=False):
137 '''Initialises the object and loads the settings into the _FAKE_SETTINGS140 '''Initialises the object and loads the settings into the
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
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
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
141 settings from the cache file being used again'''144 you don't want previously used settings from the cache file being
145 used again'''
142 fname = 'fake_review_settings.p'146 fname = 'fake_review_settings.p'
143 self.LOCATION = os.path.join(SOFTWARE_CENTER_CACHE_DIR, fname)147 self.LOCATION = os.path.join(SOFTWARE_CENTER_CACHE_DIR, fname)
144 if defaults:148 if defaults:
145 self._save_settings()149 self._save_settings()
146 else:150 else:
147 self._update_from_file()151 self._update_from_file()
148 return152
149
150 def update_setting(self, key_name, new_value):153 def update_setting(self, key_name, new_value):
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
152 and updates it with the value passed in (new_value).155 object and updates it with the value passed in (new_value).
153 Raises a NameError if the setting name doesn't exist'''156 Raises a NameError if the setting name doesn't exist'''
154 157
155 if not key_name in self._FAKE_SETTINGS:158 if not key_name in self._FAKE_SETTINGS:
156 raise NameError ('Setting key name %s does not exist' % key_name)159 raise NameError('Setting key name %s does not exist' % key_name)
157 else:160 else:
158 self._FAKE_SETTINGS[key_name] = new_value161 self._FAKE_SETTINGS[key_name] = new_value
159 self._save_settings()162 self._save_settings()
160 return163 return
161 164
162 def update_multiple(self, settings):165 def update_multiple(self, settings):
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
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
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
169 raised'''
166 for key, value in settings.items():170 for key, value in settings.items():
167 if not key in self._FAKE_SETTINGS:171 if not key in self._FAKE_SETTINGS:
168 raise NameError ('Setting key name %s does not exist' % key)172 raise NameError('Setting key name %s does not exist' % key)
169 173
170 for key, value in settings.items():174 for key, value in settings.items():
171 self._FAKE_SETTINGS[key] = value175 self._FAKE_SETTINGS[key] = value
172 self._save_settings()176 self._save_settings()
173 return177 return
174 178
175 def get_setting(self, key_name):179 def get_setting(self, key_name):
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
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
178 Raises a NameError if the setting name doesn't exist'''182 setting. Raises a NameError if the setting name doesn't exist'''
179 if not key_name in self._FAKE_SETTINGS:183 if not key_name in self._FAKE_SETTINGS:
180 raise NameError ('Setting %s does not exist' % key_name)184 raise NameError('Setting %s does not exist' % key_name)
181 else:185 else:
182 self._update_from_file()186 self._update_from_file()
183 return self._FAKE_SETTINGS[key_name]187 return self._FAKE_SETTINGS[key_name]
184 188
185 def _update_from_file(self):189 def _update_from_file(self):
186 '''Loads existing settings from cache file into _FAKE_SETTINGS dict'''190 '''Loads existing settings from cache file into _FAKE_SETTINGS dict'''
187 if os.path.exists(self.LOCATION):191 if os.path.exists(self.LOCATION):
188 try:192 try:
189 self._FAKE_SETTINGS = pickle.load(open(self.LOCATION))193 self._FAKE_SETTINGS = pickle.load(open(self.LOCATION))
190 except:194 except:
191 os.rename(self.LOCATION, self.LOCATION+".fail")195 os.rename(self.LOCATION, self.LOCATION + ".fail")
192 return196 return
193 197
194 def _save_settings(self):198 def _save_settings(self):
195 """write the dict out to cache file"""199 """write the dict out to cache file"""
196 try:200 try:
197201
=== modified file 'softwarecenter/backend/installbackend.py'
--- softwarecenter/backend/installbackend.py 2012-02-07 16:56:40 +0000
+++ softwarecenter/backend/installbackend.py 2012-03-19 14:27:20 +0000
@@ -18,32 +18,46 @@
1818
19from softwarecenter.utils import UnimplementedError19from softwarecenter.utils import UnimplementedError
2020
21
21class InstallBackend(object):22class InstallBackend(object):
22 def __init__(self):23 def __init__(self):
23 self.pending_transactions = {}24 self.pending_transactions = {}
24 self.pending_purchases = []25 self.pending_purchases = []
2526
26 def upgrade(self, app, iconname, addons_install=[], addons_remove=[], metadata=None):27 def upgrade(self, app, iconname, addons_install=[], addons_remove=[],
27 pass28 metadata=None):
28 def remove(self, app, iconname, addons_install=[], addons_remove=[], metadata=None):29 pass
29 pass30
30 def remove_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None):31 def remove(self, app, iconname, addons_install=[], addons_remove=[],
31 pass32 metadata=None):
32 def install(self, app, iconname, filename=None, addons_install=[], addons_remove=[], metadata=None):33 pass
33 pass34
34 def install_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None):35 def remove_multiple(self, apps, iconnames, addons_install=[],
35 pass36 addons_remove=[], metadatas=None):
36 def apply_changes(self, app, iconname, addons_install=[], addons_remove=[], metadata=None):37 pass
37 pass38
39 def install(self, app, iconname, filename=None, addons_install=[],
40 addons_remove=[], metadata=None):
41 pass
42
43 def install_multiple(self, apps, iconnames, addons_install=[],
44 addons_remove=[], metadatas=None):
45 pass
46
47 def apply_changes(self, app, iconname, addons_install=[],
48 addons_remove=[], metadata=None):
49 pass
50
38 def reload(self, sources_list=None, metadata=None):51 def reload(self, sources_list=None, metadata=None):
39 """ reload package list """52 """ reload package list """
40 pass53 pass
4154
55
42class InstallBackendUI(object):56class InstallBackendUI(object):
4357
44 def ask_config_file_conflict(self, old, new):58 def ask_config_file_conflict(self, old, new):
45 """ show a conffile conflict and ask what to do59 """ show a conffile conflict and ask what to do
46 Return "keep" to keep the old one 60 Return "keep" to keep the old one
47 "replace" to replace the old with the new one61 "replace" to replace the old with the new one
48 """62 """
49 raise UnimplementedError("need custom ask_config_file_conflict method")63 raise UnimplementedError("need custom ask_config_file_conflict method")
@@ -53,24 +67,27 @@
53 return True if medium is provided, False to cancel67 return True if medium is provided, False to cancel
54 """68 """
55 raise UnimplementedError("need custom ask_medium_required method")69 raise UnimplementedError("need custom ask_medium_required method")
56 70
57 def error(self, parent, primary, secondary, details=None, alternative_action=None):71 def error(self, parent, primary, secondary, details=None,
72 alternative_action=None):
58 """ show an error dialog """73 """ show an error dialog """
59 raise UnimplementedError("need custom error method")74 raise UnimplementedError("need custom error method")
6075
6176
62# singleton77# singleton
63install_backend = None78install_backend = None
79
80
64def get_install_backend():81def get_install_backend():
65 global install_backend82 global install_backend
66 if install_backend is None:83 if install_backend is None:
67 from softwarecenter.enums import USE_PACKAGEKIT_BACKEND84 from softwarecenter.enums import USE_PACKAGEKIT_BACKEND
68 if not USE_PACKAGEKIT_BACKEND:85 if not USE_PACKAGEKIT_BACKEND:
69 from softwarecenter.backend.installbackend_impl.aptd import AptdaemonBackend86 from softwarecenter.backend.installbackend_impl.aptd import (
87 AptdaemonBackend)
70 install_backend = AptdaemonBackend()88 install_backend = AptdaemonBackend()
71 else:89 else:
72 from softwarecenter.backend.installbackend_impl.packagekitd import PackagekitBackend90 from softwarecenter.backend.installbackend_impl.packagekitd \
91 import PackagekitBackend
73 install_backend = PackagekitBackend()92 install_backend = PackagekitBackend()
74 return install_backend93 return install_backend
75
76
7794
=== modified file 'softwarecenter/backend/launchpad.py'
--- softwarecenter/backend/launchpad.py 2012-02-13 19:56:12 +0000
+++ softwarecenter/backend/launchpad.py 2012-03-19 14:27:20 +0000
@@ -35,7 +35,7 @@
35# py3 compat35# py3 compat
36try:36try:
37 from queue import Queue37 from queue import Queue
38 Queue # pyflakes38 Queue # pyflakes
39except ImportError:39except ImportError:
40 from Queue import Queue40 from Queue import Queue
4141
@@ -55,16 +55,18 @@
55LOGIN_STATE_AUTH_FAILURE = "auth-fail"55LOGIN_STATE_AUTH_FAILURE = "auth-fail"
56LOGIN_STATE_USER_CANCEL = "user-cancel"56LOGIN_STATE_USER_CANCEL = "user-cancel"
5757
58
58class UserCancelException(Exception):59class UserCancelException(Exception):
59 """ user pressed cancel """60 """ user pressed cancel """
60 pass61 pass
6162
63
62class LaunchpadlibWorker(threading.Thread):64class LaunchpadlibWorker(threading.Thread):
63 """The launchpadlib worker thread - it does not touch the UI65 """The launchpadlib worker thread - it does not touch the UI
64 and only communicates via the following:66 and only communicates via the following:
6567
66 "login_state" - the current LOGIN_STATE_* value68 "login_state" - the current LOGIN_STATE_* value
67 69
68 To input reviews call "queue_review()"70 To input reviews call "queue_review()"
69 When no longer needed, call "shutdown()"71 When no longer needed, call "shutdown()"
70 """72 """
@@ -128,7 +130,7 @@
128 try:130 try:
129 self._launchpad = Launchpad.login_with(131 self._launchpad = Launchpad.login_with(
130 'software-center', SERVICE_ROOT, cachedir,132 'software-center', SERVICE_ROOT, cachedir,
131 allow_access_levels = access_level,133 allow_access_levels=access_level,
132 authorizer_class=AuthorizeRequestTokenFromThread)134 authorizer_class=AuthorizeRequestTokenFromThread)
133 self.display_name = self._launchpad.me.display_name135 self.display_name = self._launchpad.me.display_name
134 except Exception as e:136 except Exception as e:
@@ -141,7 +143,8 @@
141 (service_root, launchpadlib_dir, cache_path,143 (service_root, launchpadlib_dir, cache_path,
142 service_root_dir) = Launchpad._get_paths(SERVICE_ROOT, cachedir)144 service_root_dir) = Launchpad._get_paths(SERVICE_ROOT, cachedir)
143 credentials_path = os.path.join(service_root_dir, 'credentials')145 credentials_path = os.path.join(service_root_dir, 'credentials')
144 consumer_credentials_path = os.path.join(credentials_path, 'software-center')146 consumer_credentials_path = os.path.join(credentials_path,
147 'software-center')
145 # ---148 # ---
146 if os.path.exists(consumer_credentials_path):149 if os.path.exists(consumer_credentials_path):
147 os.remove(consumer_credentials_path)150 os.remove(consumer_credentials_path)
@@ -150,11 +153,12 @@
150 self.login_state = LOGIN_STATE_SUCCESS153 self.login_state = LOGIN_STATE_SUCCESS
151 self._logger.debug("/done %s" % self._launchpad)154 self._logger.debug("/done %s" % self._launchpad)
152155
156
153class AuthorizeRequestTokenFromThread(RequestTokenAuthorizationEngine):157class AuthorizeRequestTokenFromThread(RequestTokenAuthorizationEngine):
154 """ Internal helper that updates the login_state of158 """ Internal helper that updates the login_state of
155 the modul global lp_worker_thread object159 the modul global lp_worker_thread object
156 """160 """
157 def __init__ (self, *args, **kwargs):161 def __init__(self, *args, **kwargs):
158 super(AuthorizeRequestTokenFromThread, self).__init__(*args, **kwargs)162 super(AuthorizeRequestTokenFromThread, self).__init__(*args, **kwargs)
159 self._logger = logging.getLogger("softwarecenter.backend")163 self._logger = logging.getLogger("softwarecenter.backend")
160164
@@ -167,7 +171,7 @@
167 return o171 return o
168172
169 def input_username(self, cached_username, suggested_message):173 def input_username(self, cached_username, suggested_message):
170 self._logger.debug( "input_username: %s" %self.lp_worker.login_state)174 self._logger.debug("input_username: %s" % self.lp_worker.login_state)
171 # otherwise go into ASK state175 # otherwise go into ASK state
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,
173 LOGIN_STATE_AUTH_FAILURE,177 LOGIN_STATE_AUTH_FAILURE,
@@ -185,7 +189,8 @@
185 return self.lp_worker.login_username189 return self.lp_worker.login_username
186190
187 def input_password(self, suggested_message):191 def input_password(self, suggested_message):
188 self._logger.debug( "Input password size %s" % len(self.lp_worker.login_password))192 self._logger.debug("Input password size %s" %
193 len(self.lp_worker.login_password))
189 return self.lp_worker.login_password194 return self.lp_worker.login_password
190195
191 def input_access_level(self, available_levels, suggested_message,196 def input_access_level(self, available_levels, suggested_message,
@@ -217,7 +222,7 @@
217 """222 """
218223
219 NEW_ACCOUNT_URL = "https://login.launchpad.net/+standalone-login"224 NEW_ACCOUNT_URL = "https://login.launchpad.net/+standalone-login"
220 FORGOT_PASSWORD_URL = "https://login.launchpad.net/+standalone-login"225 FORGOT_PASSWORD_URL = "https://login.launchpad.net/+standalone-login"
221226
222 def __init__(self):227 def __init__(self):
223 LoginBackend.__init__(self)228 LoginBackend.__init__(self)
@@ -238,13 +243,13 @@
238 lp_worker_thread.shutdown()243 lp_worker_thread.shutdown()
239244
240 def enter_username_password(self, user, password):245 def enter_username_password(self, user, password):
241 """ 246 """
242 provider username and password, ususally used when the247 provider username and password, ususally used when the
243 need-username-password signal was send248 need-username-password signal was send
244 """249 """
245 lp_worker_thread.login_username = user250 lp_worker_thread.login_username = user
246 lp_worker_thread.login_password = password251 lp_worker_thread.login_password = password
247 lp_worker_thread.login_state = LOGIN_STATE_HAS_USER_AND_PASS 252 lp_worker_thread.login_state = LOGIN_STATE_HAS_USER_AND_PASS
248253
249 def login(self, username=None, password=None):254 def login(self, username=None, password=None):
250 if username and password:255 if username and password:
@@ -254,17 +259,17 @@
254259
255 def cancel_login(self):260 def cancel_login(self):
256 lp_worker_thread.login_state = LOGIN_STATE_USER_CANCEL261 lp_worker_thread.login_state = LOGIN_STATE_USER_CANCEL
257 262
258 def get_subscribed_archives(self):263 def get_subscribed_archives(self):
259 """ return list of sources.list entries """264 """ return list of sources.list entries """
260 urls = lp_worker_thread._launchpad.me.getArchiveSubscriptionURLs()265 urls = lp_worker_thread._launchpad.me.getArchiveSubscriptionURLs()
261 return self._format_archive_subscription_urls_as_deb_lines(urls)266 return self._format_archive_subscription_urls_as_deb_lines(urls)
262 267
263 def _format_archive_subscription_urls_as_deb_lines(self, urls):268 def _format_archive_subscription_urls_as_deb_lines(self, urls):
264 deb_lines = ["deb %s %s main" % (url, self.distro.get_codename()) \269 deb_lines = ["deb %s %s main" % (url, self.distro.get_codename()) \
265 for url in urls]270 for url in urls]
266 return deb_lines271 return deb_lines
267 272
268 def get_subscribed_archives_async(self, callback):273 def get_subscribed_archives_async(self, callback):
269 """ get the available subscribed archives and run 'callback' when274 """ get the available subscribed archives and run 'callback' when
270 they become availalbe275 they become availalbe
@@ -300,10 +305,16 @@
300 print ("success %s" % lp)305 print ("success %s" % lp)
301 print(lp.get_subscribed_archives())306 print(lp.get_subscribed_archives())
302 print(lp.get_subscribed_archives_async(_result_callback))307 print(lp.get_subscribed_archives_async(_result_callback))
308
309
303def _login_failed(lp):310def _login_failed(lp):
304 print ("fail %s" % lp)311 print ("fail %s" % lp)
312
313
305def _result_callback(result_list):314def _result_callback(result_list):
306 print("_result_callback %s" % result_list)315 print("_result_callback %s" % result_list)
316
317
307def _login_need_user_and_password(lp):318def _login_need_user_and_password(lp):
308 import sys319 import sys
309 sys.stdout.write("user: ")320 sys.stdout.write("user: ")
310321
=== modified file 'softwarecenter/backend/login.py'
--- softwarecenter/backend/login.py 2012-01-05 15:01:43 +0000
+++ softwarecenter/backend/login.py 2012-03-19 14:27:20 +0000
@@ -21,31 +21,33 @@
2121
22from gi.repository import GObject22from gi.repository import GObject
2323
24
24class LoginBackend(GObject.GObject):25class LoginBackend(GObject.GObject):
2526
26 NEW_ACCOUNT_URL = None27 NEW_ACCOUNT_URL = None
27 FORGOT_PASSWORD_URL = None28 FORGOT_PASSWORD_URL = None
2829
29 __gsignals__ = {30 __gsignals__ = {
30 "login-successful" : (GObject.SIGNAL_RUN_LAST,31 "login-successful": (GObject.SIGNAL_RUN_LAST,
31 GObject.TYPE_NONE, 32 GObject.TYPE_NONE,
32 (GObject.TYPE_PYOBJECT,),33 (GObject.TYPE_PYOBJECT,),
33 ),34 ),
34 "login-failed" : (GObject.SIGNAL_RUN_LAST,35 "login-failed": (GObject.SIGNAL_RUN_LAST,
35 GObject.TYPE_NONE, 36 GObject.TYPE_NONE,
36 (),37 (),
37 ),38 ),
38 "login-canceled" : (GObject.SIGNAL_RUN_LAST,39 "login-canceled": (GObject.SIGNAL_RUN_LAST,
39 GObject.TYPE_NONE, 40 GObject.TYPE_NONE,
40 (),41 (),
41 ),42 ),
42 "need-username-password" : (GObject.SIGNAL_RUN_LAST,43 "need-username-password": (GObject.SIGNAL_RUN_LAST,
43 GObject.TYPE_NONE, 44 GObject.TYPE_NONE,
44 (),45 (),
45 ),46 ),
46 }47 }
4748
48 def login(self, username=None, password=None):49 def login(self, username=None, password=None):
49 raise NotImplemented50 raise NotImplemented
51
50 def cancel_login(self):52 def cancel_login(self):
51 self.emit("login-canceled")53 self.emit("login-canceled")
5254
=== modified file 'softwarecenter/backend/login_sso.py'
--- softwarecenter/backend/login_sso.py 2012-03-14 15:45:47 +0000
+++ softwarecenter/backend/login_sso.py 2012-03-19 14:27:20 +0000
@@ -36,6 +36,7 @@
3636
37LOG = logging.getLogger(__name__)37LOG = logging.getLogger(__name__)
3838
39
39class LoginBackendDbusSSO(LoginBackend):40class LoginBackendDbusSSO(LoginBackend):
4041
41 def __init__(self, window_id, appname, help_text):42 def __init__(self, window_id, appname, help_text):
@@ -45,11 +46,11 @@
45 self.bus = dbus.SessionBus()46 self.bus = dbus.SessionBus()
46 self.proxy = self.bus.get_object(47 self.proxy = self.bus.get_object(
47 'com.ubuntu.sso', '/com/ubuntu/sso/credentials')48 'com.ubuntu.sso', '/com/ubuntu/sso/credentials')
48 self.proxy.connect_to_signal("CredentialsFound", 49 self.proxy.connect_to_signal("CredentialsFound",
49 self._on_credentials_found)50 self._on_credentials_found)
50 self.proxy.connect_to_signal("CredentialsError", 51 self.proxy.connect_to_signal("CredentialsError",
51 self._on_credentials_error)52 self._on_credentials_error)
52 self.proxy.connect_to_signal("AuthorizationDenied", 53 self.proxy.connect_to_signal("AuthorizationDenied",
53 self._on_authorization_denied)54 self._on_authorization_denied)
54 self._window_id = window_id55 self._window_id = window_id
55 self._credentials = None56 self._credentials = None
@@ -66,7 +67,7 @@
66 LOG.debug("login()")67 LOG.debug("login()")
67 self._credentials = None68 self._credentials = None
68 self.proxy.login(self.appname, self._get_params())69 self.proxy.login(self.appname, self._get_params())
69 70
70 def login_or_register(self):71 def login_or_register(self):
71 LOG.debug("login_or_register()")72 LOG.debug("login_or_register()")
72 self._credentials = None73 self._credentials = None
@@ -82,7 +83,6 @@
82 if self._credentials != credentials:83 if self._credentials != credentials:
83 self.emit("login-successful", credentials)84 self.emit("login-successful", credentials)
84 self._credentials = credentials85 self._credentials = credentials
85
8686
87 def _on_credentials_error(self, app_name, error, detailed_error=""):87 def _on_credentials_error(self, app_name, error, detailed_error=""):
88 LOG.error("_on_credentails_error for %s: %s (%s)" % (88 LOG.error("_on_credentails_error for %s: %s (%s)" % (
@@ -107,55 +107,62 @@
107 self.help_text = help_text107 self.help_text = help_text
108 self._window_id = window_id108 self._window_id = window_id
109 self._fake_settings = FakeReviewSettings()109 self._fake_settings = FakeReviewSettings()
110 110
111 @network_delay111 @network_delay
112 def login(self, username=None, password=None):112 def login(self, username=None, password=None):
113 response = self._fake_settings.get_setting('login_response')113 response = self._fake_settings.get_setting('login_response')
114 114
115 if response == "successful":115 if response == "successful":
116 self.emit("login-successful", self._return_credentials())116 self.emit("login-successful", self._return_credentials())
117 elif response == "failed":117 elif response == "failed":
118 self.emit("login-failed")118 self.emit("login-failed")
119 elif response == "denied":119 elif response == "denied":
120 self.cancel_login()120 self.cancel_login()
121 121
122 return122 return
123 123
124 def login_or_register(self):124 def login_or_register(self):
125 #fake functionality for this is no different to fake login()125 #fake functionality for this is no different to fake login()
126 self.login()126 self.login()
127 return127 return
128 128
129 def _random_unicode_string(self, length):129 def _random_unicode_string(self, length):
130 retval = ''130 retval = ''
131 for i in range(0,length):131 for i in range(0, length):
132 retval = retval + random.choice(string.letters + string.digits)132 retval = retval + random.choice(string.letters + string.digits)
133 return retval.decode('utf-8')133 return retval.decode('utf-8')
134 134
135 def _return_credentials(self):135 def _return_credentials(self):
136 c = dbus.Dictionary(136 c = dbus.Dictionary(
137 {137 {
138 dbus.String(u'consumer_secret'): dbus.String(self._random_unicode_string(30)),138 dbus.String(u'consumer_secret'): dbus.String(
139 dbus.String(u'token') : dbus.String(self._random_unicode_string(50)),139 self._random_unicode_string(30)),
140 dbus.String(u'consumer_key') : dbus.String(self._random_unicode_string(7)),140 dbus.String(u'token'): dbus.String(
141 dbus.String(u'name') : dbus.String('Ubuntu Software Center @ ' + self._random_unicode_string(6)),141 self._random_unicode_string(50)),
142 dbus.String(u'token_secret') : dbus.String(self._random_unicode_string(50))142 dbus.String(u'consumer_key'): dbus.String(
143 }, 143 self._random_unicode_string(7)),
144 dbus.String(u'name'): dbus.String('Ubuntu Software Center @ ' +
145 self._random_unicode_string(6)),
146 dbus.String(u'token_secret'): dbus.String(
147 self._random_unicode_string(50))
148 },
144 signature=dbus.Signature('ss')149 signature=dbus.Signature('ss')
145 )150 )
146 return c151 return c
147152
153
148def get_sso_backend(window_id, appname, help_text):154def get_sso_backend(window_id, appname, help_text):
149 """ 155 """
150 factory that returns an sso loader singelton156 factory that returns an sso loader singelton
151 """157 """
152 if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ:158 if "SOFTWARE_CENTER_FAKE_REVIEW_API" in os.environ:
153 sso_class = LoginBackendDbusSSOFake(window_id, appname, help_text)159 sso_class = LoginBackendDbusSSOFake(window_id, appname, help_text)
154 LOG.warn('Using fake login SSO functionality. Only meant for testing purposes')160 LOG.warn('Using fake login SSO functionality. Only meant for '
161 'testing purposes')
155 else:162 else:
156 sso_class = LoginBackendDbusSSO(window_id, appname, help_text)163 sso_class = LoginBackendDbusSSO(window_id, appname, help_text)
157 return sso_class164 return sso_class
158 165
159if __name__ == "__main__":166if __name__ == "__main__":
160 logging.basicConfig(level=logging.DEBUG)167 logging.basicConfig(level=logging.DEBUG)
161168
162169
=== modified file 'softwarecenter/backend/recagent.py'
--- softwarecenter/backend/recagent.py 2012-03-12 21:28:10 +0000
+++ softwarecenter/backend/recagent.py 2012-03-19 14:27:20 +0000
@@ -31,47 +31,48 @@
3131
32LOG = logging.getLogger(__name__)32LOG = logging.getLogger(__name__)
3333
34
34class RecommenderAgent(GObject.GObject):35class RecommenderAgent(GObject.GObject):
3536
36 __gsignals__ = {37 __gsignals__ = {
37 "server-status" : (GObject.SIGNAL_RUN_LAST,38 "server-status": (GObject.SIGNAL_RUN_LAST,
38 GObject.TYPE_NONE, 39 GObject.TYPE_NONE,
39 (GObject.TYPE_PYOBJECT,),40 (GObject.TYPE_PYOBJECT,),
40 ),41 ),
41 "profile" : (GObject.SIGNAL_RUN_LAST,42 "profile": (GObject.SIGNAL_RUN_LAST,
42 GObject.TYPE_NONE, 43 GObject.TYPE_NONE,
43 (GObject.TYPE_PYOBJECT,),44 (GObject.TYPE_PYOBJECT,),
44 ),45 ),
45 "submit-profile-finished" : (GObject.SIGNAL_RUN_LAST,46 "submit-profile-finished": (GObject.SIGNAL_RUN_LAST,
46 GObject.TYPE_NONE, 47 GObject.TYPE_NONE,
47 (GObject.TYPE_PYOBJECT, str),48 (GObject.TYPE_PYOBJECT, str),
48 ),49 ),
49 "submit-anon-profile-finished" : (GObject.SIGNAL_RUN_LAST,50 "submit-anon-profile-finished": (GObject.SIGNAL_RUN_LAST,
50 GObject.TYPE_NONE, 51 GObject.TYPE_NONE,
51 (GObject.TYPE_PYOBJECT,),52 (GObject.TYPE_PYOBJECT,),
52 ),53 ),
53 "recommend-me" : (GObject.SIGNAL_RUN_LAST,54 "recommend-me": (GObject.SIGNAL_RUN_LAST,
54 GObject.TYPE_NONE, 55 GObject.TYPE_NONE,
55 (GObject.TYPE_PYOBJECT,),56 (GObject.TYPE_PYOBJECT,),
56 ),57 ),
57 "recommend-app" : (GObject.SIGNAL_RUN_LAST,58 "recommend-app": (GObject.SIGNAL_RUN_LAST,
58 GObject.TYPE_NONE, 59 GObject.TYPE_NONE,
59 (GObject.TYPE_PYOBJECT,),60 (GObject.TYPE_PYOBJECT,),
60 ),61 ),
61 "recommend-all-apps" : (GObject.SIGNAL_RUN_LAST,62 "recommend-all-apps": (GObject.SIGNAL_RUN_LAST,
62 GObject.TYPE_NONE, 63 GObject.TYPE_NONE,
63 (GObject.TYPE_PYOBJECT,),64 (GObject.TYPE_PYOBJECT,),
64 ),65 ),
65 "recommend-top" : (GObject.SIGNAL_RUN_LAST,66 "recommend-top": (GObject.SIGNAL_RUN_LAST,
66 GObject.TYPE_NONE, 67 GObject.TYPE_NONE,
67 (GObject.TYPE_PYOBJECT,),68 (GObject.TYPE_PYOBJECT,),
68 ),69 ),
69 "error" : (GObject.SIGNAL_RUN_LAST,70 "error": (GObject.SIGNAL_RUN_LAST,
70 GObject.TYPE_NONE, 71 GObject.TYPE_NONE,
71 (str,),72 (str,),
72 ),73 ),
73 }74 }
74 75
75 def __init__(self, xid=None):76 def __init__(self, xid=None):
76 GObject.GObject.__init__(self)77 GObject.GObject.__init__(self)
77 self.xid = xid78 self.xid = xid
@@ -86,17 +87,17 @@
86 spawner.connect("error", lambda spawner, err: self.emit("error", err))87 spawner.connect("error", lambda spawner, err: self.emit("error", err))
87 spawner.run_generic_piston_helper(88 spawner.run_generic_piston_helper(
88 "SoftwareCenterRecommenderAPI", "server_status")89 "SoftwareCenterRecommenderAPI", "server_status")
89 90
90 def post_submit_profile(self, db):91 def post_submit_profile(self, db):
91 """ This will post the users profile to the recommender server92 """ This will post the users profile to the recommender server
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
93 there yet94 there yet
94 """95 """
95 # if we have not already set a recommender UUID, now is the time96 # if we have not already set a recommender UUID, now is the time
96 # to do it97 # to do it
97 if not self.recommender_uuid:98 if not self.recommender_uuid:
98 self.recommender_uuid = get_uuid()99 self.recommender_uuid = get_uuid()
99 installed_pkglist = [app.pkgname 100 installed_pkglist = [app.pkgname
100 for app in get_installed_apps_list(db)]101 for app in get_installed_apps_list(db)]
101 data = self._generate_submit_profile_data(self.recommender_uuid,102 data = self._generate_submit_profile_data(self.recommender_uuid,
102 installed_pkglist)103 installed_pkglist)
@@ -110,7 +111,7 @@
110 "SoftwareCenterRecommenderAPI",111 "SoftwareCenterRecommenderAPI",
111 "submit_profile",112 "submit_profile",
112 data=data)113 data=data)
113 114
114 def post_submit_anon_profile(self, uuid, installed_packages, extra):115 def post_submit_anon_profile(self, uuid, installed_packages, extra):
115 # build the command116 # build the command
116 spawner = SpawnHelper()117 spawner = SpawnHelper()
@@ -124,7 +125,7 @@
124 uuid=uuid,125 uuid=uuid,
125 installed_packages=installed_packages,126 installed_packages=installed_packages,
126 extra=extra)127 extra=extra)
127 128
128 def query_profile(self, pkgnames):129 def query_profile(self, pkgnames):
129 # build the command130 # build the command
130 spawner = SpawnHelper()131 spawner = SpawnHelper()
@@ -146,7 +147,7 @@
146 spawner.connect("error", lambda spawner, err: self.emit("error", err))147 spawner.connect("error", lambda spawner, err: self.emit("error", err))
147 spawner.run_generic_piston_helper(148 spawner.run_generic_piston_helper(
148 "SoftwareCenterRecommenderAPI", "recommend_me")149 "SoftwareCenterRecommenderAPI", "recommend_me")
149 150
150 def query_recommend_app(self, pkgname):151 def query_recommend_app(self, pkgname):
151 # build the command152 # build the command
152 spawner = SpawnHelper()153 spawner = SpawnHelper()
@@ -157,7 +158,7 @@
157 "SoftwareCenterRecommenderAPI",158 "SoftwareCenterRecommenderAPI",
158 "recommend_app",159 "recommend_app",
159 pkgname=pkgname)160 pkgname=pkgname)
160 161
161 def query_recommend_all_apps(self):162 def query_recommend_all_apps(self):
162 # build the command163 # build the command
163 spawner = SpawnHelper()164 spawner = SpawnHelper()
@@ -166,7 +167,7 @@
166 spawner.connect("error", lambda spawner, err: self.emit("error", err))167 spawner.connect("error", lambda spawner, err: self.emit("error", err))
167 spawner.run_generic_piston_helper(168 spawner.run_generic_piston_helper(
168 "SoftwareCenterRecommenderAPI", "recommend_all_apps")169 "SoftwareCenterRecommenderAPI", "recommend_all_apps")
169 170
170 def query_recommend_top(self):171 def query_recommend_top(self):
171 # build the command172 # build the command
172 spawner = SpawnHelper()173 spawner = SpawnHelper()
@@ -175,7 +176,7 @@
175 spawner.connect("error", lambda spawner, err: self.emit("error", err))176 spawner.connect("error", lambda spawner, err: self.emit("error", err))
176 spawner.run_generic_piston_helper(177 spawner.run_generic_piston_helper(
177 "SoftwareCenterRecommenderAPI", "recommend_top")178 "SoftwareCenterRecommenderAPI", "recommend_top")
178 179
179 def is_opted_in(self):180 def is_opted_in(self):
180 """181 """
181 Return True is the user is currently opted-in to the recommender182 Return True is the user is currently opted-in to the recommender
@@ -185,33 +186,34 @@
185 return True186 return True
186 else:187 else:
187 return False188 return False
188 189
189 def _on_server_status_data(self, spawner, piston_server_status):190 def _on_server_status_data(self, spawner, piston_server_status):
190 self.emit("server-status", piston_server_status)191 self.emit("server-status", piston_server_status)
191 192
192 def _on_profile_data(self, spawner, piston_profile):193 def _on_profile_data(self, spawner, piston_profile):
193 self.emit("profile", piston_profile)194 self.emit("profile", piston_profile)
194 195
195 def _on_submit_profile_data(self, spawner, piston_submit_profile):196 def _on_submit_profile_data(self, spawner, piston_submit_profile):
196 self.emit("submit-profile-finished", 197 self.emit("submit-profile-finished",
197 piston_submit_profile, 198 piston_submit_profile,
198 self.recommender_uuid)199 self.recommender_uuid)
199 200
200 def _on_submit_anon_profile_data(self, spawner, piston_submit_anon_profile):201 def _on_submit_anon_profile_data(self, spawner,
202 piston_submit_anon_profile):
201 self.emit("submit-anon_profile", piston_submit_anon_profile)203 self.emit("submit-anon_profile", piston_submit_anon_profile)
202204
203 def _on_recommend_me_data(self, spawner, piston_me_apps):205 def _on_recommend_me_data(self, spawner, piston_me_apps):
204 self.emit("recommend-me", piston_me_apps)206 self.emit("recommend-me", piston_me_apps)
205 207
206 def _on_recommend_app_data(self, spawner, piston_app):208 def _on_recommend_app_data(self, spawner, piston_app):
207 self.emit("recommend-app", piston_app)209 self.emit("recommend-app", piston_app)
208 210
209 def _on_recommend_all_apps_data(self, spawner, piston_all_apps):211 def _on_recommend_all_apps_data(self, spawner, piston_all_apps):
210 self.emit("recommend-all-apps", piston_all_apps)212 self.emit("recommend-all-apps", piston_all_apps)
211 213
212 def _on_recommend_top_data(self, spawner, piston_top_apps):214 def _on_recommend_top_data(self, spawner, piston_top_apps):
213 self.emit("recommend-top", piston_top_apps)215 self.emit("recommend-top", piston_top_apps)
214 216
215 def _get_recommender_uuid(self):217 def _get_recommender_uuid(self):
216 """ returns the recommender UUID value, which can be empty if it218 """ returns the recommender UUID value, which can be empty if it
217 has not yet been set (indicating that the user has not yet219 has not yet been set (indicating that the user has not yet
@@ -223,24 +225,24 @@
223 if recommender_uuid:225 if recommender_uuid:
224 return recommender_uuid226 return recommender_uuid
225 return ""227 return ""
226 228
227 def _generate_submit_profile_data(self, recommender_uuid, package_list):229 def _generate_submit_profile_data(self, recommender_uuid, package_list):
228 submit_profile_data = [230 submit_profile_data = [{
229 {231 'uuid': recommender_uuid,
230 'uuid': recommender_uuid, 232 'package_list': package_list
231 'package_list': package_list233 }]
232 }
233 ]
234 return submit_profile_data234 return submit_profile_data
235235
236 236
237if __name__ == "__main__":237if __name__ == "__main__":
238 from gi.repository import Gtk238 from gi.repository import Gtk
239239
240 def _recommend_top(agent, top_apps):240 def _recommend_top(agent, top_apps):
241 print ("_recommend_top: %s" % top_apps)241 print ("_recommend_top: %s" % top_apps)
242
242 def _recommend_me(agent, top_apps):243 def _recommend_me(agent, top_apps):
243 print ("_recommend_me: %s" % top_apps)244 print ("_recommend_me: %s" % top_apps)
245
244 def _error(agent, msg):246 def _error(agent, msg):
245 print ("got a error: %s" % msg)247 print ("got a error: %s" % msg)
246 Gtk.main_quit()248 Gtk.main_quit()
@@ -256,5 +258,4 @@
256 agent.query_recommend_top()258 agent.query_recommend_top()
257 agent.query_recommend_me()259 agent.query_recommend_me()
258260
259
260 Gtk.main()261 Gtk.main()
261262
=== modified file 'softwarecenter/backend/scagent.py'
--- softwarecenter/backend/scagent.py 2012-01-17 15:56:14 +0000
+++ softwarecenter/backend/scagent.py 2012-03-19 14:27:20 +0000
@@ -29,27 +29,28 @@
2929
30LOG = logging.getLogger(__name__)30LOG = logging.getLogger(__name__)
3131
32
32class SoftwareCenterAgent(GObject.GObject):33class SoftwareCenterAgent(GObject.GObject):
3334
34 __gsignals__ = {35 __gsignals__ = {
35 "available-for-me" : (GObject.SIGNAL_RUN_LAST,36 "available-for-me": (GObject.SIGNAL_RUN_LAST,
36 GObject.TYPE_NONE, 37 GObject.TYPE_NONE,
37 (GObject.TYPE_PYOBJECT,),38 (GObject.TYPE_PYOBJECT,),
38 ),39 ),
39 "available" : (GObject.SIGNAL_RUN_LAST,40 "available": (GObject.SIGNAL_RUN_LAST,
40 GObject.TYPE_NONE, 41 GObject.TYPE_NONE,
41 (GObject.TYPE_PYOBJECT,),42 (GObject.TYPE_PYOBJECT,),
42 ),43 ),
43 "exhibits" : (GObject.SIGNAL_RUN_LAST,44 "exhibits": (GObject.SIGNAL_RUN_LAST,
44 GObject.TYPE_NONE, 45 GObject.TYPE_NONE,
45 (GObject.TYPE_PYOBJECT,),46 (GObject.TYPE_PYOBJECT,),
46 ),47 ),
47 "error" : (GObject.SIGNAL_RUN_LAST,48 "error": (GObject.SIGNAL_RUN_LAST,
48 GObject.TYPE_NONE, 49 GObject.TYPE_NONE,
49 (str,),50 (str,),
50 ),51 ),
51 }52 }
52 53
53 def __init__(self, ignore_cache=False, xid=None):54 def __init__(self, ignore_cache=False, xid=None):
54 GObject.GObject.__init__(self)55 GObject.GObject.__init__(self)
55 self.distro = get_distro()56 self.distro = get_distro()
@@ -103,7 +104,8 @@
103 "SoftwareCenterAgentAPI", "subscriptions_for_me",104 "SoftwareCenterAgentAPI", "subscriptions_for_me",
104 complete_only=True)105 complete_only=True)
105106
106 def _on_query_available_for_me_data(self, spawner, piston_available_for_me):107 def _on_query_available_for_me_data(self, spawner,
108 piston_available_for_me):
107 self.emit("available-for-me", piston_available_for_me)109 self.emit("available-for-me", piston_available_for_me)
108110
109 def query_exhibits(self):111 def query_exhibits(self):
@@ -113,7 +115,7 @@
113 spawner.connect("data-available", self._on_exhibits_data_available)115 spawner.connect("data-available", self._on_exhibits_data_available)
114 spawner.connect("error", lambda spawner, err: self.emit("error", err))116 spawner.connect("error", lambda spawner, err: self.emit("error", err))
115 spawner.run_generic_piston_helper(117 spawner.run_generic_piston_helper(
116 "SoftwareCenterAgentAPI", "exhibits", 118 "SoftwareCenterAgentAPI", "exhibits",
117 lang=get_language(), series=self.distro.get_codename())119 lang=get_language(), series=self.distro.get_codename())
118120
119 def _on_exhibits_data_available(self, spawner, exhibits):121 def _on_exhibits_data_available(self, spawner, exhibits):
@@ -123,18 +125,22 @@
123 if not hasattr(exhibit, "title_translated"):125 if not hasattr(exhibit, "title_translated"):
124 if exhibit.html:126 if exhibit.html:
125 from softwarecenter.utils import get_title_from_html127 from softwarecenter.utils import get_title_from_html
126 exhibit.title_translated = get_title_from_html(exhibit.html)128 exhibit.title_translated = get_title_from_html(
129 exhibit.html)
127 else:130 else:
128 exhibit.title_translated = ""131 exhibit.title_translated = ""
129 self.emit("exhibits", exhibits)132 self.emit("exhibits", exhibits)
130 133
131if __name__ == "__main__":134if __name__ == "__main__":
132 def _available(agent, available):135 def _available(agent, available):
133 print ("_available: %s" % available)136 print ("_available: %s" % available)
137
134 def _available_for_me(agent, available_for_me):138 def _available_for_me(agent, available_for_me):
135 print ("_availalbe_for_me: %s" % available_for_me)139 print ("_availalbe_for_me: %s" % available_for_me)
140
136 def _exhibits(agent, exhibits):141 def _exhibits(agent, exhibits):
137 print ("exhibits: " % exhibits)142 print ("exhibits: " % exhibits)
143
138 def _error(agent, msg):144 def _error(agent, msg):
139 print ("got a error" % msg)145 print ("got a error" % msg)
140 #gtk.main_quit()146 #gtk.main_quit()
141147
=== modified file 'softwarecenter/hw.py'
--- softwarecenter/hw.py 2012-03-19 11:32:58 +0000
+++ softwarecenter/hw.py 2012-03-19 14:27:20 +0000
@@ -79,10 +79,12 @@
79 u'computer is using.'),79 u'computer is using.'),
80}80}
8181
82
82def get_hw_short_description(tag):83def get_hw_short_description(tag):
83 s = TAG_DESCRIPTION.get(tag)84 s = TAG_DESCRIPTION.get(tag)
84 return utf8(s)85 return utf8(s)
8586
87
86def get_hw_missing_long_description(tags):88def get_hw_missing_long_description(tags):
87 s = ""89 s = ""
88 # build string90 # build string
@@ -94,7 +96,7 @@
94 else:96 else:
95 # deal with generic tags97 # deal with generic tags
96 prefix, sep, postfix = tag.rpartition(":")98 prefix, sep, postfix = tag.rpartition(":")
97 descr = TAG_MISSING_DESCRIPTION.get(prefix+sep)99 descr = TAG_MISSING_DESCRIPTION.get(prefix + sep)
98 descr = descr % postfix100 descr = descr % postfix
99 if descr:101 if descr:
100 s += "%s\n" % descr102 s += "%s\n" % descr
@@ -116,8 +118,9 @@
116 res[tag] = debtagshw.enums.HardwareSupported.YES118 res[tag] = debtagshw.enums.HardwareSupported.YES
117 return res119 return res
118120
121
119def get_hardware_support_for_tags(tags):122def get_hardware_support_for_tags(tags):
120 """ wrapper around the DebtagsAvailalbeHW to support adding our own 123 """ wrapper around the DebtagsAvailalbeHW to support adding our own
121 private tag extension (like opengl-driver)124 private tag extension (like opengl-driver)
122 """125 """
123 from debtagshw.debtagshw import DebtagsAvailableHW126 from debtagshw.debtagshw import DebtagsAvailableHW
124127
=== modified file 'softwarecenter/testutils.py'
--- softwarecenter/testutils.py 2012-03-15 21:19:02 +0000
+++ softwarecenter/testutils.py 2012-03-19 14:27:20 +0000
@@ -230,7 +230,7 @@
230 },230 },
231 {231 {
232 u'package_name': u'mangler'232 u'package_name': u'mangler'
233 }, 233 },
234 {234 {
235 u'package_name': u'nexuiz'235 u'package_name': u'nexuiz'
236 },236 },
@@ -254,7 +254,7 @@
254 },254 },
255 {255 {
256 u'package_name': u'psi'256 u'package_name': u'psi'
257 }, 257 },
258 {258 {
259 u'package_name': u'midori'259 u'package_name': u'midori'
260 }260 }
@@ -282,7 +282,6 @@
282 u'phlipple',282 u'phlipple',
283 u'psi',283 u'psi',
284 u'midori'284 u'midori'
285
286 ]285 ]
287 }286 }
288 ]287 ]
289288
=== modified file 'softwarecenter/utils.py'
--- softwarecenter/utils.py 2012-03-16 17:22:59 +0000
+++ softwarecenter/utils.py 2012-03-19 14:27:20 +0000
@@ -253,7 +253,7 @@
253 # well ... it segfaults (thanks pygi)253 # well ... it segfaults (thanks pygi)
254 key = "org.gnome.system.proxy.http"254 key = "org.gnome.system.proxy.http"
255 if not key in Gio.Settings.list_schemas():255 if not key in Gio.Settings.list_schemas():
256 raise ValueError, "no key '%s'" % key256 raise ValueError("no key '%s'" % key)
257 settings = Gio.Settings.new(key)257 settings = Gio.Settings.new(key)
258 if settings.get_string("host"):258 if settings.get_string("host"):
259 authentication = ""259 authentication = ""
260260
=== modified file 'test/test_pep8.py'
--- test/test_pep8.py 2012-03-19 14:27:20 +0000
+++ test/test_pep8.py 2012-03-19 14:27:20 +0000
@@ -7,21 +7,12 @@
7setup_test_env()7setup_test_env()
88
9# Only test these two packages for now:9# Only test these two packages for now:
10import softwarecenter.backend10import softwarecenter
11import softwarecenter.db
12import softwarecenter.ui
13import softwarecenter.distro
1411
15class PackagePep8TestCase(unittest.TestCase):12class PackagePep8TestCase(unittest.TestCase):
16 maxDiff = None13 maxDiff = None
17 packages = [softwarecenter.ui,14 packages = [softwarecenter]
18 softwarecenter.backend,15 exclude = []
19 softwarecenter.db,
20 softwarecenter.distro,
21 ]
22 exclude = ['scagent.py', 'recagent.py', 'login_sso.py', 'login.py',
23 'launchpad.py', 'installbackend.py', 'fake_review_settings.py',
24 'channel.py']
2516
26 def message(self, text):17 def message(self, text):
27 self.errors.append(text)18 self.errors.append(text)