[Apt-listbugs-commits] [apt-listbugs] 03/04: add a test helper script

Francesco Poli frx-guest at alioth.debian.org
Fri Aug 30 17:41:56 UTC 2013


This is an automated email from the git hooks/post-receive script.

frx-guest pushed a commit to branch master
in repository apt-listbugs.

commit ca81c4d3ce3df0495e53887c48614a4d36219be7
Author: Francesco Poli (wintermute) <invernomuto at paranoici.org>
Date:   Mon Aug 26 22:36:06 2013 +0200

    add a test helper script
    
    Thanks to Serafeim Zanikolas for providing the initial version of the
    script!
---
 debian/examples            |    1 +
 examples/send-hook-info.rb |   73 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/debian/examples b/debian/examples
index 5ccad23..cef5165 100644
--- a/debian/examples
+++ b/debian/examples
@@ -1,3 +1,4 @@
 examples/rc2rss
 examples/listbugs-soap.rb
 examples/deblistbugs
+examples/send-hook-info.rb
diff --git a/examples/send-hook-info.rb b/examples/send-hook-info.rb
new file mode 100755
index 0000000..edd3567
--- /dev/null
+++ b/examples/send-hook-info.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/ruby1.8
+#
+# send-hook-info.rb: test helper script that reads a hook info dump from
+#                    a specified file and sends it to a specified command
+#                    through a file descriptor (useful to test
+#                    "apt-listbugs apt" without the need to invoke apt)
+#
+# Copyright (C) 2013       Google Inc
+# Copyright (C) 2013       Francesco Poli <invernomuto at paranoici.org>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License with
+#  the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL-2;
+#  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+#  Suite 330, Boston, MA  02111-1307  USA
+#
+
+def usage
+  $stderr.print "Usage: ", $0, " <file> <command>\n"
+end
+
+# parse command-line arguments
+if ARGV.length != 2
+  usage
+  exit 1
+end
+file = ARGV[0]
+command = ARGV[1]
+
+# check whether the specified file actually exists
+if ! FileTest.exist?(file)
+  $stderr.print "Cannot find file \"#{file}\"\n"
+  exit 2
+end
+
+read_fd, write_fd = IO.pipe
+
+# this variable tells the child command (e.g.: apt-listbugs) which
+# file descriptor to read from
+ENV['APT_HOOK_INFO_FD'] = read_fd.to_i.to_s
+puts "APT_HOOK_INFO_FD set to #{ENV['APT_HOOK_INFO_FD']}"
+
+if Process.fork().nil?
+  # the child
+  write_fd.close
+  exec command
+  read_fd.close
+  exit 0
+else
+  # the parent
+  read_fd.close
+  begin
+    open(file).each { |line|
+      write_fd.puts "#{line}"
+    }
+  rescue Errno::EACCES
+    $stderr.print "Cannot read from file \"#{file}\"\n" 
+    exit 3
+  end
+  write_fd.close
+  Process.waitall
+end
+
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/apt-listbugs/apt-listbugs.git



More information about the Apt-listbugs-commits mailing list