GTG

Merge lp:~narendraj9/gtg/bug_971651_fixed into lp:~gtg/gtg/old-trunk

Proposed by Narendra Joshi
Status: Merged
Merge reported by: Izidor Matušov
Merged at revision: not available
Proposed branch: lp:~narendraj9/gtg/bug_971651_fixed
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: 250 lines (+105/-23)
6 files modified
AUTHORS (+2/-1)
CHANGELOG (+1/-0)
GTG/backends/backend_localfile.py (+35/-1)
GTG/gtk/browser/custominfobar.py (+5/-1)
GTG/gtk/manager.py (+6/-0)
GTG/tools/cleanxml.py (+56/-20)
To merge this branch: bzr merge lp:~narendraj9/gtg/bug_971651_fixed
Reviewer Review Type Date Requested Status
Izidor Matušov Approve
Nimit Shah Pending
Review via email: mp+210222@code.launchpad.net

Description of the change

Fixes bug #971651: https://bugs.launchpad.net/gtg/+bug/971651

Used a module wide variable in cleanxml.py to store information about backups being used everytime a call to openxml is made. Added a function to get the state of backup usage: cleanxml.used_backup()

Modified GTG/backends/backend_localfile.py to store information about whether backup files were used while instantiating a Backend object. Added a function used_backup() to get status about backup recovery.

Added a call to BackendSignals().interaction_requested(..) in GTG/gtk/manager.py inside the open_browser function, called whenever backup files are used to recover gtg_tasks.xml. I had to modify the function GTG.gtk.browser.custominfobar._prepare_textual_iteraction to add a case for backup recovery notification. There must be a more elegant way to do this, I guess.

To post a comment you must log in.
lp:~narendraj9/gtg/bug_971651_fixed updated
1364. By Narendra Joshi

backup files are now used even when gtg_tasks.xml is missing.
Earlier they were used only when gtg_tasks.xml was malformed.

1365. By Narendra Joshi

Modified CHANGELOG and added myself to AUTHORS

1366. By Narendra Joshi

Fixed some PEP8 erros and warnings

1367. By Narendra Joshi

Fixed a typo

1368. By Narendra Joshi

Added date of creation of the backup used in recovery to the info being displayed.

1369. By Narendra Joshi

Backup infobar fixed on first_run

1370. By Narendra Joshi

Removed a PEP8 error. Fixed a typo.

