Merge lp:~nataliabidart/wsgi-oops/subprocess-compress into lp:wsgi-oops

Proposed by Natalia Bidart
Status: Merged
Approved by: Rick McBride
Approved revision: 42
Merged at revision: not available
Proposed branch: lp:~nataliabidart/wsgi-oops/subprocess-compress
Merge into: lp:wsgi-oops
Diff against target: 120 lines
2 files modified
canonical/oops/serializer.py (+17/-8)
canonical/oops/tests/test_serializer.py (+22/-7)
To merge this branch: bzr merge lp:~nataliabidart/wsgi-oops/subprocess-compress
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve
Robert Collins (community) Abstain
Tim Cole (community) Approve
Review via email: mp+14048@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Tim Cole (tcole) wrote :

Looks reasonable; nice style fixes.

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

You don't seem to check the return code of the compressor process?

review: Abstain
Revision history for this message
Nicola Larosa (teknico) wrote :

> Looks reasonable; nice style fixes.

Yes, having the imports in alphabetical order is good; however, I still prefer them on a single line, even against PEP-8. :-)

I would also like to reiterate SteveA's suggestion that gzip is a better CPU/compression tradeoff than bzip2, for text files.

Revision history for this message
Rick McBride (rmcbride) wrote :

This looks good, however I'd like to see a response to Robert's question regarding response codes from the compressor process before marking approved.

review: Approve
42. By Natalia Bidart

Checking return code of bz2 subprocess.

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

> You don't seem to check the return code of the compressor process?

Already changed Popen by check_call. Exception handling will be done in #462584.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'canonical/oops/serializer.py'
2--- canonical/oops/serializer.py 2009-10-21 21:07:05 +0000
3+++ canonical/oops/serializer.py 2009-10-28 13:22:09 +0000
4@@ -45,13 +45,15 @@
5 """
6
7 from datetime import datetime, timedelta
8+
9+import os
10 import pytz
11+import re
12+import subprocess
13+import thread
14 import weakref
15-import thread
16-import re
17-import os
18 import zipfile
19-import bz2
20+
21 from pprint import pformat
22 from canonical.versioninfo import version_info
23
24@@ -232,8 +234,12 @@
25 self.write_file("version", self._generate_version(oops))
26 for entry in oops.get_all():
27 self.write_file(entry.entry_name, entry.get_dump_data())
28+
29+ dump_filename = self._filename
30 self.finish_dump()
31
32+ return dump_filename
33+
34 def write_file(self, section, data):
35 """Basic writing data to the file system under a directory path"""
36 if self._fh:
37@@ -463,7 +469,10 @@
38 class OOPSBz2Serializer(OOPSRFC822Serializer):
39 """A serializer that will generate compressed oops files."""
40
41- def _open_dump_file(self, filename):
42- """Returns a file handler to dump to."""
43- self.bz2_filename = filename + ".bz2"
44- return bz2.BZ2File(self.bz2_filename, "w")
45+ def finish_dump(self):
46+ # store filename before parent reset it to None
47+ filename = self._filename
48+ # have the parent finishing the plain oops dump
49+ super(OOPSBz2Serializer, self).finish_dump()
50+ # compress it
51+ subprocess.check_call(('bzip2', filename))
52
53=== modified file 'canonical/oops/tests/test_serializer.py'
54--- canonical/oops/tests/test_serializer.py 2009-10-21 19:58:31 +0000
55+++ canonical/oops/tests/test_serializer.py 2009-10-28 13:22:09 +0000
56@@ -18,11 +18,12 @@
57
58 __metaclass__ = type
59
60+import bz2
61+import logging
62+import os
63+import rfc822
64 import sys
65 import unittest
66-import rfc822
67-import logging
68-import bz2
69
70 from cStringIO import StringIO
71 from canonical.oops.serializer import OOPSRFC822Serializer, OOPSBz2Serializer
72@@ -47,7 +48,7 @@
73 class OopsSerializerTests(unittest.TestCase):
74 """Test oops serialisers"""
75 serializer_class = OOPSRFC822Serializer
76-
77+
78 def _get_result_as_msg(self):
79 result = StringIO()
80 # Tell the serializer to put data into my own fh
81@@ -58,7 +59,7 @@
82 result.seek(0)
83 # Load the result up as an rfc822 message and close fh
84 return rfc822.Message(result), result
85-
86+
87 def setUp(self):
88 """Init this test"""
89 self.oops = OOPS( self.get_id )
90@@ -146,14 +147,28 @@
91 class OopsBz2SerializerTests(OopsSerializerTests):
92 """Run the same set of tests with the Zip serializer"""
93 serializer_class = OOPSBz2Serializer
94+
95 def _get_result_as_msg(self):
96 # Tell the serializer to dump data to a BZ file
97 s = self.serializer_class("key", "/tmp")
98 # This is where the serialization is done
99- s.dump(self.oops)
100- fp = bz2.BZ2File(s.bz2_filename)
101+ filename = s.dump(self.oops)
102+ assert filename is not None
103+
104+ # store filename to remove it at tearDown time
105+ self.compressed_filename = filename + '.bz2'
106+
107+ self.assertTrue(os.path.exists(self.compressed_filename))
108+ self.assertFalse(os.path.exists(filename))
109+
110+ fp = bz2.BZ2File(self.compressed_filename)
111 return rfc822.Message(fp), fp
112
113+ def tearDown(self):
114+ do_remove = hasattr(self, 'compressed_filename') and \
115+ os.path.exists(self.compressed_filename)
116+ if do_remove:
117+ os.remove(self.compressed_filename)
118
119 if __name__ == '__main__':
120 unittest.main()

Subscribers

People subscribed via source and target branches