Merge lp:~danielalmaguer/wxbanker/Db_Fallback into lp:wxbanker

Proposed by Michael Rooney
Status: Needs review
Proposed branch: lp:~danielalmaguer/wxbanker/Db_Fallback
Merge into: lp:wxbanker
Diff against target: 76 lines (+43/-2)
1 file modified
wxbanker/persistentstore.py (+43/-2)
To merge this branch: bzr merge lp:~danielalmaguer/wxbanker/Db_Fallback
Reviewer Review Type Date Requested Status
wxBanker Developers Pending
Review via email: mp+142181@code.launchpad.net

Description of the change

Thanks! I'll just propose a merge so we have a way to discuss the changes. Overall it looks great, just two suggestions. 1) for the GetLatestBackup function, it would be cleaner to simply sort the results of os.listdir and use the first/last result, using a custom "key" lambda a string sort doesn't do the trick.
2) when it calls DatabaseUpgradeError, it would be helpful to explain that the latest backup has been replaced and to request filing a bug with a link. I guess this dialog will pop up on every run?

Thanks again for your time and contribution. Did you run into a database upgrade error that inspired this improvement? If so I'd love to know about it!

To post a comment you must log in.
877. By d4nii

Added RecoverDatabaseBackup dialog

878. By d4nii

Optimized GetLatestBackup()
Indentation error bugfix in RecoverDatabaseBackup()

Revision history for this message
d4nii (danielalmaguer) wrote :

Thanks for your feedback. The Dialog informing the user and requesting him to file a bug has been implemented in DatabaseUpgradeError().

About optimizing the GetLatestBackup function, it's now done by using the sorted function as you suggested, but we didn't found an easy and neat way to implement the key function with the lambda feature, so we had to implement the function the normal way.

Any more feedback would be appreciated.

"Did you run into a database upgrade error that inspired this improvement?"
   - Not really, I actually found wxBanker very useful and wanted to contribute, so I just jumped out to the buglist and saw this one.

Unmerged revisions

878. By d4nii

Optimized GetLatestBackup()
Indentation error bugfix in RecoverDatabaseBackup()

877. By d4nii

Added RecoverDatabaseBackup dialog

876. By d4nii

Added Database Error Handling code

875. By d4nii

Added Database Fallback functions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'wxbanker/persistentstore.py'
--- wxbanker/persistentstore.py 2012-08-11 03:28:39 +0000
+++ wxbanker/persistentstore.py 2013-01-10 23:47:22 +0000
@@ -36,6 +36,7 @@
36import datetime36import datetime
37import os37import os
38import sys38import sys
39import wx
3940
40from sqlite3 import dbapi2 as sqlite41from sqlite3 import dbapi2 as sqlite
41import sqlite342import sqlite3
@@ -120,6 +121,44 @@
120121
121 return self.cachedModel122 return self.cachedModel
122123
124 def RecoverDatabaseBackup(self):
125 import shutil
126 try:
127 shutil.copyfile(self.GetLatestBackup(), self.Path)
128 except IOError:
129 raise Exception("Unable to restore database.")
130 else:
131 print "Restored Succesfully"
132 msg = """There was an error with the current database version.
133 A previous working database has been restored.
134 Please report this error to wxBanker developers in order to improve this app.
135
136 Would you like to fill a bug report?"""
137
138 dlg = wx.MessageDialog(None, msg, "Database Error", style=wx.YES|wx.NO|wx.ICON_WARNING)
139 ans = dlg.ShowModal()
140 print ans
141 if ans & wx.YES:
142 import webbrowser
143 webbrowser.open('http://bugs.launchpad.net/wxbanker/+filebug')
144 dlg.Destroy()
145
146 def GetLatestBackup(self):
147 def get_version(f):
148 try:
149 v = int (f[f.find("v")+1:f.find("-",f.find("v"))])
150 except:
151 v = 0
152 return v
153 f = sorted(os.listdir(os.path.dirname(self.Path)), key=get_version, reverse=True) [0]
154 return os.path.join(os.path.dirname(self.Path), f)
155
156 def DatabaseUpgradeError(self, errorMsg):
157 self.RecoverDatabaseBackup()
158 dlg = wx.MessageDialog(None, errorMsg, _("Database upgrade Error"), style=wx.OK|wx.ICON_WARNING)
159 dlg.ShowModal()
160 dlg.Destroy()
161
123 def CreateAccount(self, accountName, currency=0):162 def CreateAccount(self, accountName, currency=0):
124 if isinstance(currency, currencies.BaseCurrency):163 if isinstance(currency, currencies.BaseCurrency):
125 currency = currencies.GetCurrencyInt(currency)164 currency = currencies.GetCurrencyInt(currency)
@@ -275,7 +314,7 @@
275 try:314 try:
276 cursor.execute('ALTER TABLE transactions ADD recurringParent INTEGER')315 cursor.execute('ALTER TABLE transactions ADD recurringParent INTEGER')
277 except sqlite3.OperationalError:316 except sqlite3.OperationalError:
278 debug.debug("Detected a broken database from the 0.4 -> 0.6 upgrade, handling appropriately.")317 debug.debug("Detected a broken database from the 0.4 -> 0.6 upgrade, handling appropriately.")
279 elif fromVer == 7:318 elif fromVer == 7:
280 # Force a re-sync for the 0.6.1 release after fixing LP: #496341319 # Force a re-sync for the 0.6.1 release after fixing LP: #496341
281 self.needsSync = True320 self.needsSync = True
@@ -300,7 +339,9 @@
300 # globalCurrency entry339 # globalCurrency entry
301 cursor.execute('INSERT INTO meta VALUES (null, ?, ?)', ('GlobalCurrency', 0))340 cursor.execute('INSERT INTO meta VALUES (null, ?, ?)', ('GlobalCurrency', 0))
302 else:341 else:
303 raise Exception("Cannot upgrade database from version %i"%fromVer)342 # raise Exception("Cannot upgrade database from version %i"%fromVer)
343 # Fallback to latest database backup
344 self.DatabaseUpgradeError("Cannot upgrade database from version %i"%fromVer)
304 345
305 """346 """
306 # Tagging infrastructure (currently unused due to speed of parsing on startup).347 # Tagging infrastructure (currently unused due to speed of parsing on startup).

Subscribers

People subscribed via source and target branches

to all changes: