Merge lp:~aaronp/software-center/usc-605048 into lp:software-center

Proposed by Aaron Peachey
Status: Merged
Merged at revision: 1389
Proposed branch: lp:~aaronp/software-center/usc-605048
Merge into: lp:software-center
Diff against target: 107 lines (+34/-16)
2 files modified
softwarecenter/app.py (+2/-14)
softwarecenter/db/update.py (+32/-2)
To merge this branch: bzr merge lp:~aaronp/software-center/usc-605048
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+44436@code.launchpad.net

This proposal supersedes a proposal from 2010-12-19.

Description of the change

100 papercut fixes for bug 605048 and 686994.
Alters db update behaviour to stop 'rebuilding' window appearing while xapian db is being updated on detecting an externally changed cahce.
Instead, updates a new copy of the xapian db, then once finished, renamed to be the new xapian db.
Changes made in app.py and db/update.py.
Test by running "sudo update-software-center"

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote : Posted in a previous version of this proposal
Download full text (3.8 KiB)

On Sun, Dec 19, 2010 at 06:14:13AM -0000, Aaron Peachey wrote:
> Aaron Peachey has proposed merging lp:~aaronp/software-center/usc-605048 into lp:software-center.
>
> Requested reviews:
> Michael Vogt (mvo)
> Related bugs:
> #605048 "Rebuilding application catalogue" uses a separate window
> https://bugs.launchpad.net/bugs/605048
> #686994 When 'Rebuilding Software Catalogue', there is no indication that anything is happening or when it will end.
> https://bugs.launchpad.net/bugs/686994
>
>
> 100 papercut fixes for bug 605048 and 686994.
> Alters db update behaviour to stop 'rebuilding' window appearing while xapian db is being updated on detecting an externally changed cahce.
> Instead, updates a new copy of the xapian db, then once finished, renamed to be the new xapian db.
> Changes made in app.py and db/update.py.
> Test by running "sudo update-software-center"

Thanks, the branch looks fine. I will merge it, but I need to ask
first that you please sign the canonical contributors agreement, the
details are here:
http://www.canonical.com/contributors
its quick and painless.

Some small comments below:

> === modified file 'softwarecenter/app.py'
> --- softwarecenter/app.py 2010-12-14 18:57:11 +0000
> +++ softwarecenter/app.py 2010-12-19 06:13:57 +0000
> @@ -851,25 +852,12 @@
[..]
> - if is_rebuilding:
> - self.window_rebuilding.show()
[..]

Nice that we can get rid of this :)

> === modified file 'softwarecenter/db/update.py'
> --- softwarecenter/db/update.py 2010-12-15 14:02:40 +0000
> +++ softwarecenter/db/update.py 2010-12-19 06:13:57 +0000
> @@ -592,15 +594,39 @@
>
> def rebuild_database(pathname):
> cache = apt.Cache(memonly=True)
> + old_path = os.path.join(XAPIAN_BASE_PATH, "xapian_old")
> + rebuild_path = os.path.join(XAPIAN_BASE_PATH, "xapian_rb")

Its probably better to build this relative to pathname, e.g. by
just adding "_old" and "_rb" to the base pathname

> + if not os.path.exists(rebuild_path):
> + try:
> + os.makedirs(rebuild_path)
> + except:
> + LOG.warn("Problem creating rebuild path '%s'." % rebuild_path)
> + LOG.warn("Please check you have the relevant permissions.")
> + return False
> +
> # check permission
> if not os.access(pathname, os.W_OK):
> LOG.warn("Cannot write to '%s'." % pathname)
> LOG.warn("Please check you have the relevant permissions.")
> return False
> +
> + #check if old unrequired version of db still exists on filesystem
> + if os.path.exists(old_path):
> + LOG.warn("Existing xapian old db was not previously cleaned: '%s'." % old_path)
> + if os.access(old_path, os.W_OK):
> + #remove old unrequired db before beginning
> + shutil.rmtree(old_path, False, None)
> + else:
> + LOG.warn("Cannot write to '%s'." % old_path)
> + LOG.warn("Please check you have the relevant permissions.")
> + return False
> +
> +

Nice defensive style!

