← Back to team overview

apport-hackers team mailing list archive

[Merge] lp:~bryce/apport/omit_empty into lp:apport

 

Bryce Harrington has proposed merging lp:~bryce/apport/omit_empty into lp:apport.

Requested reviews:
  Apport upstream developers (apport-hackers)
Related bugs:
  Bug #813798 in apport (Ubuntu): "attach_root_command_outputs creates empty entries if no output from command"
  https://bugs.launchpad.net/ubuntu/+source/apport/+bug/813798

For more details, see:
https://code.launchpad.net/~bryce/apport/omit_empty/+merge/68616

Fixes a couple typos

Fixes 813798 by adding 'omit_empty' flag to  attach_root_command_outputs() so it doesn't append empty fields when a command gives no output.
-- 
https://code.launchpad.net/~bryce/apport/omit_empty/+merge/68616
Your team Apport upstream developers is requested to review the proposed merge of lp:~bryce/apport/omit_empty into lp:apport.
=== modified file 'apport/hookutils.py'
--- apport/hookutils.py	2011-07-15 17:23:19 +0000
+++ apport/hookutils.py	2011-07-20 22:28:30 +0000
@@ -32,7 +32,7 @@
 def path_to_key(path):
     '''Generate a valid report key name from a file path.
         
-    This will meet apport's restrictions on the characters used in keys.
+    This will replace invalid punctuation symbols with valid ones.
     '''
     return path.translate(_path_key_trans)
 
@@ -54,7 +54,7 @@
 def read_file(path):
     '''Return the contents of the specified path. 
         
-    Upon error, this will deliver a a text representation of the error,
+    Upon error, this will deliver a text representation of the error,
     instead of failing.
     '''
     try:
@@ -83,7 +83,7 @@
 def attach_dmesg(report):
     '''Attach information from the kernel ring buffer (dmesg).
 
-    This won't overwite already existing information.
+    This will not overwrite already existing information.
     '''
     try:
         if not report.get('BootDmesg', '').strip():
@@ -291,7 +291,7 @@
     assert type(command) == type([]), 'command must be a list'
     return command_output(_root_command_prefix() + command, input, stderr)
 
-def attach_root_command_outputs(report, command_map):
+def attach_root_command_outputs(report, command_map, omit_empty=False):
     '''Execute multiple commands as root and put their outputs into report.
 
     command_map is a keyname -> 'shell command' dictionary with the commands to
@@ -328,7 +328,10 @@
         # now read back the individual outputs
         for keyname in command_map:
             f = open(os.path.join(workdir, keyname))
-            report[keyname] = f.read()
+            buf = f.read()
+            if omit_empty and len(buf.strip())==0:
+                continue
+            report[keyname] = buf
             f.close()
     finally:
         shutil.rmtree(workdir)