Merge lp:~barry/software-center/lp1526450 into lp:software-center

Proposed by Barry Warsaw
Status: Merged
Approved by: dobey
Approved revision: 3326
Merged at revision: 3334
Proposed branch: lp:~barry/software-center/lp1526450
Merge into: lp:software-center
Diff against target: 305 lines (+50/-31)
10 files modified
softwarecenter/backend/scagent.py (+3/-1)
softwarecenter/backend/spawn_helper.py (+4/-2)
softwarecenter/backend/ubuntusso.py (+9/-7)
softwarecenter/config.py (+5/-3)
softwarecenter/db/__init__.py (+3/-1)
softwarecenter/db/database.py (+1/-2)
softwarecenter/db/update.py (+6/-1)
softwarecenter/distro/__init__.py (+3/-1)
softwarecenter/distro/ubuntu.py (+6/-5)
softwarecenter/utils.py (+10/-8)
To merge this branch: bzr merge lp:~barry/software-center/lp1526450
Reviewer Review Type Date Requested Status
dobey Approve
Iain Lane (community) Approve
Sebastien Bacher Pending
Review via email: mp+280656@code.launchpad.net

Description of the change

Restores some bilingual Python 2/3 constructs so that plugins can run in the Python 3 ported apt-xapian-index and still run in Python 2.7 software-center.

To post a comment you must log in.
Revision history for this message
Iain Lane (laney) wrote :

Looks good to me, thanks

I see some extra changes on '2to3 update.py' that might be worth looking into.