> # write it
> - db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OVERWRITE)
> + db = xapian.WritableDatabase(...

Read more...

Revision history for this message
Michael Vogt (mvo) wrote : Posted in a previous version of this proposal

On Sun, Dec 19, 2010 at 06:14:13AM -0000, Aaron Peachey wrote:
Another tiny note:

> + shutil.rmtree(old_path, False, None)

The False and None are default values in the shutil.rmtree, so you can
just write the slightly shorter shutil.rmtree(old_path).

Cheers,
 Michael

Revision history for this message
Aaron Peachey (aaronp) wrote :

updated as per review feedback and new changes pushed to branch ready for re-review/merging

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks a lot! Merged into trunk :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'softwarecenter/app.py'
2--- softwarecenter/app.py 2010-12-15 19:23:03 +0000
3+++ softwarecenter/app.py 2010-12-22 09:39:57 +0000
4@@ -134,6 +134,7 @@
5 self.backend.connect("channels-changed", self.on_channels_changed)
6 # xapian
7 pathname = os.path.join(xapian_base_path, "xapian")
8+
9 try:
10 self.db = StoreDatabase(pathname, self.cache)
11 self.db.open()
12@@ -851,25 +852,12 @@
13 def _on_database_rebuilding_handler(self, is_rebuilding):
14 self._logger.debug("_on_database_rebuilding_handler %s" % is_rebuilding)
15 self._database_is_rebuilding = is_rebuilding
16- self.window_rebuilding.set_transient_for(self.window_main)
17
18- # set a11y text
19- try:
20- text = self.window_rebuilding.get_children()[0]
21- text.set_property("can-focus", True)
22- text.a11y = text.get_accessible()
23- text.a11y.set_name(text.get_children()[0].get_text())
24- except IndexError:
25+ if is_rebuilding:
26 pass
27-
28- self.window_main.set_sensitive(not is_rebuilding)
29- # show dialog about the rebuilding status
30- if is_rebuilding:
31- self.window_rebuilding.show()
32 else:
33 # we need to reopen when the database finished updating
34 self.db.reopen()
35- self.window_rebuilding.hide()
36
37 def setup_database_rebuilding_listener(self):
38 """
39
40=== modified file 'softwarecenter/db/update.py'
41--- softwarecenter/db/update.py 2010-12-15 14:02:40 +0000
42+++ softwarecenter/db/update.py 2010-12-22 09:39:57 +0000
43@@ -25,11 +25,13 @@
44 import os
45 import simplejson
46 import string
47+import shutil
48 import sys
49 import time
50 import urllib
51 import xapian
52
53+
54 from ConfigParser import RawConfigParser, NoOptionError
55 from gettext import gettext as _
56 from glob import glob
57@@ -592,15 +594,39 @@
58
59 def rebuild_database(pathname):
60 cache = apt.Cache(memonly=True)
61+ old_path = pathname+"_old"
62+ rebuild_path = pathname+"_rb"
63+
64+ if not os.path.exists(rebuild_path):
65+ try:
66+ os.makedirs(rebuild_path)
67+ except:
68+ LOG.warn("Problem creating rebuild path '%s'." % rebuild_path)
69+ LOG.warn("Please check you have the relevant permissions.")
70+ return False
71+
72 # check permission
73 if not os.access(pathname, os.W_OK):
74 LOG.warn("Cannot write to '%s'." % pathname)
75 LOG.warn("Please check you have the relevant permissions.")
76 return False
77+
78+ #check if old unrequired version of db still exists on filesystem
79+ if os.path.exists(old_path):
80+ LOG.warn("Existing xapian old db was not previously cleaned: '%s'." % old_path)
81+ if os.access(old_path, os.W_OK):
82+ #remove old unrequired db before beginning
83+ shutil.rmtree(old_path)
84+ else:
85+ LOG.warn("Cannot write to '%s'." % old_path)
86+ LOG.warn("Please check you have the relevant permissions.")
87+ return False
88+
89+
90 # write it
91- db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OVERWRITE)
92+ db = xapian.WritableDatabase(rebuild_path, xapian.DB_CREATE_OR_OVERWRITE)
93 update(db, cache)
94- # write the database version into the file
95+ # write the database version into the filep
96 db.set_metadata("db-schema-version", DB_SCHEMA_VERSION)
97 # update the mo file stamp for the langpack checks
98 mofile = gettext.find("app-install-data")
99@@ -608,5 +634,9 @@
100 mo_time = os.path.getctime(mofile)
101 db.set_metadata("app-install-mo-time", str(mo_time))
102 db.flush()
103+
104+ os.rename(pathname, old_path)
105+ os.rename(rebuild_path, pathname)
106+ shutil.rmtree(old_path)
107 return True
108

Subscribers

People subscribed via source and target branches