Revision history for this message
Izidor Matušov (izidor) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AUTHORS'
2--- AUTHORS 2014-03-05 19:25:18 +0000
3+++ AUTHORS 2014-03-13 18:43:02 +0000
4@@ -133,4 +133,5 @@
5 * Sushant Raikar <sushantthecoder@gmail.com>
6 * Atit Anand <atit.anand.cs@gmail.com>
7 * Parth P. Panchal <parthpanchl@gmail.com>
8-* Sara Ribeiro <sara.rmgr@gmail.com>
9\ No newline at end of file
10+* Sara Ribeiro <sara.rmgr@gmail.com>
11+* Narendra Joshi <narendraj9@gmail.com>
12
13=== modified file 'CHANGELOG'
14--- CHANGELOG 2014-03-10 03:37:32 +0000
15+++ CHANGELOG 2014-03-13 18:43:02 +0000
16@@ -21,6 +21,7 @@
17 * Fix for bug #316922 : Have a link to the parent(s) in the task editor, by Parth Panchal
18 * Fix for bug #1287259 : pep8ify the codebase, by Izidor Matušov
19 * Rework of test-suite, by Izidor Matušov
20+ * Fix for bug #971651: Inform about automatic recovery. Also made to use backup files on gtg_tasks.xml missing
21
22 2013-11-24 Getting Things GNOME! 0.3.1
23 * Fix for bug #1024473: Have 'Show Main Window' in notification area, by Antonio Roquentin
24
25=== modified file 'GTG/backends/backend_localfile.py'
26--- GTG/backends/backend_localfile.py 2013-11-23 14:40:23 +0000
27+++ GTG/backends/backend_localfile.py 2014-03-13 18:43:02 +0000
28@@ -29,6 +29,7 @@
29
30 from GTG import _
31 from GTG.backends.genericbackend import GenericBackend
32+from GTG.backends.backendsignals import BackendSignals
33 from GTG.core import CoreConfig
34 from GTG.tools import cleanxml, taskxml
35
36@@ -93,9 +94,11 @@
37 parameters["path"] = parameters.pop("need_conversion")
38 if not self.KEY_DEFAULT_BACKEND in parameters:
39 parameters[self.KEY_DEFAULT_BACKEND] = True
40-
41 self.doc, self.xmlproj = cleanxml.openxmlfile(
42 self.get_path(), "project")
43+ # status if backup was used while trying to open xml file
44+ self._used_backup = cleanxml.used_backup()
45+ self._backup_file_info = cleanxml.backup_file_info()
46 # Make safety daily backup after loading
47 cleanxml.savexml(self.get_path(), self.doc, backup=True)
48
49@@ -130,6 +133,7 @@
50 cleanxml.savexml(self.get_path(), xml)
51 self.doc, self.xmlproj = cleanxml.openxmlfile(
52 self.get_path(), "project")
53+ self._used_backup = False
54
55 def start_get_tasks(self):
56 """ This function starts submitting the tasks from the XML file into
57@@ -197,3 +201,33 @@
58 # We save the XML file only if it's necessary
59 if modified:
60 cleanxml.savexml(self.get_path(), self.doc, backup=True)
61+
62+ def used_backup(self):
63+ """ This functions return a boolean value telling if backup files
64+ were used when instantiating Backend class.
65+ """
66+ return self._used_backup
67+
68+ def backup_file_info(self):
69+ """This functions returns status of the attempt to recover
70+ gtg_tasks.xml
71+ """
72+ return self._backup_file_info
73+
74+ def notify_user_about_backup(self):
75+ """ This function causes the inforbar to show up with the message
76+ about file recovery.
77+ """
78+ BackendSignals().interaction_requested(self.get_id(),
79+ "Oops, something unexpected "
80+ "happened! GTG tried to recover"
81+ " your tasks from backups. \n" +
82+ self.backup_file_info(),
83+ BackendSignals(
84+ ).INTERACTION_TEXT,
85+ "on_continue_clicked")
86+
87+ def on_continue_clicked(self, *args):
88+ """ Callback when the user clicks continue in the infobar
89+ """
90+ pass
91
92=== modified file 'GTG/gtk/browser/custominfobar.py'
93--- GTG/gtk/browser/custominfobar.py 2013-11-25 02:37:46 +0000
94+++ GTG/gtk/browser/custominfobar.py 2014-03-13 18:43:02 +0000
95@@ -153,7 +153,6 @@
96 if event == Gtk.ResponseType.ACCEPT:
97 if self.interaction_type == BackendSignals().INTERACTION_TEXT:
98 self._prepare_textual_interaction()
99- print("done")
100 elif self.interaction_type == BackendSignals().INTERACTION_CONFIRM:
101 self.hide()
102 threading.Thread(target=getattr(self.backend,
103@@ -164,6 +163,11 @@
104 Helper function. gtk calls to populate the infobar in the case of
105 interaction request
106 '''
107+
108+ # If infobar is used just to notify user of backup recovery
109+ if self.callback == "on_continue_clicked":
110+ self.hide()
111+ return
112 title, description\
113 = getattr(self.backend,
114 self.callback)("get_ui_dialog_text")
115
116=== modified file 'GTG/gtk/manager.py'
117--- GTG/gtk/manager.py 2014-03-09 12:59:59 +0000
118+++ GTG/gtk/manager.py 2014-03-13 18:43:02 +0000
119@@ -117,6 +117,12 @@
120 def open_browser(self):
121 if not self.browser:
122 self.browser = TaskBrowser(self.req, self)
123+ # notify user if backup was used
124+ backend_dic = self.req.get_all_backends()
125+ for backend in backend_dic:
126+ if backend.get_name() == "backend_localfile" and \
127+ backend.used_backup():
128+ backend.notify_user_about_backup()
129 Log.debug("Browser is open")
130
131 # FIXME : the browser should not be the center of the universe.
132
133=== modified file 'GTG/tools/cleanxml.py'
134--- GTG/tools/cleanxml.py 2014-03-09 12:59:59 +0000
135+++ GTG/tools/cleanxml.py 2014-03-13 18:43:02 +0000
136@@ -30,6 +30,8 @@
137 tab = "\t"
138 enter = "\n"
139 BACKUP_NBR = 7
140+_USED_BACKUP = False
141+_BACKUP_FILE_INFO = ""
142
143 # Those two functions are there only to be able to read prettyXML
144 # Source: http://yumenokaze.free.fr/?/Informatique/Snipplet/Python/cleandom
145@@ -119,6 +121,11 @@
146
147 If file doesn't exist, create a new file """
148
149+ #reset _USED_BACKUP and _BACKUP_FILE_INFO
150+ global _USED_BACKUP
151+ global _BACKUP_FILE_INFO
152+ _USED_BACKUP = False
153+ _BACKUP_FILE_INFO = ""
154 tmpfile = zefile + '__'
155 try:
156 if os.path.exists(zefile):
157@@ -126,14 +133,10 @@
158 elif os.path.exists(tmpfile):
159 Log.warning("Something happened to %s. Using backup" % zefile)
160 os.rename(tmpfile, zefile)
161- return _try_openxmlfile(zefile, root)
162- else:
163- # Creating empty file
164- doc, xmlproject = emptydoc(root)
165- newfile = savexml(zefile, doc)
166- if not newfile:
167- Log.error("Could not create a new file %s" % zefile)
168- sys.exit(1)
169+ _USED_BACKUP = True
170+ _BACKUP_FILE_INFO = "Recovered from backup made on: " + \
171+ datetime.datetime.fromtimestamp(
172+ os.path.getmtime(tmpfile)).strftime('%Y-%m-%d')
173 return _try_openxmlfile(zefile, root)
174
175 except IOError as msg:
176@@ -146,25 +149,46 @@
177 if os.path.exists(tmpfile):
178 Log.warning("Something happened to %s. Using backup" % zefile)
179 os.rename(tmpfile, zefile)
180+ _USED_BACKUP = True
181+ _BACKUP_FILE_INFO = "Recovered from backup made on: " + \
182+ datetime.datetime.fromtimestamp(
183+ os.path.getmtime(tmpfile)).strftime('%Y-%m-%d')
184 # Ok, try one more time now
185 try:
186 return _try_openxmlfile(zefile, root)
187 except Exception as msg:
188 Log.warning('Failed with reason: %s' % msg)
189
190- # Try to revert to backup
191- backup_name = _get_backup_name(zefile)
192- for i in range(BACKUP_NBR):
193- backup_file = "%s.bak.%d" % (backup_name, i)
194- if os.path.exists(backup_file):
195- Log.info("Trying to restore backup file %s" % backup_file)
196- try:
197- return _try_openxmlfile(backup_file, root)
198- except Exception as msg:
199- Log.warning('Failed with reason: %s' % msg)
200-
201- Log.info("No suitable backup was found")
202+ # Try to revert to backup
203+ backup_name = _get_backup_name(zefile)
204+ for i in range(BACKUP_NBR):
205+ backup_file = "%s.bak.%d" % (backup_name, i)
206+ if os.path.exists(backup_file):
207+ Log.info("Trying to restore backup file %s" % backup_file)
208+ _USED_BACKUP = True
209+ _BACKUP_FILE_INFO = "Recovered from backup made on: " + \
210+ datetime.datetime.fromtimestamp(
211+ os.path.getmtime(backup_file)).strftime('%Y-%m-%d')
212+ try:
213+ return _try_openxmlfile(backup_file, root)
214+ except Exception as msg:
215+ Log.warning('Failed with reason: %s' % msg)
216+
217+ Log.info("No suitable backup was found")
218+
219+ # Creating empty file
220+ doc, xmlproject = emptydoc(root)
221+ newfile = savexml(zefile, doc)
222+ if not newfile:
223+ Log.error("Could not create a new file %s" % zefile)
224 sys.exit(1)
225+ # set _USED_BACKUP even if there's a failure to notify about the same
226+ _USED_BACKUP = True
227+ _BACKUP_FILE_INFO = "No backups found. Created a new file"
228+ return _try_openxmlfile(zefile, root)
229+
230+ # exit if execution reached this statement
231+ sys.exit(1)
232
233
234 # Return a doc element with only one root element of the name "root"
235@@ -235,3 +259,15 @@
236 except IOError as msg:
237 print(msg)
238 return False
239+
240+
241+def used_backup():
242+ """ This function returns true if a call to openxml used saved backup file
243+ """
244+ return _USED_BACKUP
245+
246+
247+def backup_file_info():
248+ """ Return information about the status of automatic backup file recovery
249+ """
250+ return _BACKUP_FILE_INFO

Subscribers

People subscribed via source and target branches

to status/vote changes: