SVN: repo-scripts/mailer.py

twittner cvs at pld-linux.org
Fri Sep 8 19:39:53 CEST 2006


Author: twittner
Date: Fri Sep  8 19:39:51 2006
New Revision: 7738

Modified:
   repo-scripts/mailer.py
Log:
- limit diff output to 500 lines (workaround which works
  only for PipeOutput class)


Modified: repo-scripts/mailer.py
==============================================================================
--- repo-scripts/mailer.py	(original)
+++ repo-scripts/mailer.py	Fri Sep  8 19:39:51 2006
@@ -201,7 +201,7 @@
   def run_diff(self, cmd):
     # we're holding everything in memory, so we may as well read the
     # entire diff into memory and stash that into the buffer
-    pipe_ob = popen2.Popen3(string.join(cmd) + '|/usr/bin/head -n500')
+    pipe_ob = popen2.Popen3(cmd)
     self.write(pipe_ob.fromchild.read())
 
     # wait on the child so we don't end up with a billion zombies
@@ -260,9 +260,6 @@
     # figure out the command for delivery
     self.cmd = string.split(cfg.general.mail_command)
 
-    # we want a descriptor to /dev/null for hooking up to the diffs' stdin
-    self.null = os.open('/dev/null', os.O_RDONLY)
-
   def start(self, group, params):
     MailedOutput.start(self, group, params)
 
@@ -281,37 +278,23 @@
     self.write(self.mail_headers(group, params))
 
   def run_diff(self, cmd):
-    # flush the buffers that write to the mailer. we're about to fork, and
-    # we don't want data sitting in both copies of the buffer. we also
-    # want to ensure the parts are delivered to the mailer in the right order.
-    self.pipe.tochild.flush()
-
-    pid = os.fork()
-    if pid:
-      # in the parent
-
-      # wait for the diff to finish
-      ### do anything with the return value?
-      os.waitpid(pid, 0)
+    line_limit = 500 # limit diff to n lines
+    diff = popen2.Popen3(cmd)
+    diff.tochild.close()
+    diff_output = diff.fromchild.readline()
+    line = line_limit
+    while diff_output != '' and line >= 0:
+      diff_output = diff_output + diff.fromchild.readline()
+      line -= 1
+      
+    self.write(diff_output)
+    diff_rest_lines = len(diff.fromchild.readlines())
+    if diff_rest_lines > 0:
+      self.write('<<diff output has been trimmed to %d lines, %d line(s) remained.>>\n' %(line_limit, diff_rest_lines))
 
-      return
-
-    # in the child
-
-    # duplicate the write-to-mailer descriptor to our stdout and stderr
-    os.dup2(self.pipe.tochild.fileno(), 1)
-    os.dup2(self.pipe.tochild.fileno(), 2)
-
-    # hook up stdin to /dev/null
-    os.dup2(self.null, 0)
-
-    ### do we need to bother closing self.null and self.pipe.tochild ?
-
-    # run the diff command, now that we've hooked everything up
-    try:
-      os.execvp(cmd[0], cmd)
-    finally:
-      os._exit(1)
+    diff.fromchild.close()
+    diff.wait()
+    self.pipe.tochild.flush()
 
   def finish(self):
     # signal that we're done sending content


More information about the pld-cvs-commit mailing list