Merge lp:~ken-vandine/gwibber/lp_740494 into lp:gwibber
- lp_740494
- Merge into trunk
Proposed by
Ken VanDine
Status: | Merged |
---|---|
Merged at revision: | 1306 |
Proposed branch: | lp:~ken-vandine/gwibber/lp_740494 |
Merge into: | lp:gwibber |
Diff against target: |
397 lines (+104/-64) 11 files modified
bin/gwibber-accounts (+24/-15) gwibber/accounts.py (+16/-12) gwibber/microblog/dispatcher.py (+1/-1) gwibber/microblog/plugins/facebook/gtk/facebook/__init__.py (+1/-0) gwibber/microblog/plugins/identica/gtk/identica/__init__.py (+5/-2) gwibber/microblog/plugins/statusnet/gtk/statusnet/__init__.py (+5/-2) gwibber/microblog/plugins/twitter/gtk/twitter/__init__.py (+1/-0) gwibber/microblog/storage.py (+8/-2) gwibber/microblog/util/couchmigrate.py (+31/-19) gwibber/microblog/util/keyring.py (+11/-11) po/POTFILES.in (+1/-0) |
To merge this branch: | bzr merge lp:~ken-vandine/gwibber/lp_740494 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Klasinc (community) | Approve | ||
Review via email: mp+96471@code.launchpad.net |
Commit message
Description of the change
Fixes account migration from 2.32 to 3.3.x
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 'bin/gwibber-accounts' |
2 | --- bin/gwibber-accounts 2012-02-13 20:39:02 +0000 |
3 | +++ bin/gwibber-accounts 2012-03-07 22:10:25 +0000 |
4 | @@ -32,22 +32,8 @@ |
5 | |
6 | |
7 | ###################################################################### |
8 | -# Don't run again if we are already running |
9 | -progname = "gwibber-accounts" |
10 | -screen = Wnck.Screen.get_default() |
11 | -while Gtk.events_pending(): |
12 | - Gtk.main_iteration() |
13 | -for w in screen.get_windows(): |
14 | - if w.get_application().get_name() == progname: |
15 | - import time |
16 | - w.move_to_workspace(screen.get_active_workspace()) |
17 | - w.activate(int(time.time())) |
18 | - print int(time.time()) |
19 | - quit() |
20 | - |
21 | -###################################################################### |
22 | # Options |
23 | -from optparse import OptionParser |
24 | +from optparse import OptionParser, SUPPRESS_HELP |
25 | parser = OptionParser() |
26 | parser.add_option("-d", "--debug", action="store_true", |
27 | dest="debug", default=False, |
28 | @@ -61,6 +47,9 @@ |
29 | parser.add_option("-m", "--message", action="store", |
30 | dest="message", default=None, |
31 | help=_("Message to display explaining the condition")) |
32 | +parser.add_option("--migrate-couch", action="store_true", |
33 | + dest="migrate_couch", default=False, |
34 | + help=SUPPRESS_HELP) |
35 | |
36 | (options, args) = parser.parse_args() |
37 | |
38 | @@ -109,6 +98,26 @@ |
39 | logger.info("Running from the system path") |
40 | from gwibber import accounts |
41 | |
42 | +if options.migrate_couch: |
43 | + print "migrate_couch" |
44 | + from gwibber.microblog.util import couchmigrate |
45 | + couchmigrate.AccountCouchMigrate() |
46 | + quit() |
47 | + |
48 | +###################################################################### |
49 | +# Don't run again if we are already running |
50 | +progname = "gwibber-accounts" |
51 | +screen = Wnck.Screen.get_default() |
52 | +while Gtk.events_pending(): |
53 | + Gtk.main_iteration() |
54 | +for w in screen.get_windows(): |
55 | + if w.get_application().get_name() == progname: |
56 | + import time |
57 | + w.move_to_workspace(screen.get_active_workspace()) |
58 | + w.activate(int(time.time())) |
59 | + print int(time.time()) |
60 | + quit() |
61 | + |
62 | ###################################################################### |
63 | |
64 | |
65 | |
66 | === modified file 'gwibber/accounts.py' |
67 | --- gwibber/accounts.py 2012-02-16 06:00:43 +0000 |
68 | +++ gwibber/accounts.py 2012-03-07 22:10:25 +0000 |
69 | @@ -51,7 +51,9 @@ |
70 | if os.path.exists(os.path.join("data", "icons")): |
71 | self.icon_theme.prepend_search_path (os.path.realpath(os.path.join("data", "icons"))) |
72 | |
73 | - self.selected_account = selected_account |
74 | + self.selected_account = [] |
75 | + if selected_account: |
76 | + self.selected_account = selected_account.split(",") |
77 | self.condition = condition |
78 | self.message = message |
79 | self.gwibber = GwibberPublic() |
80 | @@ -128,17 +130,16 @@ |
81 | |
82 | def select_account(self): |
83 | column = self.account_tree.get_column(0) |
84 | - if not self.selected_account: |
85 | + if len(self.selected_account) < 1: |
86 | if len(self.account_store): |
87 | self.account_tree.set_cursor(Gtk.TreePath.new_from_string('0'), |
88 | column, False) |
89 | else: self.add_account() |
90 | else: |
91 | for i in self.account_store: |
92 | - if i[2]["id"] == self.selected_account: |
93 | - self.account_tree.set_cursor(i.path, column, False) |
94 | - self.selected_account = None |
95 | - |
96 | + if len(self.selected_account) > 0: |
97 | + if i[2]["id"] == self.selected_account[0]: |
98 | + self.account_tree.set_cursor(i.path, column, False) |
99 | |
100 | def get_icon(self, name): |
101 | try: |
102 | @@ -165,11 +166,14 @@ |
103 | private_fields = [f.split(":")[-1] for f in self.services[account["service"]]["config"] if ":" in f] |
104 | color = None |
105 | for f in private_fields: |
106 | - if not account.has_key(f): account[f] = ":KEYRING:MISSING" |
107 | + if not account.has_key(f) or account[f] is None: account[f] = ":KEYRING:MISSING" |
108 | if account[f].startswith(":KEYRING:"): |
109 | value = keyring.get_from_keyring(account["id"], f) |
110 | - if value is None: |
111 | + if value is None or account[f] == ":KEYRING:MISSING": |
112 | color = "pink" |
113 | + if account["id"] not in self.selected_account: |
114 | + self.selected_account.append (account["id"]) |
115 | + self.condition = "error" |
116 | self.account_store.append(None, [name, icon, account, color]) |
117 | except: |
118 | pass |
119 | @@ -251,10 +255,10 @@ |
120 | self.ui.get_object('vbox_create').hide() |
121 | |
122 | # if we just fixed a failure case, hide the infobar |
123 | - if self.account["id"] == self.selected_account: |
124 | - if hasattr(Gtk, "InfoBar"): |
125 | + if self.account["id"] in self.selected_account: |
126 | + if hasattr(Gtk, "InfoBar") and len(self.selected_account) <= 1: |
127 | self.infobar.hide() |
128 | - self.selected_account = None |
129 | + self.selected_account.remove (self.account["id"]) |
130 | |
131 | self.populate_account_tree() |
132 | |
133 | @@ -380,7 +384,7 @@ |
134 | iter = model.get_iter(rows[0]) |
135 | icon = model.get_value(iter, 1) |
136 | acct = model.get_value(iter, 2) |
137 | - if self.selected_account == acct["id"] and self.condition: |
138 | + if acct["id"] in self.selected_account and self.condition: |
139 | self.account_show(acct["service"], icon, acct, self.condition, self.message) |
140 | else: |
141 | self.account_show(acct["service"], icon, acct) |
142 | |
143 | === modified file 'gwibber/microblog/dispatcher.py' |
144 | --- gwibber/microblog/dispatcher.py 2012-02-23 08:59:27 +0000 |
145 | +++ gwibber/microblog/dispatcher.py 2012-03-07 22:10:25 +0000 |
146 | @@ -414,7 +414,7 @@ |
147 | GLib.source_remove(self.refresh_timer_id) |
148 | |
149 | def on_account_updated(self, account): |
150 | - pass |
151 | + self.refresh() |
152 | |
153 | def on_account_created(self, account): |
154 | self.refresh() |
155 | |
156 | === modified file 'gwibber/microblog/plugins/facebook/gtk/facebook/__init__.py' |
157 | --- gwibber/microblog/plugins/facebook/gtk/facebook/__init__.py 2012-02-14 18:02:27 +0000 |
158 | +++ gwibber/microblog/plugins/facebook/gtk/facebook/__init__.py 2012-03-07 22:10:25 +0000 |
159 | @@ -114,6 +114,7 @@ |
160 | |
161 | self.pack_start(self.scroll, True, True, 0) |
162 | self.show_all() |
163 | + self.dialog.infobar.hide() |
164 | self.ui.get_object("vbox1").hide() |
165 | self.ui.get_object("vbox_advanced").hide() |
166 | |
167 | |
168 | === modified file 'gwibber/microblog/plugins/identica/gtk/identica/__init__.py' |
169 | --- gwibber/microblog/plugins/identica/gtk/identica/__init__.py 2012-02-14 18:02:27 +0000 |
170 | +++ gwibber/microblog/plugins/identica/gtk/identica/__init__.py 2012-03-07 22:10:25 +0000 |
171 | @@ -35,12 +35,14 @@ |
172 | self.window = dialog.dialog |
173 | self.url_prefix = "https://identi.ca" |
174 | has_secret_key = False |
175 | - if self.account.has_key("id"): |
176 | + if self.account.has_key("id") and self.account.has_key("access_token") \ |
177 | + and self.account.has_key("secret_token") and self.account.has_key("username"): |
178 | + if self.account["secret_token"] and self.account["access_token"]: |
179 | has_secret_key = get_from_keyring(self.account['id'], |
180 | 'secret_token') is not None |
181 | |
182 | try: |
183 | - if self.account.has_key("access_token") and self.account.has_key("secret_token") and self.account.has_key("username") and has_secret_key: |
184 | + if has_secret_key: |
185 | self.ui.get_object("hbox_statusnet_auth").hide() |
186 | self.ui.get_object("statusnet_auth_done_label").set_label(_("%s has been authorized by %s") % (self.account["username"])) |
187 | self.ui.get_object("hbox_statusnet_auth_done").show() |
188 | @@ -88,6 +90,7 @@ |
189 | |
190 | self.pack_start(self.scroll, True, True, 0) |
191 | self.show_all() |
192 | + self.dialog.infobar.hide() |
193 | |
194 | self.ui.get_object("vbox1").hide() |
195 | self.ui.get_object("vbox_advanced").hide() |
196 | |
197 | === modified file 'gwibber/microblog/plugins/statusnet/gtk/statusnet/__init__.py' |
198 | --- gwibber/microblog/plugins/statusnet/gtk/statusnet/__init__.py 2012-02-14 18:02:27 +0000 |
199 | +++ gwibber/microblog/plugins/statusnet/gtk/statusnet/__init__.py 2012-03-07 22:10:25 +0000 |
200 | @@ -37,12 +37,14 @@ |
201 | self.dialog = dialog |
202 | self.window = dialog.dialog |
203 | has_secret_key = False |
204 | - if self.account.has_key("id"): |
205 | + if self.account.has_key("id") and self.account.has_key("access_token") \ |
206 | + and self.account.has_key("secret_token") and self.account.has_key("username"): |
207 | + if self.account["secret_token"] and self.account["access_token"]: |
208 | has_secret_key = get_from_keyring(self.account['id'], |
209 | 'secret_token') is not None |
210 | |
211 | try: |
212 | - if self.account.has_key("access_token") and self.account.has_key("secret_token") and self.account.has_key("username") and has_secret_key: |
213 | + if has_secret_key: |
214 | self.ui.get_object("hbox_statusnet_auth").hide() |
215 | self.ui.get_object("statusnet_auth_done_label").set_label(_("%s has been authorized by %s") % (self.account["username"], self.account["site_display_name"])) |
216 | self.ui.get_object("hbox_statusnet_auth_done").show() |
217 | @@ -101,6 +103,7 @@ |
218 | |
219 | self.pack_start(self.scroll, True, True, 0) |
220 | self.show_all() |
221 | + self.dialog.infobar.hide() |
222 | |
223 | self.ui.get_object("table_common_settings").hide() |
224 | self.ui.get_object("vbox1").hide() |
225 | |
226 | === modified file 'gwibber/microblog/plugins/twitter/gtk/twitter/__init__.py' |
227 | --- gwibber/microblog/plugins/twitter/gtk/twitter/__init__.py 2012-02-14 18:02:27 +0000 |
228 | +++ gwibber/microblog/plugins/twitter/gtk/twitter/__init__.py 2012-03-07 22:10:25 +0000 |
229 | @@ -86,6 +86,7 @@ |
230 | |
231 | self.pack_start(self.scroll, True, True, 0) |
232 | self.show_all() |
233 | + self.dialog.infobar.hide() |
234 | |
235 | self.ui.get_object("vbox1").hide() |
236 | self.ui.get_object("vbox_advanced").hide() |
237 | |
238 | === modified file 'gwibber/microblog/storage.py' |
239 | --- gwibber/microblog/storage.py 2012-02-13 20:39:02 +0000 |
240 | +++ gwibber/microblog/storage.py 2012-03-07 22:10:25 +0000 |
241 | @@ -259,8 +259,14 @@ |
242 | |
243 | if not self.db.execute("PRAGMA table_info(accounts)").fetchall(): |
244 | self.setup_table() |
245 | - from util import couchmigrate |
246 | - couchmigrate.AccountCouchMigrate() |
247 | + import subprocess, os |
248 | + cmd = [] |
249 | + cmd.append ("--migrate-couch") |
250 | + if os.path.exists (os.path.join ("bin", "gwibber-accounts")): |
251 | + cmd.insert (0, os.path.join ("bin", "gwibber-accounts")) |
252 | + else: |
253 | + cmd.insert (0, "gwibber-accounts") |
254 | + process = subprocess.Popen (cmd) |
255 | |
256 | self.passwords = {} |
257 | try: |
258 | |
259 | === modified file 'gwibber/microblog/util/couchmigrate.py' |
260 | --- gwibber/microblog/util/couchmigrate.py 2012-02-10 10:06:59 +0000 |
261 | +++ gwibber/microblog/util/couchmigrate.py 2012-03-07 22:10:25 +0000 |
262 | @@ -6,9 +6,12 @@ |
263 | except: |
264 | CouchDatabase = None |
265 | |
266 | -from const import SQLITE_DB_FILENAME |
267 | +import string, subprocess, os |
268 | import sqlite3, uuid, json |
269 | +from gwibber.lib import GwibberPublic |
270 | + |
271 | import resources |
272 | +from gettext import lgettext as _ |
273 | |
274 | import logging |
275 | logger = logging.getLogger("Couch Migrate") |
276 | @@ -26,8 +29,8 @@ |
277 | class AccountCouchMigrate: |
278 | def __init__(self): |
279 | if CouchDatabase: |
280 | - self.db = sqlite3.connect(SQLITE_DB_FILENAME) |
281 | - sqlite_accounts = json.loads(self.List()) |
282 | + self.gwibber = GwibberPublic() |
283 | + sqlite_accounts = json.loads(self.gwibber.GetAccounts()) |
284 | |
285 | try: |
286 | accounts = CouchDatabase(COUCH_DB_ACCOUNTS, create=False) |
287 | @@ -37,6 +40,7 @@ |
288 | return |
289 | |
290 | migrate = {} |
291 | + needs_auth = [] |
292 | |
293 | logger.info("Looking for accounts to migrate from desktopcouch to sqlite") |
294 | |
295 | @@ -48,28 +52,36 @@ |
296 | for sqlite_account in sqlite_accounts: |
297 | if record["value"]["protocol"] == sqlite_account["service"] and record["value"]["username"] == sqlite_account["username"]: |
298 | migrate[id] = False |
299 | + if not SERVICES.has_key(record["value"]["protocol"]): |
300 | + migrate[id] = False |
301 | if migrate[id]: |
302 | new_account = {} |
303 | new_account["service"] = record["value"]["protocol"] |
304 | new_account["id"] = record["value"]["_id"] |
305 | for param in SERVICES[record["value"]["protocol"]]["config"]: |
306 | key = param.replace('private:','') |
307 | - new_account[key] = record["value"][key] |
308 | + new_account[key] = record["value"].get(key, None) |
309 | + if key == "access_token" and record["value"].has_key("secret_key"): |
310 | + new_account[key] = record["value"]["secret_key"] |
311 | + if (key == "secret_token" or key == "access_token") and new_account[key] is None and new_account["id"] not in needs_auth: |
312 | + needs_auth.append (new_account["id"]) |
313 | + if key == "uid" and new_account[key] is None and new_account["id"] not in needs_auth: |
314 | + needs_auth.append (new_account["id"]) |
315 | logger.info("Found account %s - %s that needs to be migrated", new_account["service"], new_account["username"]) |
316 | - self.Create(json.dumps(new_account)) |
317 | - |
318 | - def Create(self, account): |
319 | - data = json.loads(account) |
320 | - if "id" not in data: |
321 | - data["id"] = uuid.uuid1().hex |
322 | - encoded = json.dumps(data) |
323 | - query = "INSERT INTO accounts VALUES (?, ?, ?, ?, ?, ?, ?)" |
324 | - self.db.execute(query, (data["id"], data["service"], data["username"], data["color"], |
325 | - data.get("send_enabled", None), data.get("receive_enabled", None), encoded)) |
326 | - self.db.commit() |
327 | - |
328 | - def List(self): |
329 | - results = self.db.execute("SELECT data FROM accounts") |
330 | - return "[%s]" % ", ".join([i[0] for i in results.fetchall()]) |
331 | + self.gwibber.accounts.Create(json.dumps(new_account)) |
332 | + logger.debug("ACCOUNTS NEED RE-AUTH: %s", needs_auth) |
333 | + if len(needs_auth) > 0: |
334 | + cmd = [] |
335 | + cmd.append ("-a") |
336 | + cmd.append (string.join (needs_auth, ",")) |
337 | + cmd.append ("-c") |
338 | + cmd.append ("info") |
339 | + cmd.append ("-m") |
340 | + cmd.append (_("Authorize")) |
341 | + if os.path.exists (os.path.join ("bin", "gwibber-accounts")): |
342 | + cmd.insert (0, os.path.join ("bin", "gwibber-accounts")) |
343 | + else: |
344 | + cmd.insert (0, "gwibber-accounts") |
345 | + process = subprocess.Popen (cmd) |
346 | |
347 | AccountCouchMigrate() |
348 | |
349 | === modified file 'gwibber/microblog/util/keyring.py' |
350 | --- gwibber/microblog/util/keyring.py 2012-02-13 20:39:02 +0000 |
351 | +++ gwibber/microblog/util/keyring.py 2012-03-07 22:10:25 +0000 |
352 | @@ -47,22 +47,22 @@ |
353 | result, found = GnomeKeyring.find_items_sync( |
354 | GnomeKeyring.ItemType.GENERIC_SECRET, |
355 | attrlist) |
356 | - value = found[0].secret |
357 | - mlock(value) |
358 | - |
359 | - if result == GnomeKeyring.Result.NO_MATCH: |
360 | - print id |
361 | - raise exceptions.GwibberServiceError("keyring") |
362 | - |
363 | - return value |
364 | + if result == GnomeKeyring.Result.OK: |
365 | + value = found[0].secret |
366 | + mlock(value) |
367 | + return value |
368 | + elif result == GnomeKeyring.Result.NO_MATCH: |
369 | + print "FAILED: " + id |
370 | + return None |
371 | |
372 | |
373 | libc = ctypes.CDLL("libc.so.6") |
374 | |
375 | |
376 | def mlock(var): |
377 | - libc.mlock(var, len(var)) |
378 | - |
379 | + if var: |
380 | + libc.mlock(var, len(var)) |
381 | |
382 | def munlock(var): |
383 | - libc.munlock(var, len(var)) |
384 | + if var: |
385 | + libc.munlock(var, len(var)) |
386 | |
387 | === modified file 'po/POTFILES.in' |
388 | --- po/POTFILES.in 2012-02-16 18:59:31 +0000 |
389 | +++ po/POTFILES.in 2012-03-07 22:10:25 +0000 |
390 | @@ -32,6 +32,7 @@ |
391 | gwibber/lib/gtk/widgets.py |
392 | gwibber/microblog/dispatcher.py |
393 | gwibber/microblog/util/exceptions.py |
394 | +gwibber/microblog/util/couchmigrate.py |
395 | gwibber/microblog/plugins/flickr/__init__.py |
396 | gwibber/microblog/plugins/flickr/gtk/flickr/__init__.py |
397 | gwibber/microblog/plugins/friendfeed/gtk/friendfeed/__init__.py |
Everything looks ok.