review: Approve
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/backend/scagent.py'
2--- softwarecenter/backend/scagent.py 2012-12-14 16:44:25 +0000
3+++ softwarecenter/backend/scagent.py 2015-12-15 23:10:41 +0000
4@@ -19,11 +19,13 @@
5 # this program; if not, write to the Free Software Foundation, Inc.,
6 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
7
8+from __future__ import absolute_import
9+
10 from gi.repository import GObject
11 import logging
12
13 import softwarecenter.paths
14-from spawn_helper import SpawnHelper
15+from .spawn_helper import SpawnHelper
16 from softwarecenter.i18n import get_language
17 from softwarecenter.distro import get_distro, get_current_arch
18
19
20=== modified file 'softwarecenter/backend/spawn_helper.py'
21--- softwarecenter/backend/spawn_helper.py 2013-02-06 23:38:21 +0000
22+++ softwarecenter/backend/spawn_helper.py 2015-12-15 23:10:41 +0000
23@@ -109,7 +109,8 @@
24 stdout, GLib.PRIORITY_DEFAULT, GObject.IO_IN,
25 self._helper_io_ready, (stdout, ))
26
27- def _helper_finished(self, pid, status, (stdout, stderr)):
28+ def _helper_finished(self, pid, status, stdio_tuple):
29+ stdout, stderr = stdio_tuple
30 LOG.debug("helper_finished: '%s' '%s'" % (pid, status))
31 # get status code
32 res = os.WEXITSTATUS(status)
33@@ -131,7 +132,8 @@
34 if self._child_watch:
35 GLib.source_remove(self._child_watch)
36
37- def _helper_io_ready(self, source, condition, (stdout,)):
38+ def _helper_io_ready(self, source, condition, stdio_tuple):
39+ stdout, = stdio_tuple
40 # read the raw data
41 data = ""
42 while True:
43
44=== modified file 'softwarecenter/backend/ubuntusso.py'
45--- softwarecenter/backend/ubuntusso.py 2012-12-06 16:16:49 +0000
46+++ softwarecenter/backend/ubuntusso.py 2015-12-15 23:10:41 +0000
47@@ -20,6 +20,8 @@
48 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
49
50
51+from __future__ import absolute_import, print_function
52+
53 from gi.repository import GObject, GLib
54 from gettext import gettext as _
55
56@@ -33,8 +35,8 @@
57 import softwarecenter.paths
58
59 # mostly for testing
60-from fake_review_settings import FakeReviewSettings, network_delay
61-from spawn_helper import SpawnHelper
62+from .fake_review_settings import FakeReviewSettings, network_delay
63+from .spawn_helper import SpawnHelper
64 from softwarecenter.config import get_config
65 from softwarecenter.backend.login import get_login_backend
66
67@@ -215,11 +217,11 @@
68
69 # test code
70 def _login_success(lp, token):
71- print "success", lp, token
72+ print("success", lp, token)
73
74
75 def _login_failed(lp):
76- print "fail", lp
77+ print("fail", lp)
78
79
80 def _login_need_user_and_password(sso):
81@@ -236,15 +238,15 @@
82 # interactive test code
83 if __name__ == "__main__":
84 def _whoami(sso, result):
85- print "res: ", result
86+ print("res: ", result)
87 Gtk.main_quit()
88
89 def _error(sso, result):
90- print "err: ", result
91+ print("err: ", result)
92 Gtk.main_quit()
93
94 def _dbus_maybe_login_successful(ssologin, oauth_result):
95- print "got token, verify it now"
96+ print("got token, verify it now")
97 sso = UbuntuSSO()
98 sso.connect("whoami", _whoami)
99 sso.connect("error", _error)
100
101=== modified file 'softwarecenter/config.py'
102--- softwarecenter/config.py 2013-07-09 14:33:47 +0000
103+++ softwarecenter/config.py 2015-12-15 23:10:41 +0000
104@@ -16,6 +16,8 @@
105 # this program; if not, write to the Free Software Foundation, Inc.,
106 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
107
108+from __future__ import absolute_import
109+
110 # py3 compat
111 try:
112 from configparser import SafeConfigParser
113@@ -25,7 +27,7 @@
114 import os
115 import logging
116
117-from paths import SOFTWARE_CENTER_CONFIG_FILE
118+from .paths import SOFTWARE_CENTER_CONFIG_FILE
119
120 LOG = logging.getLogger(__name__)
121
122@@ -37,7 +39,7 @@
123 def __init__(self, config):
124 SafeConfigParser.__init__(self)
125 # imported here to avoid cycle
126- from utils import safe_makedirs
127+ from .utils import safe_makedirs
128 safe_makedirs(os.path.dirname(config))
129 # we always want this sections, even on fresh installs
130 for section in self.SECTIONS:
131@@ -57,7 +59,7 @@
132 tmpname = self.configfile + ".new"
133 # see LP: #996333, its ok to remove the old configfile as
134 # its rewritten anyway
135- from utils import ensure_file_writable_and_delete_if_not
136+ from .utils import ensure_file_writable_and_delete_if_not
137 ensure_file_writable_and_delete_if_not(tmpname)
138 ensure_file_writable_and_delete_if_not(self.configfile)
139 try:
140
141=== modified file 'softwarecenter/db/__init__.py'
142--- softwarecenter/db/__init__.py 2012-05-16 15:52:07 +0000
143+++ softwarecenter/db/__init__.py 2015-12-15 23:10:41 +0000
144@@ -1,7 +1,9 @@
145+from __future__ import absolute_import
146+
147 import logging
148
149 try:
150- from debfile import DebFileApplication, DebFileOpenError
151+ from .debfile import DebFileApplication, DebFileOpenError
152 DebFileApplication # pyflakes
153 DebFileOpenError # pyflakes
154 except:
155
156=== modified file 'softwarecenter/db/database.py'
157--- softwarecenter/db/database.py 2013-09-17 17:10:03 +0000
158+++ softwarecenter/db/database.py 2015-12-15 23:10:41 +0000
159@@ -20,7 +20,6 @@
160 import logging
161 import os
162 import re
163-import string
164 import threading
165 import xapian
166 from softwarecenter.db.application import Application
167@@ -62,7 +61,7 @@
168 if not os.path.exists(filename):
169 return axi_values
170 for raw_line in open(filename):
171- line = string.split(raw_line, "#", 1)[0]
172+ line = raw_line.split("#", 1)[0]
173 if line.strip() == "":
174 continue
175 (key, value) = line.split()
176
177=== modified file 'softwarecenter/db/update.py'
178--- softwarecenter/db/update.py 2015-01-11 23:33:51 +0000
179+++ softwarecenter/db/update.py 2015-12-15 23:10:41 +0000
180@@ -54,7 +54,12 @@
181
182
183 from glob import glob
184-from urlparse import urlparse
185+
186+# py3 compat
187+try:
188+ from urlparse import urlparse
189+except ImportError:
190+ from urllib.parse import urlparse
191
192 import softwarecenter.paths
193
194
195=== modified file 'softwarecenter/distro/__init__.py'
196--- softwarecenter/distro/__init__.py 2013-11-25 21:58:02 +0000
197+++ softwarecenter/distro/__init__.py 2015-12-15 23:10:41 +0000
198@@ -19,6 +19,7 @@
199
200 import logging
201 import os
202+import sys
203
204 from gettext import gettext as _
205 import platform
206@@ -171,7 +172,8 @@
207 distro_module_name = distro_id.lower()
208 distro_class_name = distro_id.capitalize()
209 # start with a import, this gives us only a softwarecenter module
210- module = __import__(distro_module_name, globals(), locals(), [], -1)
211+ level = (-1 if sys.version_info < (3,) else 1)
212+ module = __import__(distro_module_name, globals(), locals(), [], level)
213 # get the right class and instantiate it
214 distro_class = getattr(module, distro_class_name)
215 instance = distro_class()
216
217=== modified file 'softwarecenter/distro/ubuntu.py'
218--- softwarecenter/distro/ubuntu.py 2015-01-11 23:33:51 +0000
219+++ softwarecenter/distro/ubuntu.py 2015-12-15 23:10:41 +0000
220@@ -14,11 +14,12 @@
221 # this program; if not, write to the Free Software Foundation, Inc.,
222 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
223
224+from __future__ import print_function
225+
226 import datetime
227 import locale
228 import logging
229 import os
230-import re
231
232 from apt.utils import (get_release_filename_for_pkg,
233 get_release_date_from_release_file,
234@@ -270,7 +271,7 @@
235 if __name__ == "__main__":
236 import apt
237 cache = apt.Cache()
238- print cache.get_maintenance_status(cache, "synaptic app", "synaptic",
239- "main", None)
240- print cache.get_maintenance_status(cache, "3dchess app", "3dchess",
241- "universe", None)
242+ print(cache.get_maintenance_status(cache, "synaptic app", "synaptic",
243+ "main", None))
244+ print(cache.get_maintenance_status(cache, "3dchess app", "3dchess",
245+ "universe", None))
246
247=== modified file 'softwarecenter/utils.py'
248--- softwarecenter/utils.py 2013-09-06 13:22:03 +0000
249+++ softwarecenter/utils.py 2015-12-15 23:10:41 +0000
250@@ -16,6 +16,8 @@
251 # this program; if not, write to the Free Software Foundation, Inc.,
252 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
253
254+from __future__ import absolute_import, print_function
255+
256 import dbus
257 import gc
258 import gettext
259@@ -39,13 +41,13 @@
260 except ImportError:
261 from urlparse import urlsplit
262
263-from enums import Icons, APP_INSTALL_PATH_DELIMITER
264-from paths import (
265+from .enums import Icons, APP_INSTALL_PATH_DELIMITER
266+from .paths import (
267 SOFTWARE_CENTER_CACHE_DIR,
268 OEM_CHANNEL_DESCRIPTOR,
269 )
270
271-from config import get_config
272+from .config import get_config
273
274 from gettext import gettext as _
275
276@@ -115,11 +117,11 @@
277 if not type(obj) in new_obj_types:
278 new_obj_types[type(obj)] = 0
279 new_obj_types[type(obj)] += 1
280- print "+++ new types after '%s':" % self.info
281+ print("+++ new types after '%s':" % self.info)
282 #print new_obj_types
283 for v in sorted(new_obj_types, key=new_obj_types.get):
284- print v, new_obj_types[v]
285- print "/+++\n"
286+ print(v, new_obj_types[v])
287+ print("/+++\n")
288
289
290 class TraceMemoryUsage(object):
291@@ -135,12 +137,12 @@
292 def __exit__(self, atype, value, stack):
293 now_resident = self._get_mem_from_proc()["resident"] - self.resident
294 now_data = self._get_mem_from_proc()["data"] - self.data
295- print "++++ MEMORY DELTA for '%s': res: %s data: %s (%s %s)\n" % (
296+ print("++++ MEMORY DELTA for '%s': res: %s data: %s (%s %s)\n" % (
297 self.info,
298 # assume page size of 4k here
299 get_nice_size(now_resident * 4 * 1024),
300 get_nice_size(now_data * 4 * 1024),
301- now_resident, now_data)
302+ now_resident, now_data))
303
304 def _get_mem_from_proc(self):
305 with open("/proc/%i/statm" % os.getpid()) as f: