Merge lp:~facundo/magicicada-gui/apport into lp:magicicada-gui

Proposed by Facundo Batista
Status: Merged
Approved by: Natalia Bidart
Approved revision: 97
Merged at revision: 96
Proposed branch: lp:~facundo/magicicada-gui/apport
Merge into: lp:magicicada-gui
Diff against target: 162 lines (+108/-5)
4 files modified
magicicada/logger.py (+9/-4)
magicicada/tests/test_apport.py (+49/-0)
magicicada/tests/test_logger.py (+17/-1)
source_magicicada.py (+33/-0)
To merge this branch: bzr merge lp:~facundo/magicicada-gui/apport
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Review via email: mp+65870@code.launchpad.net

Commit message

Apport hook file (LP: #590921).

Description of the change

Apport hook file.

Code to install this file in "/usr/share/apport/package-hooks/" is not included in this branch, as this should not be done in setup.py, but in the Debian/Ubuntu specific code (see https://lists.ubuntu.com/archives/bazaar/2010q4/070514.html).

Tests included.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Please remove the following comments:

#FIXME: test
# - que el fname log que attachea sea el correcto
# - que llame a attach_file_if_exists correctamente
# - que llame a attach_related_packages correctamente

review: Needs Fixing
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Also, it would be great if we can define the log filename in only one place (magicicada/logger.py).

review: Needs Fixing
Revision history for this message
Facundo Batista (facundo) wrote :

Removed the comments, and moved the filename creation responsibility to logger.py.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

The comments are still there, maybe you forgot a push?

93 +#FIXME: test
94 +# - que el fname log que attachea sea el correcto
95 +# - que llame a attach_file_if_exists correctamente
96 +# - que llame a attach_related_packages correctamente

review: Needs Fixing
lp:~facundo/magicicada-gui/apport updated
97. By Facundo Batista

Removed comment and moved the log filename responsibility.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Great work.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magicicada/logger.py'
2--- magicicada/logger.py 2011-06-17 01:14:31 +0000
3+++ magicicada/logger.py 2011-07-31 16:11:16 +0000
4@@ -65,16 +65,21 @@
5 logger.error("Unhandled exception!\n%s", msg)
6
7
8-def set_up(cache_dir=None):
9- """Set up the logging."""
10+def get_filename(cache_dir=None):
11+ """Return the log file name."""
12 if cache_dir is None:
13 # choose the folder to store the logs
14 cache_dir = xdg.BaseDirectory.xdg_cache_home
15
16- logfolder = os.path.join(cache_dir, 'magicicada')
17+ return os.path.join(cache_dir, 'magicicada', 'magicicada.log')
18+
19+
20+def set_up(cache_dir=None):
21+ """Set up the logging."""
22+ logfile = get_filename(cache_dir)
23+ logfolder = os.path.dirname(logfile)
24 if not os.path.exists(logfolder):
25 os.makedirs(logfolder)
26- logfile = os.path.join(logfolder, 'magicicada.log')
27
28 logger = logging.getLogger('magicicada')
29 handler = CustomRotatingFH(logfile, maxBytes=1e6, backupCount=10)
30
31=== added file 'magicicada/tests/test_apport.py'
32--- magicicada/tests/test_apport.py 1970-01-01 00:00:00 +0000
33+++ magicicada/tests/test_apport.py 2011-07-31 16:11:16 +0000
34@@ -0,0 +1,49 @@
35+#
36+# Author: Facundo Batista <facundo@taniquetil.com.ar>
37+#
38+# Copyright 2010-2011 Chicharreros
39+#
40+# This program is free software: you can redistribute it and/or modify it
41+# under the terms of the GNU General Public License version 3, as published
42+# by the Free Software Foundation.
43+#
44+# This program is distributed in the hope that it will be useful, but
45+# WITHOUT ANY WARRANTY; without even the implied warranties of
46+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
47+# PURPOSE. See the GNU General Public License for more details.
48+#
49+# You should have received a copy of the GNU General Public License along
50+# with this program. If not, see <http://www.gnu.org/licenses/>.
51+
52+"""Tests Apport integration."""
53+
54+from twisted.trial.unittest import TestCase
55+
56+import source_magicicada
57+
58+from magicicada import logger
59+
60+
61+class ApportTestCase(TestCase):
62+ """Test the Apport usage."""
63+
64+ def test_attach_log_file(self):
65+ """Attach the log file."""
66+ called = []
67+ self.patch(source_magicicada, 'attach_file_if_exists',
68+ lambda *a: called.extend(a))
69+ d = {}
70+ source_magicicada.add_info(d)
71+ self.assertIs(called[0], d)
72+ self.assertEqual(called[1], logger.get_filename())
73+ self.assertEqual(called[2], 'MagicicadaLog')
74+
75+ def test_attach_package_info_u1client(self):
76+ """Attach the package information for ubuntuone-client."""
77+ called = []
78+ self.patch(source_magicicada, 'attach_related_packages',
79+ lambda *a: called.extend(a))
80+ d = {}
81+ source_magicicada.add_info(d)
82+ self.assertIs(called[0], d)
83+ self.assertEqual(called[1], ['ubuntuone-client'])
84
85=== modified file 'magicicada/tests/test_logger.py'
86--- magicicada/tests/test_logger.py 2011-06-17 01:14:31 +0000
87+++ magicicada/tests/test_logger.py 2011-07-31 16:11:16 +0000
88@@ -20,19 +20,35 @@
89
90 import cStringIO
91 import logging
92+import os
93 import sys
94 import unittest
95
96 from twisted.python import log, failure
97 from ubuntuone.devtools.handlers import MementoHandler
98+from xdg.BaseDirectory import xdg_cache_home
99
100-from magicicada.logger import exception_handler, deferror_handler
101+from magicicada.logger import exception_handler, deferror_handler, get_filename
102
103
104 # It's ok to access private data in the test suite
105 # pylint: disable=W0212
106
107
108+class SimpleTestCase(unittest.TestCase):
109+ """Several simple tests for the logger module."""
110+
111+ def test_log_fname_default(self):
112+ """The log filename by default."""
113+ fname = os.path.join(xdg_cache_home, 'magicicada', 'magicicada.log')
114+ self.assertEqual(get_filename(), fname)
115+
116+ def test_log_fname_basedir(self):
117+ """The log filename using other base dir."""
118+ fname = os.path.join('tmp', 'magicicada', 'magicicada.log')
119+ self.assertEqual(get_filename(cache_dir='tmp'), fname)
120+
121+
122 class ExceptionTests(unittest.TestCase):
123 """Test that we log on unhandled exceptions."""
124
125
126=== added file 'source_magicicada.py'
127--- source_magicicada.py 1970-01-01 00:00:00 +0000
128+++ source_magicicada.py 2011-07-31 16:11:16 +0000
129@@ -0,0 +1,33 @@
130+# source_magicicada.py
131+#
132+# Author: Facundo Batista <facundo@taniquetil.com.ar>
133+#
134+# Copyright 2010-2011 Chicharreros
135+#
136+# This program is free software: you can redistribute it and/or modify it
137+# under the terms of the GNU General Public License version 3, as published
138+# by the Free Software Foundation.
139+#
140+# This program is distributed in the hope that it will be useful, but
141+# WITHOUT ANY WARRANTY; without even the implied warranties of
142+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
143+# PURPOSE. See the GNU General Public License for more details.
144+#
145+# You should have received a copy of the GNU General Public License along
146+# with this program. If not, see <http://www.gnu.org/licenses/>.
147+
148+"""Configuration file for Apport."""
149+
150+from apport.hookutils import attach_related_packages, attach_file_if_exists
151+
152+from magicicada import logger
153+
154+
155+def add_info(report):
156+ """Add info to the report."""
157+ # attach the log
158+ fname = logger.get_filename()
159+ attach_file_if_exists(report, fname, "MagicicadaLog")
160+
161+ # which ubuntuone-client package version is installed
162+ attach_related_packages(report, ["ubuntuone-client"])

Subscribers

People subscribed via source and target branches